Search in sources :

Example 6 with IdmTokenDto

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());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 7 with IdmTokenDto

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());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 8 with IdmTokenDto

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());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) ZonedDateTime(java.time.ZonedDateTime) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 9 with IdmTokenDto

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());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) ZonedDateTime(java.time.ZonedDateTime) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) TokenManager(eu.bcvsolutions.idm.core.security.api.service.TokenManager) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Before(org.junit.Before) Transactional(org.springframework.transaction.annotation.Transactional) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) ZonedDateTime(java.time.ZonedDateTime) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 10 with IdmTokenDto

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());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmTokenDto (eu.bcvsolutions.idm.core.api.dto.IdmTokenDto)58 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)38 Test (org.junit.Test)34 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)16 UUID (java.util.UUID)16 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)15 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)8 IdmJwtAuthentication (eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication)8 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)7 IdmJwtAuthenticationDto (eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto)7 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)7 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)7 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)6 Transactional (org.springframework.transaction.annotation.Transactional)6 ZonedDateTime (java.time.ZonedDateTime)5 IdmTokenFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter)4 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)4 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)4 TwoFactorRegistrationResponseDto (eu.bcvsolutions.idm.core.security.api.dto.TwoFactorRegistrationResponseDto)4