Search in sources :

Example 1 with IdmIdentityRole

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.

the class IdentityRoleSaveProcessor method process.

@Override
public EventResult<IdmIdentityRoleDto> process(EntityEvent<IdmIdentityRoleDto> event) {
    IdmIdentityRoleDto identityRole = event.getContent();
    identityRole = service.saveInternal(identityRole);
    // TODO: Create validable DTO? Or validate in service?
    final IdmIdentityRole roleEntity = new IdmIdentityRole();
    modelMapper.map(identityRole, roleEntity);
    event.setContent(identityRole);
    // if identityRole isn't valid save request into validRequests
    if (!EntityUtils.isValid(roleEntity)) {
        // create new IdmIdentityRoleValidRequest
        validRequestService.createByIdentityRoleId(identityRole.getId());
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 2 with IdmIdentityRole

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.

the class IdentityAutomaticRoleFilter method getPredicate.

@Override
public Predicate getPredicate(Root<IdmIdentity> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmIdentityFilter filter) {
    if (filter.getAutomaticRoleId() == null) {
        return null;
    }
    Subquery<IdmIdentityRole> subquery = query.subquery(IdmIdentityRole.class);
    Root<IdmIdentityRole> subRoot = subquery.from(IdmIdentityRole.class);
    subquery.select(subRoot);
    subquery.where(builder.and(// correlation
    builder.equal(subRoot.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity), root), builder.equal(subRoot.get(IdmIdentityRole_.automaticRole).get(AbstractEntity_.id), filter.getAutomaticRoleId())));
    Predicate predicate = builder.exists(subquery);
    return predicate;
}
Also used : IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) Predicate(javax.persistence.criteria.Predicate)

Example 3 with IdmIdentityRole

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeService method getCriteriaForRulesByContract.

/**
 * Return all criteria for given rules by contract
 * Compose all specification for identity/contract and rules
 *
 * @param automaticRoleId
 * @param rules
 * @param onlyNew
 * @param passed
 * @param identityId
 * @param contractId
 * @return
 */
private Specification<IdmIdentityContract> getCriteriaForRulesByContract(UUID automaticRoleId, List<IdmAutomaticRoleAttributeRuleDto> rules, boolean passed, UUID contractId) {
    Specification<IdmIdentityContract> criteria = new Specification<IdmIdentityContract>() {

        @Override
        public Predicate toPredicate(Root<IdmIdentityContract> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            List<Predicate> predicates = new ArrayList<>();
            // 
            if (contractId != null) {
                predicates.add(cb.equal(root.get(AbstractEntity_.id), contractId));
            }
            // 
            Subquery<IdmIdentityRole> subquery = query.subquery(IdmIdentityRole.class);
            Root<IdmIdentityRole> subRoot = subquery.from(IdmIdentityRole.class);
            subquery.select(subRoot);
            subquery.where(cb.and(// correlation attr
            cb.equal(subRoot.get(IdmIdentityRole_.identityContract), root), cb.equal(subRoot.get(IdmIdentityRole_.automaticRole).get(IdmAutomaticRole_.id), automaticRoleId)));
            // 
            if (passed) {
                predicates.add(cb.isNull(subquery));
            } else {
                predicates.add(cb.exists(subquery));
            }
            // 
            List<Predicate> predicatesFromRules = new ArrayList<>();
            for (IdmAutomaticRoleAttributeRuleDto rule : rules) {
                // compose all predicate from rules
                Predicate predicate = DefaultIdmAutomaticRoleAttributeService.this.getPredicateForRuleByContract(rule, root, query, cb, passed);
                predicatesFromRules.add(predicate);
            }
            // 
            if (!predicatesFromRules.isEmpty()) {
                if (!passed) {
                    // if we find all rules that not pass is necessary add 'or' statement between predicates from rules
                    Predicate or = cb.or(predicatesFromRules.toArray(new Predicate[predicatesFromRules.size()]));
                    predicates.add(or);
                } else {
                    predicates.addAll(predicatesFromRules);
                }
            }
            return query.where(predicates.toArray(new Predicate[predicates.size()])).getRestriction();
        }
    };
    return criteria;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ArrayList(java.util.ArrayList) Specification(org.springframework.data.jpa.domain.Specification) Predicate(javax.persistence.criteria.Predicate) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)

Example 4 with IdmIdentityRole

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityRoleService method toEntity.

@Override
protected IdmIdentityRole toEntity(IdmIdentityRoleDto dto, IdmIdentityRole entity) {
    IdmIdentityRole resultEntity = super.toEntity(dto, entity);
    // set additional automatic role
    if (resultEntity != null && dto.getRoleTreeNode() != null) {
        // it isn't possible use lookupService entity lookup
        IdmAutomaticRole automaticRole = automaticRoleRepository.findOne(dto.getRoleTreeNode());
        resultEntity.setAutomaticRole(automaticRole);
    }
    return resultEntity;
}
Also used : IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) IdmAutomaticRole(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole)

Example 5 with IdmIdentityRole

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.

the class IdentityRoleValidRequestSchedulerTest method createNonValidRoleAndValid.

@Test
public void createNonValidRoleAndValid() throws InterruptedException, ExecutionException {
    IdmIdentityDto identity = createAndSaveIdentity();
    IdmRoleDto role = createAndSaveRole();
    createAndSaveRoleSystem(role, system);
    IdmTreeTypeDto treeType = createAndSaveTreeType();
    IdmTreeNodeDto treeNode = createAndSaveTreeNode(treeType);
    IdmIdentityContractDto identityContract = createAndSaveIdentityContract(identity, treeNode);
    LocalDate validFrom = new LocalDate();
    // set plus days
    validFrom = validFrom.plusDays(5);
    // provisioning is not executed, role isn't valid from now
    createAndSaveIdentityRole(identityContract, role, null, validFrom);
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    List<AccIdentityAccountDto> list = identityAccountService.find(filter, null).getContent();
    // it must not exists
    assertEquals(true, list.isEmpty());
    // 
    IdentityRoleValidRequestTaskExecutor taskExecutor1 = new IdentityRoleValidRequestTaskExecutor();
    LongRunningFutureTask<Boolean> futureTask1 = longRunningTaskManager.execute(taskExecutor1);
    assertEquals(true, futureTask1.getFutureTask().get());
    IdmLongRunningTaskDto longRunningTask1 = longRunningTaskService.get(taskExecutor1.getLongRunningTaskId());
    assertEquals(OperationState.EXECUTED, longRunningTask1.getResult().getState());
    list = identityAccountService.find(filter, null).getContent();
    // still empty, role isn't valid
    assertEquals(true, list.isEmpty());
    List<IdmIdentityRole> roles = identityRoleRepository.findAllByIdentityContract_Identity_Id(identity.getId(), null);
    assertEquals(1, roles.size());
    IdmIdentityRole identityRole = roles.get(0);
    validFrom = new LocalDate();
    validFrom = validFrom.minusDays(5);
    identityRole.setValidFrom(validFrom);
    identityRoleRepository.save(identityRole);
    // execute again
    IdentityRoleValidRequestTaskExecutor taskExecutor2 = new IdentityRoleValidRequestTaskExecutor();
    LongRunningFutureTask<Boolean> futureTask2 = longRunningTaskManager.execute(taskExecutor2);
    assertEquals(true, futureTask2.getFutureTask().get());
    IdmLongRunningTaskDto longRunningTask2 = longRunningTaskService.get(taskExecutor2.getLongRunningTaskId());
    assertEquals(OperationState.EXECUTED, longRunningTask2.getResult().getState());
    list = identityAccountService.find(filter, null).getContent();
    assertEquals(false, list.isEmpty());
    assertEquals(1, list.size());
    // newly created accounts
    assertNotNull(list.get(0));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) LocalDate(org.joda.time.LocalDate) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) IdentityRoleValidRequestTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.IdentityRoleValidRequestTaskExecutor) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityRole (eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole)9 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)4 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)4 ArrayList (java.util.ArrayList)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)2 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)2 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)2 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)2 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)2 IdentityRoleValidRequestTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.IdentityRoleValidRequestTaskExecutor)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 UUID (java.util.UUID)2 Predicate (javax.persistence.criteria.Predicate)2 LocalDate (org.joda.time.LocalDate)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)1