2017-06-21 4 views
0

abgelaufen ist ich ein Gateway implementiert haben oauth2 Client vor meiner Ressourcen Dienste und ui zu sein. Alles funktioniert gut, außer wenn ein Token verfallen i@ EnableOAuth2Sso prüft nicht, ob Token

erhalten
<oauth> 
    <error_description>bfc5a9f6-0537-4ab9-91c1-e756501b429d</error_description> 
    <error>invalid_token</error> 
</oauth> 

das Protokoll überprüft i-Gateway fand heraus, den Benutzer erwägt, wie bereits als Sitzungs authentifiziert existieren

2017-06-21 09:17:34.311 DEBUG 32482 --- [nio-8080-exec-6] o.s.s.w.a.i.FilterSecurityInterceptor : Previously Authenticated: or[email protected]a80f4caf: Principal: user; Credentials: [PROTECTED]; Authenticated: true; Details: remoteAddress=0:0:0:0:0:0:0:1, sessionId=<SESSION>, tokenType=bearertokenValue=<TOKEN>; Granted Authorities: ROLE_ACTUATOR, ROLE_USER 
2017-06-21 09:17:34.311 DEBUG 32482 --- [nio-8080-exec-6] o.s.s.access.vote.AffirmativeBased  : Voter: org.sp[email protected]1aaae9c5, returned: 1 

während meine Ressourcen Service oder UI nicht

2017-06-21 09:17:34.532 WARN 32484 --- [nio-9001-exec-1] o.s.b.a.s.o.r.UserInfoTokenServices  : Could not fetch user details: class org.springframework.security.oauth2.client.resource.UserRedirectRequiredException, A redirect is required to get the users approval 

Gateway-Konfiguration

@SpringBootApplication 
@EnableDiscoveryClient 
@EnableZuulProxy 
public class GatewayApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(GatewayApplication.class, args); 
    } 
} 

@Configuration 
@EnableOAuth2Sso 
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { 


    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .csrf() 
       .disable() 
       .authorizeRequests() 
       .anyRequest().authenticated(); 

    } 

} 

security: 
    oauth2: 
    client: 
     accessTokenUri: http://localhost:9191/uaa/oauth/token 
     userAuthorizationUri: http://localhost:9191/uaa/oauth/authorize 
     clientId: acme 
     clientSecret: acmesecret 
    resource: 
     user-info-uri: http://localhost:9191/uaa/user 
     prefer-token-info: false 
zuul: 
    ignored-services: '*' 
    routes: 
    authserver: /uaa/** 
    resource-service: /resource/** 
    ui: 
     path: /ui/** 
     strip-prefix: false 

UI-Konfiguration oder Alle Ressourcen Server

@SpringBootApplication 
@EnableDiscoveryClient 
@EnableResourceServer 
public class UiApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(UiApplication.class, args); 
    } 
} 

security: 
    oauth2: 
    resource: 
     user-info-uri: http://localhost:9191/uaa/user 
server: 
    port: 9001 
    context-path: /${spring.application.name} 

Was ich zu erwarten und versuch zu tun, dass Gateway zu überprüfen, ob das Token gültig ist, und wenn es den Benutzer nicht umleiten zum Login-Seite oder die Aktualisierungs-Token verwenden um das Token zu aktualisieren?

Antwort

0

Nach einem Gespräch mit @ dave-Syer auf gitter, sagte er mir, dass wir OAuth2RestOperations innerhalb des Gateway erklären müssen, wie es standardmäßig erstellt wird, nicht in spring-boot und es benötigt wird, um die Aktualisierungs-Token in den OAuth2TokenRelayFilter

anfordern so einfach nur mit den unten fixiert alles

@Bean 
public OAuth2RestOperations oAuth2RestOperations(OAuth2ClientContext oauth2ClientContext, OAuth2ProtectedResourceDetails details) { 
    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(details, oauth2ClientContext); 
    return oAuth2RestTemplate; 
} 
Verwandte Themen