Search in sources :

Example 6 with KeyBasedPersistenceTokenService

use of org.springframework.security.core.token.KeyBasedPersistenceTokenService in project spring-security by spring-projects.

the class KeyBasedPersistenceTokenServiceTests method getService.

private KeyBasedPersistenceTokenService getService() {
    SecureRandomFactoryBean fb = new SecureRandomFactoryBean();
    KeyBasedPersistenceTokenService service = new KeyBasedPersistenceTokenService();
    service.setServerSecret("MY:SECRET$$$#");
    service.setServerInteger(Integer.valueOf(454545));
    try {
        SecureRandom rnd = (SecureRandom) fb.getObject();
        service.setSecureRandom(rnd);
        service.afterPropertiesSet();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return service;
}
Also used : KeyBasedPersistenceTokenService(org.springframework.security.core.token.KeyBasedPersistenceTokenService) SecureRandom(java.security.SecureRandom) SecureRandomFactoryBean(org.springframework.security.core.token.SecureRandomFactoryBean)

Example 7 with KeyBasedPersistenceTokenService

use of org.springframework.security.core.token.KeyBasedPersistenceTokenService in project spring-security by spring-projects.

the class KeyBasedPersistenceTokenServiceTests method testOperationWithEmptyRandomNumber.

@Test
public void testOperationWithEmptyRandomNumber() {
    KeyBasedPersistenceTokenService service = getService();
    service.setPseudoRandomNumberBytes(0);
    Token token = service.allocateToken("Hello:world:::");
    Token result = service.verifyToken(token.getKey());
    assertThat(result).isEqualTo(token);
}
Also used : KeyBasedPersistenceTokenService(org.springframework.security.core.token.KeyBasedPersistenceTokenService) Token(org.springframework.security.core.token.Token) DefaultToken(org.springframework.security.core.token.DefaultToken) Test(org.junit.Test)

Aggregations

KeyBasedPersistenceTokenService (org.springframework.security.core.token.KeyBasedPersistenceTokenService)7 Test (org.junit.Test)6 DefaultToken (org.springframework.security.core.token.DefaultToken)6 Token (org.springframework.security.core.token.Token)6 Date (java.util.Date)2 SecureRandom (java.security.SecureRandom)1 SecureRandomFactoryBean (org.springframework.security.core.token.SecureRandomFactoryBean)1