2017-05-12 2 views
0

認証と承認のためにspring-securityspring-security-oauth2(JWTアクセストークン)を使用しています。アイデアはすべての要求を通過させるが、認証されたユーザーと認証されていないユーザーを区別できるようにすることです。できるだけ早く有効にする@EnableResourceServer私の設定HttpSecurityは無視されるようです。そして、要求は401を返す:authorizeRequests()。anyRequest()。permitAll()

{ 
    "error": "unauthorized", 
    "error_description": "Full authentication is required to access this resource" 
} 

をここに設定です:

@SpringBootApplication 
@EnableJpaRepositories 
@ComponentScan 
@EntityScan 
@EnableWebSecurity 
public class Application { 

    public static void main(final String[] args) { 
     new SpringApplicationBuilder(Application.class).bannerMode(Banner.Mode.OFF).run(args); 
    } 

    @EnableResourceServer 
    public static class SecurityConfig extends WebSecurityConfigurerAdapter implements JwtAccessTokenConverterConfigurer { 

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

     @Override 
     public void configure(final JwtAccessTokenConverter converter) { 
      final DefaultAccessTokenConverter conv = new DefaultAccessTokenConverter(); 
      conv.setUserTokenConverter(userAuthenticationConverter()); 
      converter.setAccessTokenConverter(conv); 

     } 

     @Bean 
     public UserAuthenticationConverter userAuthenticationConverter() { 
      return new ResourceAuthenticationConverter(); 
     } 
    } 

答えて

2

あなたはほとんどそこにいます。リソースの詳細(URLパスとリソース を指定すること

ユーザーがこの注釈を追加し、タイプの@Bean(ResourceServerConfigurerAdapter経由など) ResourceServerConfigurerを提供する必要があり :javadoc of @EnableResourceServerは答えを提供 - それは簡単な修正ですid)。

ただし、WebSecurityConfigurerAdapterを使用しています。ただ、ResourceServerConfigurerAdapterに変更し、configureの視認性を高める:

@EnableResourceServer 
public static class SecurityConfig extends ResourceServerConfigurerAdapter implements JwtAccessTokenConverterConfigurer { 
// snip 
     @Override 
     public void configure(final HttpSecurity http) throws Exception { 
      http.csrf().disable(); 
      http.authorizeRequests().anyRequest().permitAll(); 
     } 
// snip 
関連する問題