Search in sources :

Example 11 with IdmIdentityContract

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

the class DefaultIdmIdentityContractServiceUnitTest method testSimpleDisabledPrimeContract.

@Test
public void testSimpleDisabledPrimeContract() {
    List<IdmIdentityContract> contracts = new ArrayList<>();
    IdmIdentityContract invalidContract = new IdmIdentityContract(UUID.randomUUID());
    invalidContract.setMain(true);
    invalidContract.setDisabled(true);
    IdmIdentityContract mainContract = new IdmIdentityContract(UUID.randomUUID());
    mainContract.setMain(true);
    contracts.add(invalidContract);
    contracts.add(mainContract);
    // 
    when(repository.findAllByIdentity_Id(any(UUID.class), any())).thenReturn(contracts);
    when(treeConfiguration.getDefaultType()).thenReturn(null);
    // 
    Assert.assertEquals(mainContract.getId(), service.getPrimeContract(UUID.randomUUID()).getId());
}
Also used : ArrayList(java.util.ArrayList) UUID(java.util.UUID) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 12 with IdmIdentityContract

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

the class IdentityRoleAddAuthoritiesProcessor method checkAddedPermissions.

private void checkAddedPermissions(IdmIdentityRoleDto identityRole) {
    IdmIdentityContract contract = contractRepository.findOne(identityRole.getIdentityContract());
    IdmIdentity identity = contract.getIdentity();
    List<IdmIdentityRoleDto> withoutAdded = identityRoleService.findAllByIdentity(identity.getId());
    withoutAdded.remove(identityRole);
    // represents the final authorities set after role removal
    Collection<? extends GrantedAuthority> original = authorityHierarchy.getReachableGrantedAuthorities(authoritiesFactory.getGrantedAuthoritiesForValidRoles(identity.getId(), withoutAdded));
    Collection<? extends GrantedAuthority> addedAuthorities = authorityHierarchy.getReachableGrantedAuthorities(authoritiesFactory.getGrantedAuthoritiesForValidRoles(identity.getId(), Collections.singletonList(identityRole)));
    if (!authoritiesFactory.containsAllAuthorities(original, addedAuthorities)) {
        // authorities were changed, update identity flag
        IdmAuthorityChange ac = repository.findOneByIdentity_Id(identity.getId());
        if (ac == null) {
            ac = new IdmAuthorityChange();
            ac.setIdentity(identity);
        }
        ac.authoritiesChanged();
        repository.save(ac);
    }
}
Also used : IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)

Example 13 with IdmIdentityContract

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

the class IdentityRoleDeleteAuthoritiesProcessor method checkRevokedPermissions.

private void checkRevokedPermissions(IdmIdentityRoleDto identityRole) {
    IdmIdentityContract contract = contractRepository.findOne(identityRole.getIdentityContract());
    IdmIdentity identity = contract.getIdentity();
    List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identity.getId());
    roles.remove(identityRole);
    // represents the final authorities set after role removal
    Collection<? extends GrantedAuthority> withoutDeleted = authorityHierarchy.getReachableGrantedAuthorities(authoritiesFactory.getGrantedAuthoritiesForValidRoles(identity.getId(), roles));
    Collection<? extends GrantedAuthority> deletedAuthorities = authorityHierarchy.getReachableGrantedAuthorities(authoritiesFactory.getGrantedAuthoritiesForValidRoles(identity.getId(), Collections.singletonList(identityRole)));
    if (!authoritiesFactory.containsAllAuthorities(withoutDeleted, deletedAuthorities)) {
        // authorities were changed, update identity flag
        IdmAuthorityChange ac = repository.findOneByIdentity_Id(identity.getId());
        if (ac == null) {
            ac = new IdmAuthorityChange();
            ac.setIdentity(identity);
        }
        ac.authoritiesChanged();
        repository.save(ac);
    }
}
Also used : IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)

Example 14 with IdmIdentityContract

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

the class DefaultIdmAutomaticRoleAttributeService method getPredicateForRuleByContract.

/**
 * Return predicate for given rule by contract
 *
 * @param rule
 * @param root
 * @param query
 * @param cb
 * @return
 */
private Predicate getPredicateForRuleByContract(IdmAutomaticRoleAttributeRuleDto rule, Root<IdmIdentityContract> root, CriteriaQuery<?> query, CriteriaBuilder cb, boolean pass) {
    // 
    Metamodel metamodel = entityManager.getMetamodel();
    if (rule.getType() == AutomaticRoleAttributeRuleType.CONTRACT) {
        SingularAttribute<? super IdmIdentityContract, ?> singularAttribute = metamodel.entity(IdmIdentityContract.class).getSingularAttribute(rule.getAttributeName());
        Path<Object> path = root.get(singularAttribute.getName());
        return getPredicateWithComparsion(path, castToType(singularAttribute, rule.getValue()), cb, rule.getComparison(), !pass);
    } else if (rule.getType() == AutomaticRoleAttributeRuleType.CONTRACT_EAV) {
        IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
        // 
        Object value = getEavValue(rule.getValue(), formAttributeDto.getPersistentType());
        // 
        Subquery<IdmIdentityContractFormValue> subquery = query.subquery(IdmIdentityContractFormValue.class);
        Root<IdmIdentityContractFormValue> subRoot = subquery.from(IdmIdentityContractFormValue.class);
        subquery.select(subRoot);
        // 
        Path<?> path = subRoot.get(getSingularAttributeForEav(formAttributeDto.getPersistentType()));
        // 
        subquery.where(cb.and(cb.equal(subRoot.get(IdmIdentityContractFormValue_.owner), root), cb.equal(subRoot.get(IdmIdentityContractFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, value, cb, rule.getComparison(), null)));
        // 
        Predicate existsInEav = getPredicateForConnection(subquery, cb, pass);
        // 
        return existsInEav;
    } else if (rule.getType() == AutomaticRoleAttributeRuleType.IDENTITY_EAV) {
        IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
        // 
        Object value = getEavValue(rule.getValue(), formAttributeDto.getPersistentType());
        // 
        Subquery<IdmIdentity> subquery = query.subquery(IdmIdentity.class);
        Root<IdmIdentity> subRoot = subquery.from(IdmIdentity.class);
        subquery.select(subRoot);
        Subquery<IdmIdentityFormValue> subQueryIdentityEav = query.subquery(IdmIdentityFormValue.class);
        Root<IdmIdentityFormValue> subRootIdentityEav = subQueryIdentityEav.from(IdmIdentityFormValue.class);
        subQueryIdentityEav.select(subRootIdentityEav);
        // 
        Path<?> path = subRootIdentityEav.get(getSingularAttributeForEav(formAttributeDto.getPersistentType()));
        subQueryIdentityEav.where(cb.and(cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.owner), subRoot), cb.equal(root.get(IdmIdentityContract_.identity), subRoot), cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, value, cb, rule.getComparison(), null)));
        // 
        Predicate existsInEav = getPredicateForConnection(subQueryIdentityEav, cb, pass);
        // 
        subquery.where(cb.and(cb.equal(subRoot.get(IdmIdentity_.id), root.get(IdmIdentityContract_.identity).get(AbstractEntity_.id)), existsInEav));
        // 
        return cb.exists(subquery);
    } else if (rule.getType() == AutomaticRoleAttributeRuleType.IDENTITY) {
        Subquery<IdmIdentity> subquery = query.subquery(IdmIdentity.class);
        Root<IdmIdentity> subRoot = subquery.from(IdmIdentity.class);
        subquery.select(subRoot);
        // 
        SingularAttribute<? super IdmIdentity, ?> singularAttribute = metamodel.entity(IdmIdentity.class).getSingularAttribute(rule.getAttributeName());
        Path<Object> path = subRoot.get(singularAttribute.getName());
        // 
        subquery.where(// correlation attr
        cb.and(// correlation attr
        cb.equal(subRoot.get(IdmIdentity_.id), root.get(IdmIdentityContract_.identity).get(AbstractEntity_.id)), getPredicateWithComparsion(path, castToType(singularAttribute, rule.getValue()), cb, rule.getComparison(), null)));
        // 
        return getPredicateForConnection(subquery, cb, pass);
    } else {
        throw new UnsupportedOperationException("Type: " + rule.getType().name() + ", isn't supported for contract rules!");
    }
}
Also used : Path(javax.persistence.criteria.Path) Root(javax.persistence.criteria.Root) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) Subquery(javax.persistence.criteria.Subquery) Predicate(javax.persistence.criteria.Predicate) SingularAttribute(javax.persistence.metamodel.SingularAttribute) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Metamodel(javax.persistence.metamodel.Metamodel) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmIdentityContractFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityContractFormValue)

Aggregations

IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)14 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)8 UUID (java.util.UUID)8 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 LocalDate (org.joda.time.LocalDate)3 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)2 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)2 IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)2 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)2 IdmTreeType (eu.bcvsolutions.idm.core.model.entity.IdmTreeType)2 Predicate (javax.persistence.criteria.Predicate)2 Root (javax.persistence.criteria.Root)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)1 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)1 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1