Search in sources :

Example 1 with AssignableCond

use of org.apache.syncope.core.persistence.api.dao.search.AssignableCond in project syncope by apache.

the class JPAGroupDAO method buildDynMembershipCond.

private SearchCond buildDynMembershipCond(final String baseCondFIQL, final Realm groupRealm) {
    AssignableCond cond = new AssignableCond();
    cond.setRealmFullPath(groupRealm.getFullPath());
    cond.setFromGroup(true);
    return SearchCond.getAndCond(SearchCond.getLeafCond(cond), SearchCondConverter.convert(baseCondFIQL));
}
Also used : AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond)

Example 2 with AssignableCond

use of org.apache.syncope.core.persistence.api.dao.search.AssignableCond in project syncope by apache.

the class SyncopeLogic method searchAssignableGroups.

@PreAuthorize("isAuthenticated()")
public Pair<Integer, List<GroupTO>> searchAssignableGroups(final String realm, final String term, final int page, final int size) {
    AssignableCond assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath(realm);
    SearchCond searchCond;
    if (StringUtils.isNotBlank(term)) {
        AnyCond termCond = new AnyCond(AttributeCond.Type.ILIKE);
        termCond.setSchema("name");
        String termSearchableValue = (term.startsWith("*") && !term.endsWith("*")) ? term + "%" : (!term.startsWith("*") && term.endsWith("*")) ? "%" + term : (term.startsWith("*") && term.endsWith("*") ? term : "%" + term + "%");
        termCond.setExpression(termSearchableValue);
        searchCond = SearchCond.getAndCond(SearchCond.getLeafCond(assignableCond), SearchCond.getLeafCond(termCond));
    } else {
        searchCond = SearchCond.getLeafCond(assignableCond);
    }
    int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, AnyTypeKind.GROUP);
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("name");
    orderByClause.setDirection(OrderByClause.Direction.ASC);
    List<Group> matching = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, page, size, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
    List<GroupTO> result = matching.stream().map(group -> groupDataBinder.getGroupTO(group, false)).collect(Collectors.toList());
    return Pair.of(count, result);
}
Also used : Arrays(java.util.Arrays) SecurityQuestionDAO(org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO) AopUtils(org.springframework.aop.support.AopUtils) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) GroupProvisioningManager(org.apache.syncope.core.provisioning.api.GroupProvisioningManager) PlatformInfo(org.apache.syncope.common.lib.info.PlatformInfo) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) InetAddress(java.net.InetAddress) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) URI(java.net.URI) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Method(java.lang.reflect.Method) PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) RuntimeMXBean(java.lang.management.RuntimeMXBean) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) GroupWorkflowAdapter(org.apache.syncope.core.workflow.api.GroupWorkflowAdapter) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) NotificationDAO(org.apache.syncope.core.persistence.api.dao.NotificationDAO) EntitlementsHolder(org.apache.syncope.core.provisioning.api.EntitlementsHolder) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SystemInfo(org.apache.syncope.common.lib.info.SystemInfo) List(java.util.List) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) ConnIdBundleManager(org.apache.syncope.core.provisioning.api.ConnIdBundleManager) PropagationTaskExecutor(org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) VirAttrCache(org.apache.syncope.core.provisioning.api.cache.VirAttrCache) AbstractBaseBean(org.apache.syncope.common.lib.AbstractBaseBean) NumbersInfo(org.apache.syncope.common.lib.info.NumbersInfo) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) PasswordGenerator(org.apache.syncope.core.spring.security.PasswordGenerator) GroupDataBinder(org.apache.syncope.core.provisioning.api.data.GroupDataBinder) UserWorkflowAdapter(org.apache.syncope.core.workflow.api.UserWorkflowAdapter) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) AnyObjectProvisioningManager(org.apache.syncope.core.provisioning.api.AnyObjectProvisioningManager) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Iterator(java.util.Iterator) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) UnknownHostException(java.net.UnknownHostException) ImplementationLookup(org.apache.syncope.core.persistence.api.ImplementationLookup) Component(org.springframework.stereotype.Component) UserProvisioningManager(org.apache.syncope.core.provisioning.api.UserProvisioningManager) JavaImplInfo(org.apache.syncope.common.lib.info.JavaImplInfo) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) AnyObjectWorkflowAdapter(org.apache.syncope.core.workflow.api.AnyObjectWorkflowAdapter) TaskType(org.apache.syncope.common.lib.types.TaskType) Transactional(org.springframework.transaction.annotation.Transactional) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) Group(org.apache.syncope.core.persistence.api.entity.group.Group) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with AssignableCond

use of org.apache.syncope.core.persistence.api.dao.search.AssignableCond in project syncope by apache.

the class AnySearchTest method assignable.

@Test
public void assignable() {
    AssignableCond assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath("/even/two");
    SearchCond searchCondition = SearchCond.getLeafCond(assignableCond);
    assertTrue(searchCondition.isValid());
    List<Group> groups = searchDAO.search(searchCondition, AnyTypeKind.GROUP);
    assertTrue(groups.stream().anyMatch(group -> "additional".equals(group.getName())));
    assertFalse(groups.stream().anyMatch(group -> "fake".equals(group.getName())));
    assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath("/odd");
    searchCondition = SearchCond.getLeafCond(assignableCond);
    assertTrue(searchCondition.isValid());
    List<AnyObject> anyObjects = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertFalse(anyObjects.stream().anyMatch(anyObject -> "9e1d130c-d6a3-48b1-98b3-182477ed0688".equals(anyObject.getKey())));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) RoleCond(org.apache.syncope.core.persistence.api.dao.search.RoleCond) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) PrivilegeCond(org.apache.syncope.core.persistence.api.dao.search.PrivilegeCond) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) ResourceCond(org.apache.syncope.core.persistence.api.dao.search.ResourceCond) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) MemberCond(org.apache.syncope.core.persistence.api.dao.search.MemberCond) Test(org.junit.jupiter.api.Test) List(java.util.List) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) RelationshipCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipCond) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 4 with AssignableCond

use of org.apache.syncope.core.persistence.api.dao.search.AssignableCond in project syncope by apache.

the class SearchCondVisitor method visitPrimitive.

@SuppressWarnings("ConvertToStringSwitch")
private SearchCond visitPrimitive(final SearchCondition<SearchBean> sc) {
    String name = getRealPropertyName(sc.getStatement().getProperty());
    Optional<SpecialAttr> specialAttrName = SpecialAttr.fromString(name);
    String value = null;
    try {
        value = SearchUtils.toSqlWildcardString(URLDecoder.decode(sc.getStatement().getValue().toString(), StandardCharsets.UTF_8.name()), false).replaceAll("\\\\_", "_");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("While decoding " + sc.getStatement().getValue(), e);
    }
    Optional<SpecialAttr> specialAttrValue = SpecialAttr.fromString(value);
    AttributeCond attributeCond = createAttributeCond(name);
    attributeCond.setExpression(value);
    ConditionType ct = sc.getConditionType();
    if (sc instanceof SyncopeFiqlSearchCondition && sc.getConditionType() == ConditionType.CUSTOM) {
        SyncopeFiqlSearchCondition<SearchBean> sfsc = (SyncopeFiqlSearchCondition<SearchBean>) sc;
        if (SyncopeFiqlParser.IEQ.equals(sfsc.getOperator())) {
            ct = ConditionType.EQUALS;
        } else if (SyncopeFiqlParser.NIEQ.equals(sfsc.getOperator())) {
            ct = ConditionType.NOT_EQUALS;
        } else {
            throw new IllegalArgumentException(String.format("Condition type %s is not supported", sfsc.getOperator()));
        }
    }
    SearchCond leaf;
    switch(ct) {
        case EQUALS:
        case NOT_EQUALS:
            if (!specialAttrName.isPresent()) {
                if (specialAttrValue.isPresent() && specialAttrValue.get() == SpecialAttr.NULL) {
                    attributeCond.setType(AttributeCond.Type.ISNULL);
                    attributeCond.setExpression(null);
                } else if (value.indexOf('%') == -1) {
                    attributeCond.setType(sc.getConditionType() == ConditionType.CUSTOM ? AttributeCond.Type.IEQ : AttributeCond.Type.EQ);
                } else {
                    attributeCond.setType(sc.getConditionType() == ConditionType.CUSTOM ? AttributeCond.Type.ILIKE : AttributeCond.Type.LIKE);
                }
                leaf = SearchCond.getLeafCond(attributeCond);
            } else {
                switch(specialAttrName.get()) {
                    case TYPE:
                        AnyTypeCond typeCond = new AnyTypeCond();
                        typeCond.setAnyTypeKey(value);
                        leaf = SearchCond.getLeafCond(typeCond);
                        break;
                    case RESOURCES:
                        ResourceCond resourceCond = new ResourceCond();
                        resourceCond.setResourceKey(value);
                        leaf = SearchCond.getLeafCond(resourceCond);
                        break;
                    case GROUPS:
                        MembershipCond groupCond = new MembershipCond();
                        groupCond.setGroup(value);
                        leaf = SearchCond.getLeafCond(groupCond);
                        break;
                    case RELATIONSHIPS:
                        RelationshipCond relationshipCond = new RelationshipCond();
                        relationshipCond.setAnyObject(value);
                        leaf = SearchCond.getLeafCond(relationshipCond);
                        break;
                    case RELATIONSHIP_TYPES:
                        RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
                        relationshipTypeCond.setRelationshipTypeKey(value);
                        leaf = SearchCond.getLeafCond(relationshipTypeCond);
                        break;
                    case ROLES:
                        RoleCond roleCond = new RoleCond();
                        roleCond.setRole(value);
                        leaf = SearchCond.getLeafCond(roleCond);
                        break;
                    case PRIVILEGES:
                        PrivilegeCond privilegeCond = new PrivilegeCond();
                        privilegeCond.setPrivilege(value);
                        leaf = SearchCond.getLeafCond(privilegeCond);
                        break;
                    case DYNREALMS:
                        DynRealmCond dynRealmCond = new DynRealmCond();
                        dynRealmCond.setDynRealm(value);
                        leaf = SearchCond.getLeafCond(dynRealmCond);
                        break;
                    case ASSIGNABLE:
                        AssignableCond assignableCond = new AssignableCond();
                        assignableCond.setRealmFullPath(realm);
                        leaf = SearchCond.getLeafCond(assignableCond);
                        break;
                    case MEMBER:
                        MemberCond memberCond = new MemberCond();
                        memberCond.setMember(value);
                        leaf = SearchCond.getLeafCond(memberCond);
                        break;
                    default:
                        throw new IllegalArgumentException(String.format("Special attr name %s is not supported", specialAttrName));
                }
            }
            if (ct == ConditionType.NOT_EQUALS) {
                if (leaf.getAttributeCond() != null && leaf.getAttributeCond().getType() == AttributeCond.Type.ISNULL) {
                    leaf.getAttributeCond().setType(AttributeCond.Type.ISNOTNULL);
                } else if (leaf.getAnyCond() != null && leaf.getAnyCond().getType() == AnyCond.Type.ISNULL) {
                    leaf.getAnyCond().setType(AttributeCond.Type.ISNOTNULL);
                } else {
                    leaf = SearchCond.getNotLeafCond(leaf);
                }
            }
            break;
        case GREATER_OR_EQUALS:
            attributeCond.setType(AttributeCond.Type.GE);
            leaf = SearchCond.getLeafCond(attributeCond);
            break;
        case GREATER_THAN:
            attributeCond.setType(AttributeCond.Type.GT);
            leaf = SearchCond.getLeafCond(attributeCond);
            break;
        case LESS_OR_EQUALS:
            attributeCond.setType(AttributeCond.Type.LE);
            leaf = SearchCond.getLeafCond(attributeCond);
            break;
        case LESS_THAN:
            attributeCond.setType(AttributeCond.Type.LT);
            leaf = SearchCond.getLeafCond(attributeCond);
            break;
        default:
            throw new IllegalArgumentException(String.format("Condition type %s is not supported", ct.name()));
    }
    return leaf;
}
Also used : AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) MemberCond(org.apache.syncope.core.persistence.api.dao.search.MemberCond) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RelationshipCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipCond) ResourceCond(org.apache.syncope.core.persistence.api.dao.search.ResourceCond) SpecialAttr(org.apache.syncope.common.lib.search.SpecialAttr) SyncopeFiqlSearchCondition(org.apache.syncope.common.lib.search.SyncopeFiqlSearchCondition) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) RoleCond(org.apache.syncope.core.persistence.api.dao.search.RoleCond) DynRealmCond(org.apache.syncope.core.persistence.api.dao.search.DynRealmCond) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) ConditionType(org.apache.cxf.jaxrs.ext.search.ConditionType) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) PrivilegeCond(org.apache.syncope.core.persistence.api.dao.search.PrivilegeCond)

Example 5 with AssignableCond

use of org.apache.syncope.core.persistence.api.dao.search.AssignableCond in project syncope by apache.

the class SearchCondConverterTest method assignable.

@Test
public void assignable() {
    String fiql = new GroupFiqlSearchConditionBuilder().isAssignable().query();
    assertEquals(SpecialAttr.ASSIGNABLE + "==" + SpecialAttr.NULL, fiql);
    AssignableCond assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath("/even/two");
    SearchCond simpleCond = SearchCond.getLeafCond(assignableCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql, "/even/two"));
}
Also used : AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) GroupFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.GroupFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Aggregations

AssignableCond (org.apache.syncope.core.persistence.api.dao.search.AssignableCond)5 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)4 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)3 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)2 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)2 AnyObjectDAO (org.apache.syncope.core.persistence.api.dao.AnyObjectDAO)2 AnySearchDAO (org.apache.syncope.core.persistence.api.dao.AnySearchDAO)2 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)2 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)2 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)2 AnyCond (org.apache.syncope.core.persistence.api.dao.search.AnyCond)2 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)2 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)2 Entity (org.apache.syncope.core.persistence.api.entity.Entity)2 Group (org.apache.syncope.core.persistence.api.entity.group.Group)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Transactional (org.springframework.transaction.annotation.Transactional)2