Search in sources :

Example 26 with IdmAutomaticRoleAttributeRuleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testCreateIncompatibleRuleGreaterThen.

@Test(expected = ResultCodeException.class)
public void testCreateIncompatibleRuleGreaterThen() {
    IdmRoleDto role = getHelper().createRole();
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(getHelper().createName());
    automaticRole = automaticRoleAttributeService.save(automaticRole);
    IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
    rule.setComparison(AutomaticRoleAttributeRuleComparison.GREATER_THAN_OR_EQUAL);
    rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
    rule.setValue("10");
    rule.setAttributeName(IdmIdentity_.username.getName());
    rule.setAutomaticRoleAttribute(automaticRole.getId());
    automaticRoleAttributeRuleService.save(rule);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 27 with IdmAutomaticRoleAttributeRuleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testRemoveLastRuleWithCheck.

@Test
public void testRemoveLastRuleWithCheck() {
    String eavCode = "testingEav";
    Long testEavContractValue = System.currentTimeMillis();
    UUID testEavIdentityValue = UUID.randomUUID();
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmRoleDto role = getHelper().createRole();
    IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity.getId());
    // create two eav attributes (for identity and contract)
    IdmFormAttributeDto eavAttributeIdentity = getHelper().createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.UUID);
    getHelper().setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.UUID);
    IdmFormAttributeDto eavAttributeContract = getHelper().createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.LONG);
    getHelper().setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.LONG);
    IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
    IdmAutomaticRoleAttributeRuleDto rule1 = getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttributeIdentity.getId(), testEavIdentityValue.toString());
    IdmAutomaticRoleAttributeRuleDto rule2 = getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract.getId(), testEavContractValue.toString());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    automaticRoleAttributeRuleService.delete(rule1);
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // in process will be start LRT with async remove all identity roles
    automaticRoleAttributeRuleService.delete(rule2);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 28 with IdmAutomaticRoleAttributeRuleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleRequestService method realizeAttributeRules.

/**
 * Execute change of the request for attribute automatic role
 *
 * @param request
 * @param automaticRoleId
 * @param ruleConcepts
 */
private void realizeAttributeRules(IdmAutomaticRoleRequestDto request, IdmAutomaticRoleAttributeDto automaticRole, List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts) {
    // Create new rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.ADD == concept.getOperation();
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
        rule.setAutomaticRoleAttribute(automaticRole.getId());
        rule = automaticRoleRuleService.save(convertConceptRuleToRule(concept, rule));
        // Save created identity role id
        concept.setRule(rule.getId());
        automaticRoleRuleRequestService.save(concept);
    });
    // Update rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.UPDATE == concept.getOperation();
    }).filter(concept -> {
        return concept.getRule() != null;
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = automaticRoleRuleService.get(concept.getRule());
        rule = automaticRoleRuleService.save(convertConceptRuleToRule(concept, rule));
        // Save created identity role id
        concept.setRule(rule.getId());
        automaticRoleRuleRequestService.save(concept);
    });
    // Delete rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.REMOVE == concept.getOperation();
    }).filter(concept -> {
        return concept.getRule() != null;
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = automaticRoleRuleService.get(concept.getRule());
        if (rule != null) {
            concept.setRule(rule.getId());
            automaticRoleRuleRequestService.save(concept);
            // Finally delete of the rule
            automaticRoleRuleService.delete(rule);
        }
    });
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AutomaticRoleRequestEventType(eu.bcvsolutions.idm.core.model.event.AutomaticRoleRequestEvent.AutomaticRoleRequestEventType) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) Predicate(javax.persistence.criteria.Predicate) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) IdmAutomaticRole_(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole_) IdmAutomaticRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest_) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ImmutableMap(com.google.common.collect.ImmutableMap) IdmAutomaticRoleAttributeRuleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleRequestService) Collection(java.util.Collection) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Serializable(java.io.Serializable) List(java.util.List) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) HashMap(java.util.HashMap) IdmAutomaticRoleRequestRepository(eu.bcvsolutions.idm.core.model.repository.IdmAutomaticRoleRequestRepository) IdmRoleTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmRoleTreeNode) IdmTreeNode_(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode_) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmAutomaticRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) AutomaticRoleRequestType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Root(javax.persistence.criteria.Root) AutomaticRoleRequestEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleRequestEvent) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) IdmAutomaticRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest) ApplicationContext(org.springframework.context.ApplicationContext) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) IdmAutomaticRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) IdmAutomaticRoleAttribute(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleAttribute) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)

Example 29 with IdmAutomaticRoleAttributeRuleDto

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 roles
        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.count(identityFilter);
            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);
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 30 with IdmAutomaticRoleAttributeRuleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.

the class AutomaticRoleAttributeRuleSaveProcessor method process.

@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
    IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
    // 
    dto = automactiRoleAttributeRuleService.saveInternal(dto);
    event.setContent(dto);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)

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