Search in sources :

Example 61 with TestingAuthenticationToken

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

the class RemoteAuthenticationManagerImplTests method testSuccessfulAuthentication.

@Test
public void testSuccessfulAuthentication() {
    RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
    AuthenticationManager am = mock(AuthenticationManager.class);
    when(am.authenticate(any(Authentication.class))).thenReturn(new TestingAuthenticationToken("u", "p", "A"));
    manager.setAuthenticationManager(am);
    manager.attemptAuthentication("rod", "password");
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) Authentication(org.springframework.security.core.Authentication) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 62 with TestingAuthenticationToken

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

the class RememberMeAuthenticationProviderTests method testIgnoresClassesItDoesNotSupport.

@Test
public void testIgnoresClassesItDoesNotSupport() throws Exception {
    RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
    TestingAuthenticationToken token = new TestingAuthenticationToken("user", "password", "ROLE_A");
    assertThat(aap.supports(TestingAuthenticationToken.class)).isFalse();
    // Try it anyway
    assertThat(aap.authenticate(token)).isNull();
}
Also used : RememberMeAuthenticationProvider(org.springframework.security.authentication.RememberMeAuthenticationProvider) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 63 with TestingAuthenticationToken

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

the class DefaultWebInvocationPrivilegeEvaluatorTests method allowsAccessIfAccessDecisionManagerDoes.

@Test
public void allowsAccessIfAccessDecisionManagerDoes() throws Exception {
    Authentication token = new TestingAuthenticationToken("test", "Password", "MOCK_INDEX");
    DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(interceptor);
    assertThat(wipe.isAllowed("/foo/index.jsp", token)).isTrue();
}
Also used : Authentication(org.springframework.security.core.Authentication) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 64 with TestingAuthenticationToken

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

the class RefreshTokenGrantTests method setup.

@Before
public void setup() {
    resource = new ResourceOwnerPasswordResourceDetails();
    resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
    resource.setClientId("my-trusted-client");
    resource.setId("sparklr");
    resource.setScope(Arrays.asList("trust"));
    resource.setUsername("marissa");
    resource.setPassword("koala");
    OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
    existingToken = template.getAccessToken();
    ((DefaultOAuth2AccessToken) existingToken).setExpiration(new Date(0L));
    SecurityContextImpl securityContext = new SecurityContextImpl();
    securityContext.setAuthentication(new TestingAuthenticationToken("marissa", "koala", "ROLE_USER"));
    SecurityContextHolder.setContext(securityContext);
}
Also used : ResourceOwnerPasswordResourceDetails(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Date(java.util.Date) Before(org.junit.Before)

Example 65 with TestingAuthenticationToken

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

the class RedisTokenStoreMockTests method setUp.

@Before
public void setUp() throws Exception {
    connectionFactory = mock(JedisConnectionFactory.class);
    connection = mock(JedisConnection.class);
    when(connectionFactory.getConnection()).thenReturn(connection);
    tokenStore = new RedisTokenStore(connectionFactory);
    Set<String> scope = new LinkedHashSet<String>(Arrays.asList("read", "write", "read-write"));
    request = RequestTokenFactory.createOAuth2Request("clientId", false, scope);
    authentication = new TestingAuthenticationToken("user", "password");
}
Also used : JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) JedisConnection(org.springframework.data.redis.connection.jedis.JedisConnection) 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