use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto 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.IdmAutomaticRoleAttributeDto 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.IdmAutomaticRoleAttributeDto 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.IdmAutomaticRoleAttributeDto 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.IdmAutomaticRoleAttributeDto in project CzechIdMng by bcvsolutions.
the class AutomaticRoleAttributeCreateProcessor method process.
@Override
public EventResult<IdmAutomaticRoleAttributeDto> process(EntityEvent<IdmAutomaticRoleAttributeDto> event) {
IdmAutomaticRoleAttributeDto automaticRoleAttributeDto = event.getContent();
//
automaticRoleAttributeDto = service.saveInternal(automaticRoleAttributeDto);
event.setContent(automaticRoleAttributeDto);
//
return new DefaultEventResult<>(event, this);
}
Aggregations