Существует ли фильтр, который проверяет токены доступа и токены идентификатора в Spring Security? - PullRequest
0 голосов
/ 26 сентября 2019

У меня настроен OAuth 2, и эта конфигурация сохраняет токен доступа в хранилище в памяти.Я вижу, что во время первоначального входа в систему токен доступа и токен идентификатора проверяются в пределах OAuth2LoginAuthenticationFilter.

Но для последующих запросов нет проверки срока действия для токенов id / access.Что заставляет меня задуматься, как Spring Security проверяет срок действия токена?

Вот цепочка фильтров, через которую проходит запрос.Я прошел через следующую цепочку фильтров, однако она не вызывает OAuth2LoginAuthenticationFilter.

WebAsyncManagerIntegrationFilter
SecurityContextPersistenceFilter
HeaderWriterFilter
CsrfFilter
LogoutFilter
OAuth2AuthroizationRequestRedirectFilter
OAuth2LoginAuthenticationFilter
DefautLoginPageGeneratingFilter
RequestCacheAwareFilter
SecurityContextHolderAwareRequestFilter
AnonymousAuthenticationFilter
SessionManagementFilter
ExceptionTranslationFilter
FilterSecurityInterceptor

Вот конфигурация:

@EnableWebSecurity
@Configuration
@ConfigurationProperties(prefix = "openid-auth")
@Setter
@Log4j2
public class AuthConfig extends WebSecurityConfigurerAdapter {

    protected static final String RESTRICTED_PATHS = "/api/**";
    private String clientId;

    @Autowired
    private StoreCheckoutLogoutHandler storeCheckoutLogoutHandler;
    @Autowired
    private StringEncryptor jasyptStringEncryptor;
    @Autowired
    private AuthTokenHandler authTokenHandler;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        if (enabled) {
            log.info("Authentication enabled for {}", RESTRICTED_PATHS);
            configureSecurity(http);
            configureOAuthAuthorization(http);
            configureLogOut(http);
            configureStatelessAuth(http);
        } else {
            http.csrf().disable();
            log.info("Authentication disabled");
        }
    }

    private void configureSecurity(HttpSecurity http) throws Exception {
        http.antMatcher("/**")
            .authorizeRequests()
            .antMatchers("/api/unprotected")
            .permitAll()
            .antMatchers(RESTRICTED_PATHS)
            .authenticated()
            .anyRequest()
            .permitAll();
    }

    private void configureOAuthAuthorization(HttpSecurity http) throws Exception {
        http.oauth2Login()
            .userInfoEndpoint()
            .userAuthoritiesMapper(userAuthoritiesMapper())
            .and()
            .defaultSuccessUrl("/", true);
    }

    private void configureLogOut(HttpSecurity http) throws Exception {
        http.logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/api/user", "DELETE"))
            .addLogoutHandler(storeCheckoutLogoutHandler)
            .logoutSuccessUrl("/")
            .invalidateHttpSession(true)
            .deleteCookies(OIDC_TOKEN_COOKIE, OAUTH2_AUTHORIZATION_REQUEST_COOKIE);
    }

    private void configureStatelessAuth(HttpSecurity http) throws Exception {
        http
                .sessionManagement()
                .sessionCreationPolicy(ALWAYS)
                .and()
              .csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
    }

    private GrantedAuthoritiesMapper userAuthoritiesMapper() {
        return new GroupsGrantedAuthoritiesMapper();
    }
}

Кто-нибудь знает, где Spring Securityпроверка идентификатора / токена доступа по умолчанию происходит?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...