Search in sources :

Example 41 with IdmIdentity

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

the class IdentityGuaranteesForRoleFilterIntegrationTest method testFindGuaranteesByTypeInIdentityAndRole.

@Test
public void testFindGuaranteesByTypeInIdentityAndRole() {
    // prepare data
    String guaranteeType = getHelper().createName();
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityThree = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto role = getHelper().createRole();
    IdmRoleDto roleGuarantee = getHelper().createRole();
    getHelper().createRoleGuarantee(role, identityOne, guaranteeType);
    getHelper().createRoleGuaranteeRole(role, roleGuarantee, guaranteeType);
    getHelper().createIdentityRole(identityThree, roleGuarantee);
    getHelper().createIdentityRole(identityTwo, role);
    // 
    IdmIdentityFilter dataFilter = new IdmIdentityFilter();
    dataFilter.setGuaranteesForRole(role.getId());
    dataFilter.setGuaranteeType(guaranteeType);
    List<IdmIdentity> identities = filter.find(dataFilter, null).getContent();
    // 
    Assert.assertEquals(2, identities.size());
    Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityOne.getId())));
    Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityThree.getId())));
}
Also used : List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 42 with IdmIdentity

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

the class IdentityGuaranteesForRoleFilterIntegrationTest method testFindWithGuaranteeType.

@Test
public void testFindWithGuaranteeType() {
    // prepare data
    String guaranteeType = getHelper().createName();
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityThree = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto role = getHelper().createRole();
    IdmRoleDto roleGuarantee = getHelper().createRole();
    getHelper().createRoleGuarantee(role, identityOne, guaranteeType);
    getHelper().createRoleGuaranteeRole(role, roleGuarantee, guaranteeType);
    getHelper().createIdentityRole(identityThree, roleGuarantee);
    getHelper().createIdentityRole(identityTwo, role);
    // 
    IdmIdentityFilter dataFilter = new IdmIdentityFilter();
    dataFilter.setGuaranteesForRole(role.getId());
    List<IdmIdentity> identities = filter.find(dataFilter, null).getContent();
    // 
    Assert.assertEquals(2, identities.size());
    Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityOne.getId())));
    Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityThree.getId())));
}
Also used : List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 43 with IdmIdentity

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

the class PhoneIdentityFilterBuilderIntegrationTest method testFindIdentityByPhone.

@Test
public void testFindIdentityByPhone() {
    // prepare data
    IdmIdentityDto identityOne = new IdmIdentityDto(getHelper().createName());
    identityOne.setPhone(getHelper().createName().substring(0, 30));
    identityOne = identityService.save(identityOne);
    IdmIdentityDto identityTwo = new IdmIdentityDto(getHelper().createName());
    identityTwo.setPhone(getHelper().createName().substring(0, 30));
    identityTwo = identityService.save(identityTwo);
    // 
    IdmIdentityFilter dataFilter = new IdmIdentityFilter();
    dataFilter.setPhone(identityOne.getPhone());
    List<IdmIdentity> identities = filter.find(dataFilter, null).getContent();
    // 
    assertEquals(1, identities.size());
    assertEquals(identityOne.getId(), identities.get(0).getId());
    // 
    dataFilter.setPhone(identityTwo.getPhone());
    identities = filter.find(dataFilter, null).getContent();
    assertEquals(1, identities.size());
    assertEquals(identityTwo.getId(), identities.get(0).getId());
}
Also used : IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 44 with IdmIdentity

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity 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());
        // role will be added and wich roles will be removed.
        return getPredicateWithComparsion(path, castToType(singularAttribute, rule.getValue(), rule.getComparison()), cb, rule.getComparison(), !pass);
    } else if (rule.getType() == AutomaticRoleAttributeRuleType.CONTRACT_EAV) {
        IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
        AutomaticRoleAttributeRuleComparison comparison = rule.getComparison();
        // Cast given value to specific persistent type
        // For is empty and is not empty comparison is returned null even if value exists
        Object value = getFormValue(rule.getValue(), formAttributeDto, comparison);
        // 
        // For contract form attribute was composed only one subquery
        Subquery<IdmIdentityContractFormValue> subquery = query.subquery(IdmIdentityContractFormValue.class);
        Root<IdmIdentityContractFormValue> subRoot = subquery.from(IdmIdentityContractFormValue.class);
        subquery.select(subRoot);
        // 
        Path<?> path = subRoot.get(getSingularAttributeForEav(formAttributeDto.getPersistentType()));
        // Is empty comparison has specific behavior because form value isn't empty, but value doesn't exist
        if (comparison == AutomaticRoleAttributeRuleComparison.IS_EMPTY) {
            subquery.where(cb.or(// Predicate for check if value exists
            getPredicateForNullFormAttributeIdentityContract(root, query, cb, formAttributeDto), cb.and(cb.equal(subRoot.get(IdmIdentityContractFormValue_.owner), root), cb.equal(subRoot.get(IdmIdentityContractFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, null, cb, rule.getComparison(), null))));
            if (pass) {
                return cb.not(cb.exists(subquery));
            }
            return cb.exists(subquery);
        }
        // 
        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, formAttributeDto.isMultiple());
        // For comparison with not is required also check null values
        if (comparison == AutomaticRoleAttributeRuleComparison.NOT_CONTAINS || comparison == AutomaticRoleAttributeRuleComparison.NOT_END_WITH || comparison == AutomaticRoleAttributeRuleComparison.NOT_EQUALS || comparison == AutomaticRoleAttributeRuleComparison.NOT_START_WITH) {
            if (pass) {
                existsInEav = cb.or(existsInEav, cb.not(getPredicateForNullFormAttributeIdentityContract(root, query, cb, formAttributeDto)));
            } else {
                existsInEav = cb.and(existsInEav, getPredicateForNullFormAttributeIdentityContract(root, query, cb, formAttributeDto));
            }
        }
        // 
        return existsInEav;
    } else if (rule.getType() == AutomaticRoleAttributeRuleType.IDENTITY_EAV) {
        IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
        AutomaticRoleAttributeRuleComparison comparison = rule.getComparison();
        // Cast given value to specific persistent type
        // For is empty and is not empty comparison is returned null even if value exists
        Object value = getFormValue(rule.getValue(), formAttributeDto, comparison);
        // 
        // Rules for identity form values must contains two subquery identity -> identity eav
        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()));
        // Is empty comparison has specific behavior because form value isn't empty, but value doesn't exist
        if (comparison == AutomaticRoleAttributeRuleComparison.IS_EMPTY) {
            subquery.where(cb.and(cb.equal(root.get(IdmIdentityContract_.identity), subRoot), cb.or(cb.exists(subQueryIdentityEav.where(cb.and(cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.owner), subRoot), cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, null, cb, rule.getComparison(), null)))), // Predicate for check if value exists
            getPredicateForNullFormAttributeIdentity(subRoot, subquery, cb, formAttributeDto))));
            // 
            if (pass) {
                return cb.not(cb.exists(subquery));
            }
            return cb.exists(subquery);
        }
        // 
        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, formAttributeDto.isMultiple());
        // For comparison with not is required also check null values
        if (comparison == AutomaticRoleAttributeRuleComparison.NOT_CONTAINS || comparison == AutomaticRoleAttributeRuleComparison.NOT_END_WITH || comparison == AutomaticRoleAttributeRuleComparison.NOT_EQUALS || comparison == AutomaticRoleAttributeRuleComparison.NOT_START_WITH) {
            if (pass) {
                existsInEav = cb.or(existsInEav, cb.not(getPredicateForNullFormAttributeIdentity(subRoot, subquery, cb, formAttributeDto)));
            } else {
                existsInEav = cb.and(existsInEav, getPredicateForNullFormAttributeIdentity(subRoot, subquery, cb, formAttributeDto));
            }
        }
        // 
        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(), rule.getComparison()), cb, rule.getComparison(), null)));
        // 
        return getPredicateForConnection(subquery, cb, pass, false);
    } else {
        throw new UnsupportedOperationException("Type: " + rule.getType().name() + ", isn't supported for contract rules!");
    }
}
Also used : Path(javax.persistence.criteria.Path) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) 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)

Example 45 with IdmIdentity

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

the class RoleRequestByIdentityEvaluator method getPermissions.

@Override
public Set<String> getPermissions(IdmRoleRequest entity, AuthorizationPolicy policy) {
    Set<String> permissions = super.getPermissions(entity, policy);
    // Add permissions, when CHANGEPERMISSION or CANBEREQUESTED is available on at least one contract of selected identity.
    IdmIdentity applicant = entity.getApplicant();
    if (applicant != null) {
        IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
        filter.setEvaluatePermissionOperator(PermissionContext.OPERATOR_OR);
        filter.setIdentity(applicant.getId());
        // 
        if (contractService.count(filter, ContractBasePermission.CHANGEPERMISSION, ContractBasePermission.CANBEREQUESTED) > 0) {
            permissions.add(IdmBasePermission.READ.getName());
            permissions.add(IdmBasePermission.CREATE.getName());
            permissions.add(IdmBasePermission.UPDATE.getName());
            permissions.add(IdmBasePermission.DELETE.getName());
        }
    }
    return permissions;
}
Also used : IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity)

Aggregations

IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)58 Test (org.junit.Test)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)18 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)13 Transactional (org.springframework.transaction.annotation.Transactional)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)7 DataFilter (eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)5 Assert (org.junit.Assert)5 IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)4 UUID (java.util.UUID)4 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)3 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3