Search in sources :

Example 66 with TestingAuthenticationToken

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());
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 67 with TestingAuthenticationToken

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);
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 68 with TestingAuthenticationToken

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);
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 69 with TestingAuthenticationToken

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;
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 70 with TestingAuthenticationToken

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;
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Aggregations

TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)183 Test (org.junit.Test)106 Authentication (org.springframework.security.core.Authentication)76 SecurityContext (org.springframework.security.core.context.SecurityContext)46 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)38 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)38 MifosUser (org.mifos.security.MifosUser)36 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)32 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)28 Before (org.junit.Before)25 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 ConfigAttribute (org.springframework.security.access.ConfigAttribute)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 MockFilterChain (org.springframework.mock.web.MockFilterChain)9 GrantedAuthority (org.springframework.security.core.GrantedAuthority)9 FilterChain (javax.servlet.FilterChain)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)8 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)7