Search in sources :

Example 51 with IdmTokenDto

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);
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID)

Example 52 with IdmTokenDto

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);
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 53 with IdmTokenDto

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);
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 54 with IdmTokenDto

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

Example 55 with IdmTokenDto

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

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