0

oauth2(リソースサーバーとして)で正しく動作するスプリングブートアプリケーションがあります。カスタムconfigure(HttpSecurity http)メソッドはありません。のみoauth2でスプリングセキュリティのカスタム設定を追加できません

spring-boot-starter-security 
spring-security-oauth2 
spring-security-jwt 

がpomに追加されます。

ここで、保護されていないエンドポイントを追加します。だから、(回答SO多くは以下の)私は追加で開始:

@Configuration 
public class Security extends ResourceServerConfigurerAdapter { 

    @Override 
    public void configure(HttpSecurity http) throws Exception { 
    } 
} 

、その後、私が得た:

Cannot apply org.springframework.security.config.[email protected]6513fd22 to already built object

全エラー:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: Cannot apply org.springframework.security.config.[email protected]6513fd22 to already built object 

それでは、どのように私は追加するには、私のセキュリティを設定する必要があります匿名アクセスのエンドポイント?

答えて

1

configure()メソッドでは空の本体からエラーが発生します。

明示的に指定する必要があります。例えば(私たちの作業アプリケーションから):/unprotected/sample/find/**/unprotected/sample/find/**に一致

@Override 
public void configure(HttpSecurity http) throws Exception { 
    http.authorizeRequests() 
      .antMatchers("/unprotected/sample/find/**").permitAll() 
      .antMatchers("/unprotected/another/register").permitAll() 
      .anyRequest().authenticated().and() 
      .csrf().disable(); 
} 

エンドポイントが保護されていないと、他のすべてが保護されています。

もちろん保護されていないエンドポイントには@PreAuthorize()が定義されていてはなりません。

関連する問題