Search in sources :

Example 1 with RememberMeAuthenticationProvider

use of org.springframework.security.authentication.RememberMeAuthenticationProvider 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 2 with RememberMeAuthenticationProvider

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

the class RememberMeAuthenticationProviderTests method testNormalOperation.

@Test
public void testNormalOperation() throws Exception {
    RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
    RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("qwerty", "Test", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
    Authentication result = aap.authenticate(token);
    assertThat(token).isEqualTo(result);
}
Also used : RememberMeAuthenticationProvider(org.springframework.security.authentication.RememberMeAuthenticationProvider) Authentication(org.springframework.security.core.Authentication) RememberMeAuthenticationToken(org.springframework.security.authentication.RememberMeAuthenticationToken) Test(org.junit.Test)

Example 3 with RememberMeAuthenticationProvider

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

the class RememberMeConfigurer method init.

@SuppressWarnings("unchecked")
@Override
public void init(H http) throws Exception {
    validateInput();
    String key = getKey();
    RememberMeServices rememberMeServices = getRememberMeServices(http, key);
    http.setSharedObject(RememberMeServices.class, rememberMeServices);
    LogoutConfigurer<H> logoutConfigurer = http.getConfigurer(LogoutConfigurer.class);
    if (logoutConfigurer != null && this.logoutHandler != null) {
        logoutConfigurer.addLogoutHandler(this.logoutHandler);
    }
    RememberMeAuthenticationProvider authenticationProvider = new RememberMeAuthenticationProvider(key);
    authenticationProvider = postProcess(authenticationProvider);
    http.authenticationProvider(authenticationProvider);
    initDefaultLoginFilter(http);
}
Also used : PersistentTokenBasedRememberMeServices(org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices) RememberMeServices(org.springframework.security.web.authentication.RememberMeServices) AbstractRememberMeServices(org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices) TokenBasedRememberMeServices(org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices) RememberMeAuthenticationProvider(org.springframework.security.authentication.RememberMeAuthenticationProvider)

Example 4 with RememberMeAuthenticationProvider

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

the class RememberMeAuthenticationProviderTests method testGettersSetters.

@Test
public void testGettersSetters() throws Exception {
    RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider("qwerty");
    aap.afterPropertiesSet();
    assertThat(aap.getKey()).isEqualTo("qwerty");
}
Also used : RememberMeAuthenticationProvider(org.springframework.security.authentication.RememberMeAuthenticationProvider) Test(org.junit.Test)

Example 5 with RememberMeAuthenticationProvider

use of org.springframework.security.authentication.RememberMeAuthenticationProvider 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)

Aggregations

RememberMeAuthenticationProvider (org.springframework.security.authentication.RememberMeAuthenticationProvider)6 Test (org.junit.Test)5 RememberMeAuthenticationToken (org.springframework.security.authentication.RememberMeAuthenticationToken)2 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 RememberMeServices (org.springframework.security.web.authentication.RememberMeServices)1 AbstractRememberMeServices (org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices)1 PersistentTokenBasedRememberMeServices (org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices)1 TokenBasedRememberMeServices (org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices)1