use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRoleViaManager.
/**
* Test for AutomaticRoleManager. Create automatic role with rule.
*/
@Test
public void testCreateAutomaticAttributeRoleViaManager() {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
try {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getCode());
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());
getHelper().waitForResult(res -> {
return identityRoleService.findAllByIdentity(identity.getId()).isEmpty();
});
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertFalse(identityRoles.isEmpty());
Assert.assertEquals(1, identityRoles.size());
Assert.assertEquals(role.getId(), identityRoles.get(0).getRole());
Assert.assertNotNull(identityRoles.get(0).getAutomaticRole());
} finally {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testRemoveRule.
@Test
public void testRemoveRule() {
getHelper().setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
//
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getCode());
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());
}
Aggregations