Search in sources :

Example 21 with TestingAuthenticationToken

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

the class AuthenticationTagTests method testOperationWhenPrincipalIsNull.

@Test
public void testOperationWhenPrincipalIsNull() throws JspException {
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(null, "koala", AuthorityUtils.NO_AUTHORITIES));
    authenticationTag.setProperty("principal");
    assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
    assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 22 with TestingAuthenticationToken

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

the class JaasApiIntegrationFilterTests method obtainSubjectNonJaasAuthentication.

@Test
public void obtainSubjectNonJaasAuthentication() {
    Authentication authentication = new TestingAuthenticationToken("un", "pwd");
    authentication.setAuthenticated(true);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    assertNullSubject(filter.obtainSubject(request));
}
Also used : Authentication(org.springframework.security.core.Authentication) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 23 with TestingAuthenticationToken

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

the class GrantedAuthorityDefaultsJcTests method setup.

private void setup(String role) {
    TestingAuthenticationToken user = new TestingAuthenticationToken("user", "password", role);
    SecurityContextHolder.getContext().setAuthentication(user);
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 24 with TestingAuthenticationToken

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

the class GrantedAuthorityDefaultsXmlTests method setup.

private void setup(String role) {
    TestingAuthenticationToken user = new TestingAuthenticationToken("user", "password", role);
    SecurityContextHolder.getContext().setAuthentication(user);
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 25 with TestingAuthenticationToken

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

the class WebMvcSecurityConfigurationTests method setup.

@Before
public void setup() {
    mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
    authentication = new TestingAuthenticationToken("user", "password", AuthorityUtils.createAuthorityList("ROLE_USER"));
    SecurityContextHolder.getContext().setAuthentication(authentication);
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

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