use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testDisableAutomaticRoleDuringSynchronization.
@Test
public void testDisableAutomaticRoleDuringSynchronization() {
// default initialization of system and all necessary things
SysSystemDto system = initData();
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
// we want start recalculation after synchronization
config.setStartAutoRoleRec(false);
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name";
String user1 = "test-1-" + System.currentTimeMillis();
this.getBean().setTestData(user1, testFirstName, testLastName);
String user2 = "test-2-" + System.currentTimeMillis();
this.getBean().setTestData(user2, testFirstName, testLastName);
String user3 = "test-3-" + System.currentTimeMillis();
this.getBean().setTestData(user3, testFirstName, testLastName);
IdmRoleDto role1 = helper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = helper.createAutomaticRole(role1.getId());
helper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, user1);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityDto identity1 = identityService.getByUsername(user1);
IdmIdentityDto identity2 = identityService.getByUsername(user2);
IdmIdentityDto identity3 = identityService.getByUsername(user3);
// we must change username, after create contract is also save identity (change state)
identity1.setUsername(user1 + System.currentTimeMillis());
identity1 = identityService.save(identity1);
helper.createIdentityContact(identity1);
helper.createIdentityContact(identity2);
helper.createIdentityContact(identity3);
List<IdmIdentityRoleDto> identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
List<IdmIdentityRoleDto> identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
List<IdmIdentityRoleDto> identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
assertEquals(0, identityRoles1.size());
assertEquals(0, identityRoles2.size());
assertEquals(0, identityRoles3.size());
// enable test processor
testIdentityProcessor.enable();
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
assertEquals(0, identityRoles1.size());
assertEquals(0, identityRoles2.size());
assertEquals(0, identityRoles3.size());
// synchronization immediately recalculate is disabled
int size = testIdentityProcessor.getRolesByUsername(user1).size();
assertEquals(0, size);
size = testIdentityProcessor.getRolesByUsername(user2).size();
assertEquals(0, size);
size = testIdentityProcessor.getRolesByUsername(user3).size();
assertEquals(0, size);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByAttributeTaskExecutor method process.
@Override
public Boolean process() {
UUID automaticRoleId = getAutomaticRoleId();
IdmAutomaticRoleAttributeDto automaticRolAttributeDto = automaticRoleAttributeService.get(automaticRoleId);
if (automaticRoleId == null || automaticRolAttributeDto == null) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_TASK_EMPTY);
}
Set<AbstractIdmAutomaticRoleDto> setWithAutomaticRole = Sets.newHashSet(automaticRolAttributeDto);
//
List<String> failedEntitiesAdd = new ArrayList<>();
List<String> failedEntitiesRemove = new ArrayList<>();
//
// by contract
Page<UUID> newPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, true, new PageRequest(0, PAGE_SIZE));
Page<UUID> newNotPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, false, new PageRequest(0, PAGE_SIZE));
//
counter = 0L;
count = Long.valueOf(newPassedContracts.getTotalElements() + newNotPassedContracts.getTotalElements());
//
// assign new passed roles
boolean canContinue = true;
//
// process contracts
canContinue = true;
while (canContinue) {
for (UUID contractId : newPassedContracts) {
IdmIdentityContractDto contract = identityContractService.get(contractId);
// check for contract validity
if (contract.getState() == ContractState.DISABLED || !contract.isValidNowOrInFuture()) {
continue;
}
//
try {
automaticRoleAttributeService.addAutomaticRoles(contract, setWithAutomaticRole);
counter++;
} catch (Exception ex) {
LOG.error("Error while add new automatic role id [{}] to contract id [{}] and identity id [{}]", automaticRoleId, contractId, contract.getIdentity(), ex);
failedEntitiesAdd.add(contractId.toString());
} finally {
canContinue = updateState();
if (!canContinue) {
break;
}
}
}
if (newPassedContracts.hasNext()) {
newPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, true, newPassedContracts.nextPageable());
} else {
break;
}
}
//
while (canContinue) {
for (UUID contractId : newNotPassedContracts) {
try {
automaticRoleAttributeService.removeAutomaticRoles(contractId, setWithAutomaticRole);
counter++;
} catch (Exception ex) {
LOG.error("Error while remove automatic role id [{}] from contract id [{}].", automaticRoleId, contractId, ex);
failedEntitiesRemove.add(contractId.toString());
} finally {
canContinue = updateState();
if (!canContinue) {
break;
}
}
}
if (newNotPassedContracts.hasNext()) {
newNotPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, false, newNotPassedContracts.nextPageable());
} else {
break;
}
}
//
if (!failedEntitiesAdd.isEmpty() || !failedEntitiesRemove.isEmpty()) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_PROCESS_TASK_NOT_COMPLETE, ImmutableMap.of("automaticRole", automaticRoleId, "failedAddEntities", StringUtils.join(failedEntitiesAdd, ","), "failedRemoveEntities", StringUtils.join(failedEntitiesRemove, ",")));
}
//
return Boolean.TRUE;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleContractExterneAttribute.
@Test
public void testAutomaticRoleContractExterneAttribute() {
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.externe.getName(), null, "true");
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
primeContract.setExterne(true);
primeContract = identityContractService.save(primeContract);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
primeContract.setExterne(false);
primeContract = identityContractService.save(primeContract);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testFilterRuleType.
@Test
public void testFilterRuleType() {
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(getTestName());
automaticRole = automaticRoleAttributeService.save(automaticRole);
//
IdmAutomaticRoleFilter filter = new IdmAutomaticRoleFilter();
filter.setRuleType(AutomaticRoleAttributeRuleType.CONTRACT);
List<IdmAutomaticRoleAttributeDto> content = automaticRoleAttributeService.find(filter, null).getContent();
assertEquals(0, content.size());
//
IdmAutomaticRoleAttributeRuleDto rule1 = new IdmAutomaticRoleAttributeRuleDto();
rule1.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule1.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule1.setValue("test");
rule1.setAttributeName(IdmIdentity_.username.getName());
rule1.setAutomaticRoleAttribute(automaticRole.getId());
automaticRoleAttributeRuleService.save(rule1);
//
filter = new IdmAutomaticRoleFilter();
filter.setRuleType(AutomaticRoleAttributeRuleType.CONTRACT);
content = automaticRoleAttributeService.find(filter, null).getContent();
assertEquals(0, content.size());
//
// try add next rules
IdmAutomaticRoleAttributeRuleDto rule2 = new IdmAutomaticRoleAttributeRuleDto();
rule2.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule2.setType(AutomaticRoleAttributeRuleType.CONTRACT);
rule2.setValue("test");
rule2.setAttributeName(IdmIdentityContract_.description.getName());
rule2.setAutomaticRoleAttribute(automaticRole.getId());
automaticRoleAttributeRuleService.save(rule2);
//
filter = new IdmAutomaticRoleFilter();
filter.setRuleType(AutomaticRoleAttributeRuleType.CONTRACT);
content = automaticRoleAttributeService.find(filter, null).getContent();
assertEquals(1, content.size());
IdmAutomaticRoleAttributeDto found = content.get(0);
assertEquals(automaticRole.getId(), found.getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleContractMainAttribute.
@Test
public void testAutomaticRoleContractMainAttribute() {
IdmIdentityDto identity = testHelper.createIdentity();
//
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.main.getName(), null, "false");
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
primeContract.setMain(false);
primeContract = identityContractService.save(primeContract);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
primeContract.setMain(true);
primeContract = identityContractService.save(primeContract);
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
Aggregations