use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security-oauth by spring-projects.
the class RedisTokenStoreTests method storeAccessTokenWithoutRefreshTokenRemoveAccessTokenVerifyTokenRemoved.
// gh-572
@Test
public void storeAccessTokenWithoutRefreshTokenRemoveAccessTokenVerifyTokenRemoved() {
OAuth2Request request = RequestTokenFactory.createOAuth2Request("clientId", false);
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
OAuth2AccessToken oauth2AccessToken = new DefaultOAuth2AccessToken("access-token-" + UUID.randomUUID());
OAuth2Authentication oauth2Authentication = new OAuth2Authentication(request, authentication);
tokenStore.storeAccessToken(oauth2AccessToken, oauth2Authentication);
tokenStore.removeAccessToken(oauth2AccessToken);
Collection<OAuth2AccessToken> oauth2AccessTokens = tokenStore.findTokensByClientId(request.getClientId());
assertTrue(oauth2AccessTokens.isEmpty());
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class SecurityEvaluationContextExtensionTests method getRootObjectExplicitAuthenticationOverridesSecurityContextHolder.
@Test
public void getRootObjectExplicitAuthenticationOverridesSecurityContextHolder() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "ROLE_EXPLICIT");
securityExtension = new SecurityEvaluationContextExtension(explicit);
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
SecurityContextHolder.getContext().setAuthentication(authentication);
assertThat(getRoot().getAuthentication()).isSameAs(explicit);
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class SecurityEvaluationContextExtensionTests method getRootObjectSecurityContextHolderAuthentication.
@Test
public void getRootObjectSecurityContextHolderAuthentication() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
SecurityContextHolder.getContext().setAuthentication(authentication);
assertThat(getRoot().getAuthentication()).isSameAs(authentication);
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class HttpNamespaceWithMultipleInterceptorsTests method createAuthenticatedSession.
public HttpSession createAuthenticatedSession(String... roles) {
MockHttpSession session = new MockHttpSession();
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("bob", "bobspassword", roles));
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
SecurityContextHolder.clearContext();
return session;
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class HttpPathParameterStrippingTests method createAuthenticatedSession.
public HttpSession createAuthenticatedSession(String... roles) {
MockHttpSession session = new MockHttpSession();
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("bob", "bobspassword", roles));
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
SecurityContextHolder.clearContext();
return session;
}
Aggregations