Search in sources :

Example 46 with IdmAutomaticRoleAttributeDto

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());
}
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 47 with IdmAutomaticRoleAttributeDto

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());
}
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)

Example 48 with IdmAutomaticRoleAttributeDto

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());
}
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)

Example 49 with IdmAutomaticRoleAttributeDto

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!");
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 50 with IdmAutomaticRoleAttributeDto

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);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Aggregations

IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)44 Test (org.junit.Test)41 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)37 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)34 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)30 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)17 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)15 UUID (java.util.UUID)12 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)7 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)5 IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)5 LocalDate (org.joda.time.LocalDate)5 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)4 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)4