use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testDisableToken.
@Test
public void testDisableToken() {
IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
IdmTokenDto token = createToken(owner, null, null);
Assert.assertNull(token.getExpiration());
Assert.assertFalse(token.isDisabled());
//
token = manager.disableToken(token.getId());
//
Assert.assertNotNull(token.getExpiration());
Assert.assertTrue(token.isDisabled());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testVerifyTokenOk.
@Test
public void testVerifyTokenOk() {
IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
IdmTokenDto token = createToken(owner, null, null);
//
Assert.assertEquals(token.getId(), manager.verifyToken(token.getId()).getId());
token = createToken(owner, null, ZonedDateTime.now().plusMinutes(1));
//
Assert.assertEquals(token.getId(), manager.verifyToken(token.getId()).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testDisableSetExpiration.
/**
* Disabled token has to set expiration
*/
@Test
public void testDisableSetExpiration() {
IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
IdmTokenDto token = createToken(owner, null, null);
//
manager.disableTokens(owner);
//
token = manager.getToken(token.getId());
Assert.assertTrue(token.isDisabled());
Assert.assertNotNull(token.getExpiration());
Assert.assertFalse(token.getExpiration().isAfter(ZonedDateTime.now()));
//
token = createToken(owner, null, ZonedDateTime.now().plusDays(1));
//
manager.disableTokens(owner);
//
token = manager.getToken(token.getId());
Assert.assertTrue(token.isDisabled());
Assert.assertNotNull(token.getExpiration());
Assert.assertFalse(token.getExpiration().isAfter(ZonedDateTime.now()));
//
ZonedDateTime expired = ZonedDateTime.now().minusDays(1);
token = createToken(owner, null, expired);
//
manager.disableTokens(owner);
//
token = manager.getToken(token.getId());
Assert.assertTrue(token.isDisabled());
Assert.assertNotNull(token.getExpiration());
Assert.assertEquals(expired, token.getExpiration());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testPurgeTokens.
@Test
public void testPurgeTokens() {
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
String typeOne = getHelper().createName();
String typeTwo = getHelper().createName();
IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
//
createToken(owner, typeOne, null);
createToken(owner, typeOne, now.plusDays(1));
createToken(owner, typeOne, now);
createToken(owner, typeOne, now.minusDays(1));
IdmTokenDto tokenOneExpiredTwoDaysBefore = createToken(owner, typeOne, now.minusDays(2));
createToken(owner, typeTwo, null);
createToken(owner, typeTwo, now.plusDays(1));
createToken(owner, typeTwo, now);
createToken(owner, typeTwo, now.minusDays(1));
IdmTokenDto tokenTwoExpiredTwoDaysBefore = createToken(owner, typeTwo, now.minusDays(2));
List<IdmTokenDto> tokens = manager.getTokens(owner);
Assert.assertEquals(10, tokens.size());
// 2 weeks by default
// TODO: configurable
manager.purgeTokens();
//
tokens = manager.getTokens(owner);
Assert.assertEquals(10, tokens.size());
//
manager.purgeTokens(typeTwo, now.minusDays(1));
//
tokens = manager.getTokens(owner);
Assert.assertEquals(9, tokens.size());
Assert.assertFalse(tokens.stream().anyMatch(t -> t.getId().equals(tokenTwoExpiredTwoDaysBefore.getId())));
//
manager.purgeTokens(null, now.minusDays(1));
//
tokens = manager.getTokens(owner);
Assert.assertEquals(8, tokens.size());
Assert.assertFalse(tokens.stream().anyMatch(t -> t.getId().equals(tokenOneExpiredTwoDaysBefore.getId())));
//
manager.purgeTokens(typeOne, null);
//
tokens = manager.getTokens(owner);
Assert.assertEquals(4, tokens.size());
Assert.assertFalse(tokens.stream().anyMatch(t -> t.getTokenType().equals(typeOne)));
//
manager.purgeTokens(null, null);
//
tokens = manager.getTokens(owner);
Assert.assertTrue(tokens.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testVerifyTokenExpired.
@Test(expected = ResultCodeException.class)
public void testVerifyTokenExpired() {
IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
IdmTokenDto token = createToken(owner, null, ZonedDateTime.now().minusNanos(1));
//
manager.verifyToken(token.getId());
}
Aggregations