Search in sources :

Example 36 with IdmAutomaticRoleAttributeRuleDto

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

Example 37 with IdmAutomaticRoleAttributeRuleDto

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

Aggregations

IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)37 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)34 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)28 Test (org.junit.Test)25 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)17 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 UUID (java.util.UUID)14 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)11 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)11 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)7 IdmAutomaticRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)5 IdmAutomaticRoleAttributeRuleService (eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService)5 IdmAutomaticRoleAttributeService (eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService)5 List (java.util.List)5