Search in sources :

Example 1 with DefaultToken

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

the class DefaultTokenTests method testEquality.

@Test
public void testEquality() {
    String key = "key";
    long created = new Date().getTime();
    String extendedInformation = "extended";
    DefaultToken t1 = new DefaultToken(key, created, extendedInformation);
    DefaultToken t2 = new DefaultToken(key, created, extendedInformation);
    assertThat(t2).isEqualTo(t1);
}
Also used : DefaultToken(org.springframework.security.core.token.DefaultToken) Date(java.util.Date) Test(org.junit.Test)

Example 2 with DefaultToken

use of org.springframework.security.core.token.DefaultToken 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 3 with DefaultToken

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

the class DefaultTokenTests method testRejectsNullExtendedInformation.

@Test(expected = IllegalArgumentException.class)
public void testRejectsNullExtendedInformation() {
    String key = "key";
    long created = new Date().getTime();
    new DefaultToken(key, created, null);
}
Also used : DefaultToken(org.springframework.security.core.token.DefaultToken) Date(java.util.Date) Test(org.junit.Test)

Example 4 with DefaultToken

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

the class DefaultTokenTests method testEqualityWithDifferentExtendedInformation3.

@Test
public void testEqualityWithDifferentExtendedInformation3() {
    String key = "key";
    long created = new Date().getTime();
    DefaultToken t1 = new DefaultToken(key, created, "length1");
    DefaultToken t2 = new DefaultToken(key, created, "longerLength2");
    assertThat(t1).isNotEqualTo(t2);
}
Also used : DefaultToken(org.springframework.security.core.token.DefaultToken) Date(java.util.Date) Test(org.junit.Test)

Example 5 with DefaultToken

use of org.springframework.security.core.token.DefaultToken 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)

Aggregations

Date (java.util.Date)5 Test (org.junit.Test)5 DefaultToken (org.springframework.security.core.token.DefaultToken)5 KeyBasedPersistenceTokenService (org.springframework.security.core.token.KeyBasedPersistenceTokenService)2 Token (org.springframework.security.core.token.Token)2