@Test void safeCleanupSecurityContext() { SecurityContextHolder.clearContext(); assertThat(SecurityContextHolder.getContext().getAuthentication(), is(nullValue())); TokenDetails tokenDetails = new TokenDetails(); tokenDetails.setCredentialsProvider(AuthenticationJwtBearerTokenAwareFilter.class); SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("admin", tokenDetails)); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Class credentialsProvider = ((TokenDetails) authentication.getCredentials()).getCredentialsProvider(); assertThat(authentication, is(notNullValue())); assertThat(credentialsProvider, is(equalTo(AuthenticationJwtBearerTokenAwareFilter.class))); helper.safeCleanupSecurityContext(AuthenticationJwtBearerTokenAwareFilter.class); assertThat(SecurityContextHolder.getContext().getAuthentication(), is(nullValue())); SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("admin", tokenDetails)); authentication = SecurityContextHolder.getContext().getAuthentication(); credentialsProvider = ((TokenDetails) authentication.getCredentials()).getCredentialsProvider(); assertThat(authentication, is(notNullValue())); assertThat(credentialsProvider, is(equalTo(AuthenticationJwtBearerTokenAwareFilter.class))); authentication = SecurityContextHolder.getContext().getAuthentication(); credentialsProvider = ((TokenDetails) authentication.getCredentials()).getCredentialsProvider(); assertThat(authentication, is(notNullValue())); assertThat(credentialsProvider, is(equalTo(AuthenticationJwtBearerTokenAwareFilter.class))); }
public void safeCleanupSecurityContext(Class clazz) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !(authentication.getCredentials() instanceof TokenDetails)) { return; } TokenDetails tokenDetails = (TokenDetails) authentication.getCredentials(); if (tokenDetails != null && tokenDetails.getCredentialsProvider() == clazz) { SecurityContextHolder.clearContext(); } }
OidcAuthenticationHelper { public void safeCleanupSecurityContext(Class clazz) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !(authentication.getCredentials() instanceof TokenDetails)) { return; } TokenDetails tokenDetails = (TokenDetails) authentication.getCredentials(); if (tokenDetails != null && tokenDetails.getCredentialsProvider() == clazz) { SecurityContextHolder.clearContext(); } } }
OidcAuthenticationHelper { public void safeCleanupSecurityContext(Class clazz) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !(authentication.getCredentials() instanceof TokenDetails)) { return; } TokenDetails tokenDetails = (TokenDetails) authentication.getCredentials(); if (tokenDetails != null && tokenDetails.getCredentialsProvider() == clazz) { SecurityContextHolder.clearContext(); } } OidcAuthenticationHelper();  OidcAuthenticationHelper(OidcConfiguration oidcConfiguration,
                                    OAuthClient oAuthClient,
                                    SecurityConfig config,
                                    RealmService realmService); }
OidcAuthenticationHelper { public void safeCleanupSecurityContext(Class clazz) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !(authentication.getCredentials() instanceof TokenDetails)) { return; } TokenDetails tokenDetails = (TokenDetails) authentication.getCredentials(); if (tokenDetails != null && tokenDetails.getCredentialsProvider() == clazz) { SecurityContextHolder.clearContext(); } } OidcAuthenticationHelper();  OidcAuthenticationHelper(OidcConfiguration oidcConfiguration,
                                    OAuthClient oAuthClient,
                                    SecurityConfig config,
                                    RealmService realmService); String getBearerToken(HttpServletRequest request); String getBearerToken(HttpServletResponse response); TokenDetails getTokenDetails(HttpServletResponse response); String getRefreshToken(HttpServletResponse response); String getAccessToken(HttpServletRequest request); String getRefreshToken(HttpServletRequest request); String createRedirectUrl(String redirectUrlTemplate, HttpServletRequest request); void setRealmForCurrentRequest(String realm); String getRealmForCurrentRequest(); String getRealmForCurrentRequest(HttpServletResponse response); void validateRealm(TokenDetails tokenDetails); void removeRealmFromCurrentRequest(); boolean shouldApplyUrl(String method, String path); boolean shouldApplyUrl(HttpRequest request); boolean shouldSkip(HttpRequest request); void authenticateCurrentThread(String accessToken, String refreshToken); void authenticateCurrentThread(TokenDetails tokenDetails); @Deprecated AccessToken parseAccessToken(TokenDetails tokenDetails); String removeCodeFromUrl(String url, String code); String removeCodeFromUrl(HttpServletRequest request); boolean isTokenExpiredOrShouldBeRefreshed(TokenDetails tokenDetails); @Deprecated TokenDetails generateTokenDetails(String accessToken, String refreshToken); void safeCleanupSecurityContext(Class clazz); @Autowired void setOidcConfiguration(OidcConfiguration oidcConfiguration); @Autowired void setOAuthClient(OAuthClient oAuthClient); @Autowired void setConfig(SecurityConfig config); @Autowired void setRealmService(RealmService realmService); }
OidcAuthenticationHelper { public void safeCleanupSecurityContext(Class clazz) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !(authentication.getCredentials() instanceof TokenDetails)) { return; } TokenDetails tokenDetails = (TokenDetails) authentication.getCredentials(); if (tokenDetails != null && tokenDetails.getCredentialsProvider() == clazz) { SecurityContextHolder.clearContext(); } } OidcAuthenticationHelper();  OidcAuthenticationHelper(OidcConfiguration oidcConfiguration,
                                    OAuthClient oAuthClient,
                                    SecurityConfig config,
                                    RealmService realmService); String getBearerToken(HttpServletRequest request); String getBearerToken(HttpServletResponse response); TokenDetails getTokenDetails(HttpServletResponse response); String getRefreshToken(HttpServletResponse response); String getAccessToken(HttpServletRequest request); String getRefreshToken(HttpServletRequest request); String createRedirectUrl(String redirectUrlTemplate, HttpServletRequest request); void setRealmForCurrentRequest(String realm); String getRealmForCurrentRequest(); String getRealmForCurrentRequest(HttpServletResponse response); void validateRealm(TokenDetails tokenDetails); void removeRealmFromCurrentRequest(); boolean shouldApplyUrl(String method, String path); boolean shouldApplyUrl(HttpRequest request); boolean shouldSkip(HttpRequest request); void authenticateCurrentThread(String accessToken, String refreshToken); void authenticateCurrentThread(TokenDetails tokenDetails); @Deprecated AccessToken parseAccessToken(TokenDetails tokenDetails); String removeCodeFromUrl(String url, String code); String removeCodeFromUrl(HttpServletRequest request); boolean isTokenExpiredOrShouldBeRefreshed(TokenDetails tokenDetails); @Deprecated TokenDetails generateTokenDetails(String accessToken, String refreshToken); void safeCleanupSecurityContext(Class clazz); @Autowired void setOidcConfiguration(OidcConfiguration oidcConfiguration); @Autowired void setOAuthClient(OAuthClient oAuthClient); @Autowired void setConfig(SecurityConfig config); @Autowired void setRealmService(RealmService realmService); static final String AUTH_HEADER_VALUE_PREFIX; }