use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testCrudToken.
@Test
public void testCrudToken() {
IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
IdmTokenDto token = createToken(owner, null, null);
//
Assert.assertNotNull(token.getId());
Assert.assertEquals(owner.getId(), token.getOwnerId());
Assert.assertEquals(manager.getOwnerType(owner), token.getOwnerType());
//
IdmTokenDto getToken = manager.getToken(token.getId());
//
Assert.assertEquals(token.getId(), getToken.getId());
Assert.assertEquals(owner.getId(), getToken.getOwnerId());
Assert.assertFalse(getToken.isDisabled());
//
List<IdmTokenDto> tokens = manager.getTokens(owner);
//
Assert.assertEquals(1, tokens.size());
Assert.assertEquals(token.getId(), tokens.get(0).getId());
//
manager.disableTokens(owner);
//
getToken = manager.getToken(token.getId());
Assert.assertEquals(token.getId(), getToken.getId());
Assert.assertEquals(owner.getId(), getToken.getOwnerId());
Assert.assertTrue(getToken.isDisabled());
//
manager.deleteTokens(owner);
//
tokens = manager.getTokens(owner);
Assert.assertTrue(tokens.isEmpty());
Assert.assertNull(manager.getToken(token.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testEvictTokenCache.
@Test
public void testEvictTokenCache() {
IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
IdmTokenDto token = createToken(owner, null, null);
token = manager.getToken(token.getId());
//
Assert.assertNotNull(cacheManager.getValue(TokenManager.TOKEN_CACHE_NAME, token.getId()));
//
token.setDisabled(true);
manager.saveToken(owner, token);
//
Assert.assertNull(cacheManager.getValue(TokenManager.TOKEN_CACHE_NAME, token.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testDisableTokenAfterIdentityIsDisabled.
@Test
public void testDisableTokenAfterIdentityIsDisabled() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmTokenDto token = createToken(identity, null, null);
Assert.assertFalse(token.isDisabled());
//
identityService.disable(identity.getId());
//
token = manager.getToken(token.getId());
//
Assert.assertTrue(token.isDisabled());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTokenManagerIntegrationTest method testDisableTokenAfterIdentityIsDeleted.
@Test
public void testDisableTokenAfterIdentityIsDeleted() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmTokenDto token = createToken(identity, null, null);
Assert.assertFalse(token.isDisabled());
//
identityService.delete(identity);
//
token = manager.getToken(token.getId());
//
Assert.assertTrue(token.isDisabled());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class OAuthAuthenticationManagerUnitTest method testAuthSuccess.
/**
* Successful authentication
*/
@Test
public void testAuthSuccess() {
IdmIdentityDto i = getTestIdentity();
IdmJwtAuthentication authentication = getAuthentication(UUID.randomUUID(), i, ZonedDateTime.now().plusHours(1), ZonedDateTime.now());
doNothing().when(workflowIdentityService).setAuthenticatedUserId(USER_NAME);
doNothing().when(securityService).setAuthentication(authentication);
IdmTokenDto token = new IdmTokenDto(authentication.getId());
token.setOwnerId(i.getId());
when(tokenService.get(authentication.getId())).thenReturn(token);
when(cacheManager.getValue(TokenManager.TOKEN_CACHE_NAME, token.getId())).thenReturn(null);
Authentication auth = authManager.authenticate(authentication);
Assert.assertEquals(USER_NAME, auth.getName());
Assert.assertEquals(USER_NAME, auth.getPrincipal());
Assert.assertTrue(auth.getAuthorities().isEmpty());
verify(workflowIdentityService).setAuthenticatedUserId(USER_NAME);
verify(securityService).setAuthentication(authentication);
verify(tokenService).get(authentication.getId());
verify(cacheManager).getValue(TokenManager.TOKEN_CACHE_NAME, token.getId());
}
Aggregations