Search in sources :

Example 11 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.

the class SecuredAnnotationDrivenBeanDefinitionParserTests method targetIsSerializableAfterUse.

@Test(expected = AccessDeniedException.class)
public void targetIsSerializableAfterUse() throws Exception {
    try {
        target.someAdminMethod();
    } catch (AuthenticationCredentialsNotFoundException expected) {
    }
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("u", "p", "ROLE_A"));
    BusinessService chompedTarget = (BusinessService) serializeAndDeserialize(target);
    chompedTarget.someAdminMethod();
}
Also used : BusinessService(org.springframework.security.access.annotation.BusinessService) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 12 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.

the class SecuredTests method securedAdminRoleDenied.

@Test(expected = AccessDeniedException.class)
public void securedAdminRoleDenied() {
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "pass", "ROLE_USER"));
    service.securedAdminRole();
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 13 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.

the class AbstractSecurityWebSocketMessageBrokerConfigurerDocTests method setup.

@Before
public void setup() {
    token = new DefaultCsrfToken("header", "param", "token");
    sessionAttr = "sessionAttr";
    messageUser = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
}
Also used : DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Example 14 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.

the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method setup.

@Before
public void setup() {
    token = new DefaultCsrfToken("header", "param", "token");
    sessionAttr = "sessionAttr";
    messageUser = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
}
Also used : DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Example 15 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.

the class SecurityContextChannelInterceptorTests method restoresOriginalContext.

// SEC-2829
@Test
public void restoresOriginalContext() throws Exception {
    TestingAuthenticationToken original = new TestingAuthenticationToken("original", "original", "ROLE_USER");
    SecurityContextHolder.getContext().setAuthentication(original);
    messageBuilder.setHeader(SimpMessageHeaderAccessor.USER_HEADER, authentication);
    interceptor.beforeHandle(messageBuilder.build(), channel, handler);
    assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(authentication);
    interceptor.afterMessageHandled(messageBuilder.build(), channel, handler, null);
    assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(original);
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

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