Search in sources :

Example 1 with KeyBasedPersistenceTokenService

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

the class KeyBasedPersistenceTokenServiceTests method testOperationWithSimpleExtendedInformation.

@Test
public void testOperationWithSimpleExtendedInformation() {
    KeyBasedPersistenceTokenService service = getService();
    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)

Example 2 with KeyBasedPersistenceTokenService

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

the class KeyBasedPersistenceTokenServiceTests method testOperationWithComplexExtendedInformation.

@Test
public void testOperationWithComplexExtendedInformation() {
    KeyBasedPersistenceTokenService service = getService();
    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)

Example 3 with KeyBasedPersistenceTokenService

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

the class KeyBasedPersistenceTokenServiceTests method testOperationWithTamperedKey.

@Test(expected = IllegalArgumentException.class)
public void testOperationWithTamperedKey() {
    KeyBasedPersistenceTokenService service = getService();
    Token goodToken = service.allocateToken("");
    String fake = goodToken.getKey().toUpperCase();
    Token token = new DefaultToken(fake, new Date().getTime(), "");
    service.verifyToken(token.getKey());
}
Also used : DefaultToken(org.springframework.security.core.token.DefaultToken) KeyBasedPersistenceTokenService(org.springframework.security.core.token.KeyBasedPersistenceTokenService) Token(org.springframework.security.core.token.Token) DefaultToken(org.springframework.security.core.token.DefaultToken) Date(java.util.Date) Test(org.junit.Test)

Example 4 with KeyBasedPersistenceTokenService

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

the class KeyBasedPersistenceTokenServiceTests method testOperationWithMissingKey.

@Test(expected = IllegalArgumentException.class)
public void testOperationWithMissingKey() {
    KeyBasedPersistenceTokenService service = getService();
    Token token = new DefaultToken("", new Date().getTime(), "");
    service.verifyToken(token.getKey());
}
Also used : DefaultToken(org.springframework.security.core.token.DefaultToken) KeyBasedPersistenceTokenService(org.springframework.security.core.token.KeyBasedPersistenceTokenService) Token(org.springframework.security.core.token.Token) DefaultToken(org.springframework.security.core.token.DefaultToken) Date(java.util.Date) Test(org.junit.Test)

Example 5 with KeyBasedPersistenceTokenService

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

the class KeyBasedPersistenceTokenServiceTests method testOperationWithNoExtendedInformation.

@Test
public void testOperationWithNoExtendedInformation() {
    KeyBasedPersistenceTokenService service = getService();
    Token token = service.allocateToken("");
    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