1

Oauth2をSpringセキュリティで構成しようとしています。しかし、Oauthの設定はSpring Securityの設定と矛盾します。Oauth 2.0構成がSpringセキュリティと競合する

リソースサーバーの設定は/api/v0/.*に限らず、すべてのセキュリティ設定を上書きしているようです。リソースサーバーはうまく機能します。しかし、Spring Securityでのフォームベースの認証は機能しません。HTTP 404エラーを返します。

私はこれがResourceServerConfigurerAdapter

@Override 
     public void configure(HttpSecurity http) throws Exception { 
      http 
        .authorizeRequests() 
        .regexMatchers("/api/v0/.*").authenticated(); 

     } 

ログ

AntPathRequestMatcher:151 - Checking match of request : '/login-attempt'; against '/html/**' 
AntPathRequestMatcher:151 - Checking match of request : '/login-attempt'; against '/webapi/**' 
OrRequestMatcher:65 - Trying to match using Ant [pattern='/oauth/token'] 
AntPathRequestMatcher:151 - Checking match of request : '/login-attempt'; against '/oauth/token' 
OrRequestMatcher:65 - Trying to match using Ant [pattern='/oauth/token_key'] 
AntPathRequestMatcher:151 - Checking match of request : '/login-attempt'; against '/oauth/token_key' 
OrRequestMatcher:65 - Trying to match using Ant [pattern='/oauth/check_token'] 
AntPathRequestMatcher:151 - Checking match of request : '/login-attempt'; against '/oauth/check_token' 
OrRequestMatcher:72 - No matches found 
FilterChainProxy:324 - /login-attempt at position 1 of 11 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter' 
FilterChainProxy:324 - /login-attempt at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 
FilterChainProxy:324 - /login-attempt at position 3 of 11 in additional filter chain; firing Filter: 'HeaderWriterFilter' 
HstsHeaderWriter:128 - Not injecting HSTS header since it did not match the requestMatcher org.springframework.se[email protected]2fa4c8cd 
FilterChainProxy:324 - /login-attempt at position 4 of 11 in additional filter chain; firing Filter: 'LogoutFilter' 
AntPathRequestMatcher:151 - Checking match of request : '/login-attempt'; against '/logout' 
FilterChainProxy:324 - /login-attempt at position 5 of 11 in additional filter chain; firing Filter: 'OAuth2AuthenticationProcessingFilter' 
BearerTokenExtractor:54 - Token not found in headers. Trying request parameters. 
BearerTokenExtractor:57 - Token not found in request parameters. Not an OAuth2 request. 
OAuth2AuthenticationProcessingFilter:141 - No token in request, will continue chain. 
FilterChainProxy:324 - /login-attempt at position 6 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter' 
FilterChainProxy:324 - /login-attempt at position 7 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter' 
FilterChainProxy:324 - /login-attempt at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter' 
AnonymousAuthenticationFilter:100 - Populated SecurityContextHolder with anonymous token: 'org.sprin[email protected]9056f12c: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]380f4: RemoteIpAddress: 127.0.0.1;SessionId:672t27n01ruouli4a041a0xq;Granted Authorities: ROLE_ANONYMOUS' 
FilterChainProxy:324 - /login-attempt at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter' 
FilterChainProxy:324 - /login-attempt at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' 
FilterChainProxy:324 - /login-attempt at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' 
RegexRequestMatcher:106 - Checking match of request : '/login-attempt'; against '/api/v0/.*' 
FilterSecurityInterceptor:209 - Public object - authentication not attempted 
FilterChainProxy:309 - /login-attempt reached end of additional filter chain; proceeding with original chain 
からの私の構成である私の WebSecurityConfigurerAdapter

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .authorizeRequests() 
       .antMatchers("/admin/**").access("hasRole('ADMINISTRATOR')") 
       .antMatchers("/1/admin/**").access("hasRole('ADMINISTRATOR')") 
       .antMatchers("/profile**").authenticated() 
       .antMatchers("/oauth/authorize").authenticated() 

       .and() 
       .formLogin() 
       .loginPage("/login") 
       .failureUrl("/login?error=1") 
       .loginProcessingUrl("/login-attempt") 
       .defaultSuccessUrl("/", false) 

       .and() 
       .csrf(); 
    } 

に次のコードを持っています

私は間違っていますか?前もって感謝します!

答えて

1

問題が解決するかどうかは不明です。試してみましょう。

@Order(1) 
@Order(2) 

をコンフィグレーションクラスに追加してもう一度お試しください。

関連する問題