use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRoleViaManager.
@Test
public /**
* Test for AutomaticRoleManager. Create automatic role with rule.
*/
void testCreateAutomaticAttributeRoleViaManager() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, true, rule);
// Recalculate
Assert.assertNotNull(automaticRole.getId());
this.recalculateSync(automaticRole.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertFalse(identityRoles.isEmpty());
Assert.assertEquals(role.getId(), identityRoles.get(0).getRole());
Assert.assertNotNull(identityRoles.get(0).getRoleTreeNode());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testRemoveRule.
@Test
public void testRemoveRule() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identityTwo = helper.createIdentity();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, true, rule);
Assert.assertNotNull(automaticRole.getId());
IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
List<IdmAutomaticRoleAttributeRuleDto> rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(1, rules.size());
rule = rules.get(0);
rule.setValue(identityTwo.getUsername());
// Change automatic role via manager
automaticRole = automaticRoleManager.changeAutomaticRoleRules(automaticRole, true);
// Find current rules
rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(0, rules.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testAddRule.
@Test
public void testAddRule() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identityTwo = helper.createIdentity();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, true, rule);
Assert.assertNotNull(automaticRole.getId());
IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
List<IdmAutomaticRoleAttributeRuleDto> rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(1, rules.size());
rule = rules.get(0);
// Create new rule
IdmAutomaticRoleAttributeRuleDto newRule = new IdmAutomaticRoleAttributeRuleDto();
newRule.setAttributeName(IdmIdentity_.username.getName());
newRule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
newRule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
newRule.setValue(identityTwo.getUsername());
// Change automatic role via manager
automaticRole = automaticRoleManager.changeAutomaticRoleRules(automaticRole, true, newRule);
// Find current rules
rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(1, rules.size());
// We created new rule and deleted old
Assert.assertNotEquals(rule.getId(), rules.get(0).getId());
Assert.assertEquals(identityTwo.getUsername(), rules.get(0).getValue());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRoleWithApproval.
@Test
public void testCreateAutomaticAttributeRoleWithApproval() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto guaranteeIdentity = helper.createIdentity();
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(role.getId());
guarantee.setGuarantee(guaranteeIdentity.getId());
role.getGuarantees().add(guarantee);
role = roleService.save(role);
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
try {
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, false, rule);
} catch (AcceptedException ex) {
// The request is in approval
Assert.assertNotNull(ex.getIdentifier());
UUID requestId = UUID.fromString(ex.getIdentifier());
loginAsNoAdmin(guaranteeIdentity.getUsername());
try {
completeTasksFromUsers(guaranteeIdentity.getUsername(), "approve");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
Assert.assertEquals(RequestState.EXECUTED, request.getState());
Assert.assertNotNull(request.getAutomaticRole());
automaticRole = automaticRoleAttributeService.get(request.getAutomaticRole());
Assert.assertNotNull(automaticRole);
Assert.assertEquals(role.getId(), automaticRole.getRole());
return;
}
fail("Automatic role request have to be approving by gurantee!");
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class AutomaticRoleAttributeRuleDeleteProcessor method process.
@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
//
List<IdmAutomaticRoleAttributeRuleDto> allRules = automactiRoleAttributeRuleService.findAllRulesForAutomaticRole(dto.getAutomaticRoleAttribute());
// by default is skip value null => false
if (!this.getBooleanProperty(SKIP_CHECK_LAST_RULE, event.getProperties())) {
// it's last rule, remove all identity role
if (allRules.size() == 1 && dto.getId().equals(allRules.get(0).getId())) {
// before we start delete identity role, we check how many identities has the auto role
// if doesn't exist identities that has the role, skip remove
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
long totalElements = identityService.find(identityFilter, new PageRequest(0, 1)).getTotalElements();
if (totalElements > 0) {
UUID automaticRoleAttributeId = dto.getAutomaticRoleAttribute();
removeAllRoles(automaticRoleAttributeId);
//
// we also set concept to false
IdmAutomaticRoleAttributeDto roleAttributeDto = automaticRoleAttributeRuleService.get(automaticRoleAttributeId);
roleAttributeDto.setConcept(false);
roleAttributeDto = automaticRoleAttributeRuleService.save(roleAttributeDto);
}
}
}
UUID automaticRuleId = dto.getId();
// Find all automatic role requests and remove relation on rule
if (automaticRuleId != null) {
IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
automaticRoleRequestFilter.setRuleId(automaticRuleId);
ruleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
request.setRule(null);
ruleRequestService.save(request);
});
}
//
automactiRoleAttributeRuleService.deleteInternal(dto);
//
return new DefaultEventResult<>(event, this);
}
Aggregations