use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class TokenEvictCacheProcessor method process.
@Override
public EventResult<IdmTokenDto> process(EntityEvent<IdmTokenDto> event) {
IdmTokenDto token = event.getContent();
IdmTokenDto previousToken = event.getOriginalSource();
// evict authorization manager caches for token identity only
if (JwtAuthenticationMapper.AUTHENTICATION_TOKEN_NAME.equals(token.getTokenType()) && (event.hasType(TokenEventType.DELETE) || previousToken == null || (!previousToken.isDisabled() && token.isDisabled()))) {
// authentication token was disabled
// identity owner = see condition above => authentication token only
UUID identityId = token.getOwnerId();
// evict authorization manager caches for token identity only
cacheManager.evictValue(AuthorizationManager.PERMISSION_CACHE_NAME, identityId);
// cached identity authorization policies
cacheManager.evictValue(AuthorizationManager.AUTHORIZATION_POLICY_CACHE_NAME, identityId);
}
// evict token cache on every token change
cacheManager.evictValue(TokenManager.TOKEN_CACHE_NAME, token.getId());
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class TokenDeleteProcessor method process.
@Override
public EventResult<IdmTokenDto> process(EntityEvent<IdmTokenDto> event) {
IdmTokenDto token = event.getContent();
//
service.deleteInternal(token);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class TokenSaveProcessor method process.
@Override
public EventResult<IdmTokenDto> process(EntityEvent<IdmTokenDto> event) {
IdmTokenDto token = event.getContent();
token = service.saveInternal(token);
event.setContent(token);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleDeleteAuthoritiesProcessorTest method testRoleRemovedSuperAuthorityStays.
/**
* User has to roles with same authorities - removing just one role
* shall not change the authorities modification flag.
*/
@Test
public void testRoleRemovedSuperAuthorityStays() {
// role with APP_ADMIN authority
IdmRoleDto r = getHelper().createRole();
createTestPolicy(r, IdmBasePermission.ADMIN, IdmGroupPermission.APP);
//
IdmRoleDto role2 = getTestRole();
IdmIdentityDto i = getHelper().createIdentity();
IdmIdentityContractDto c = getTestContract(i);
IdmIdentityRoleDto ir = getTestIdentityRole(r, c);
IdmIdentityRoleDto ir2 = getTestIdentityRole(role2, c);
//
List<IdmTokenDto> tokens = tokenManager.getTokens(i);
//
Assert.assertTrue(tokens.isEmpty());
Assert.assertEquals(2, identityRoleService.findAllByIdentity(i.getId()).size());
//
// login - one token
getHelper().login(i.getUsername(), i.getPassword());
try {
tokens = tokenManager.getTokens(i);
Assert.assertEquals(1, tokens.size());
Assert.assertFalse(tokens.get(0).isDisabled());
identityRoleService.delete(ir2);
tokens = tokenManager.getTokens(i);
Assert.assertEquals(1, tokens.size());
Assert.assertFalse(tokens.get(0).isDisabled());
Assert.assertEquals(1, identityRoleService.findAllByIdentity(i.getId()).size());
Assert.assertEquals(ir.getId(), identityRoleService.findAllByIdentity(i.getId()).get(0).getId());
Assert.assertEquals(1, authoritiesFactory.getGrantedAuthoritiesForIdentity(i.getId()).size());
} finally {
getHelper().logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class PermissionsAuthorityChangeProcessorTest method testAddAuthorityUpdateUsers.
@Test
public void testAddAuthorityUpdateUsers() throws Exception {
IdmRoleDto role = getTestRole();
IdmIdentityDto i = getHelper().createIdentity();
IdmIdentityContractDto c = getTestContract(i);
getTestIdentityRole(role, c);
//
IdmTokenFilter filter = new IdmTokenFilter();
filter.setOwnerType(tokenManager.getOwnerType(i.getClass()));
filter.setOwnerId(i.getId());
List<IdmTokenDto> tokens = tokenManager.getTokens(i);
//
Assert.assertTrue(tokens.isEmpty());
//
// login - one token
getHelper().login(i.getUsername(), i.getPassword());
try {
tokens = tokenManager.getTokens(i);
Assert.assertEquals(1, tokens.size());
Assert.assertFalse(tokens.get(0).isDisabled());
//
createTestPolicy(role, IdmBasePermission.EXECUTE, IdmGroupPermission.APP);
//
// add role - token should not be removed
tokens = tokenManager.getTokens(i);
Assert.assertEquals(1, tokens.size());
Assert.assertFalse(tokens.get(0).isDisabled());
} finally {
getHelper().logout();
}
}
Aggregations