Search in sources :

Example 6 with RememberMeAuthenticationToken

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

the class RememberMeAuthenticationProviderTests method testDetectsAnInvalidKey.

// ~ Methods
// ========================================================================================================
@Test
public void testDetectsAnInvalidKey() throws Exception {
    RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
    RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("WRONG_KEY", "Test", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
    try {
        aap.authenticate(token);
        fail("Should have thrown BadCredentialsException");
    } catch (BadCredentialsException expected) {
    }
}
Also used : RememberMeAuthenticationProvider(org.springframework.security.authentication.RememberMeAuthenticationProvider) RememberMeAuthenticationToken(org.springframework.security.authentication.RememberMeAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) Test(org.junit.Test)

Example 7 with RememberMeAuthenticationToken

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

the class RememberMeAuthenticationTokenTests method testGetters.

@Test
public void testGetters() {
    RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("key", "Test", ROLES_12);
    assertThat(token.getKeyHash()).isEqualTo("key".hashCode());
    assertThat(token.getPrincipal()).isEqualTo("Test");
    assertThat(token.getCredentials()).isEqualTo("");
    assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities())).contains("ROLE_ONE");
    assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities())).contains("ROLE_TWO");
    assertThat(token.isAuthenticated()).isTrue();
}
Also used : RememberMeAuthenticationToken(org.springframework.security.authentication.RememberMeAuthenticationToken) Test(org.junit.Test)

Example 8 with RememberMeAuthenticationToken

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

the class RememberMeAuthenticationTokenTests method testSetAuthenticatedIgnored.

@Test
public void testSetAuthenticatedIgnored() {
    RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("key", "Test", ROLES_12);
    assertThat(token.isAuthenticated()).isTrue();
    token.setAuthenticated(false);
    assertThat(!token.isAuthenticated()).isTrue();
}
Also used : RememberMeAuthenticationToken(org.springframework.security.authentication.RememberMeAuthenticationToken) Test(org.junit.Test)

Example 9 with RememberMeAuthenticationToken

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

the class RememberMeAuthenticationTokenTests method testNotEqualsDueToAbstractParentEqualsCheck.

@Test
public void testNotEqualsDueToAbstractParentEqualsCheck() {
    RememberMeAuthenticationToken token1 = new RememberMeAuthenticationToken("key", "Test", ROLES_12);
    RememberMeAuthenticationToken token2 = new RememberMeAuthenticationToken("key", "DIFFERENT_PRINCIPAL", ROLES_12);
    assertThat(token1.equals(token2)).isFalse();
}
Also used : RememberMeAuthenticationToken(org.springframework.security.authentication.RememberMeAuthenticationToken) Test(org.junit.Test)

Example 10 with RememberMeAuthenticationToken

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

the class RememberMeAuthenticationTokenTests method testNotEqualsDueToKey.

@Test
public void testNotEqualsDueToKey() {
    RememberMeAuthenticationToken token1 = new RememberMeAuthenticationToken("key", "Test", ROLES_12);
    RememberMeAuthenticationToken token2 = new RememberMeAuthenticationToken("DIFFERENT_KEY", "Test", ROLES_12);
    assertThat(token1.equals(token2)).isFalse();
}
Also used : RememberMeAuthenticationToken(org.springframework.security.authentication.RememberMeAuthenticationToken) Test(org.junit.Test)

Aggregations

RememberMeAuthenticationToken (org.springframework.security.authentication.RememberMeAuthenticationToken)15 Test (org.junit.Test)14 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)3 User (org.springframework.security.core.userdetails.User)3 RememberMeAuthenticationProvider (org.springframework.security.authentication.RememberMeAuthenticationProvider)2 FilterChain (javax.servlet.FilterChain)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1