protected SearchCond buildEffectiveCond(final SearchCond cond, final Set<String> dynRealmKeys) { List<SearchCond> effectiveConds = dynRealmKeys.stream().map(dynRealmKey -> { DynRealmCond dynRealmCond = new DynRealmCond(); dynRealmCond.setDynRealm(dynRealmKey); return SearchCond.getLeafCond(dynRealmCond); }).collect(Collectors.toList()); effectiveConds.add(cond); return SearchCond.getAndCond(effectiveConds); }
@Override public SearchCond visitNOT_EXPR(final SCIMFilterParser.NOT_EXPRContext ctx) { SearchCond cond = visit(ctx.expression()); if (cond.getAttributeCond() != null) { if (cond.getAttributeCond().getType() == AttributeCond.Type.ISNULL) { cond.getAttributeCond().setType(AttributeCond.Type.ISNOTNULL); } else if (cond.getAttributeCond().getType() == AttributeCond.Type.ISNOTNULL) { cond.getAttributeCond().setType(AttributeCond.Type.ISNULL); } } else if (cond.getAnyCond() != null) { if (cond.getAnyCond().getType() == AnyCond.Type.ISNULL) { cond.getAnyCond().setType(AnyCond.Type.ISNOTNULL); } else if (cond.getAnyCond().getType() == AnyCond.Type.ISNOTNULL) { cond.getAnyCond().setType(AnyCond.Type.ISNULL); } } else { cond = SearchCond.getNotLeafCond(cond); } return cond; }
public static SearchCond getOrCond(final List<SearchCond> conditions) { if (conditions.size() == 1) { return conditions.get(0); } else if (conditions.size() > 2) { SearchCond removed = conditions.remove(0); return getOrCond(removed, getOrCond(conditions)); } else { return getOrCond(conditions.get(0), conditions.get(1)); } }
switch (cond.getType()) { case LEAF: case NOT_LEAF: if (cond.getAnyTypeCond() != null && AnyTypeKind.ANY_OBJECT == svs.anyTypeKind) { query.append(getQuery(cond.getAnyTypeCond(), cond.getType() == SearchCond.Type.NOT_LEAF, parameters, svs)); } else if (cond.getRelationshipTypeCond() != null && (AnyTypeKind.USER == svs.anyTypeKind || AnyTypeKind.ANY_OBJECT == svs.anyTypeKind)) { query.append(getQuery(cond.getRelationshipTypeCond(), cond.getType() == SearchCond.Type.NOT_LEAF, parameters, svs)); } else if (cond.getRelationshipCond() != null && (AnyTypeKind.USER == svs.anyTypeKind || AnyTypeKind.ANY_OBJECT == svs.anyTypeKind)) { query.append(getQuery(cond.getRelationshipCond(), cond.getType() == SearchCond.Type.NOT_LEAF, parameters, svs)); } else if (cond.getMembershipCond() != null && (AnyTypeKind.USER == svs.anyTypeKind || AnyTypeKind.ANY_OBJECT == svs.anyTypeKind)) { query.append(getQuery(cond.getMembershipCond(), cond.getType() == SearchCond.Type.NOT_LEAF, parameters, svs)); } else if (cond.getAssignableCond() != null) { query.append(getQuery(cond.getAssignableCond(), parameters, svs)); } else if (cond.getRoleCond() != null && AnyTypeKind.USER == svs.anyTypeKind) { query.append(getQuery(cond.getRoleCond(), cond.getType() == SearchCond.Type.NOT_LEAF, parameters, svs)); } else if (cond.getPrivilegeCond() != null && AnyTypeKind.USER == svs.anyTypeKind) { query.append(getQuery(cond.getPrivilegeCond(), cond.getType() == SearchCond.Type.NOT_LEAF, parameters, svs));
public static SearchCond getNotLeafCond(final AttributeCond attributeCond) { SearchCond nodeCond = getLeafCond(attributeCond); nodeCond.type = Type.NOT_LEAF; return nodeCond; }
cond.setExpression(expression); searchConds.add(SearchCond.getLeafCond(cond)); }); ? SearchCond.getOrCond(searchConds) : SearchCond.getAndCond(searchConds);
leaf = SearchCond.getLeafCond(attributeCond); } else { switch (specialAttrName.get()) { AnyTypeCond typeCond = new AnyTypeCond(); typeCond.setAnyTypeKey(value); leaf = SearchCond.getLeafCond(typeCond); break; ResourceCond resourceCond = new ResourceCond(); resourceCond.setResourceKey(value); leaf = SearchCond.getLeafCond(resourceCond); break; MembershipCond groupCond = new MembershipCond(); groupCond.setGroup(value); leaf = SearchCond.getLeafCond(groupCond); break; RelationshipCond relationshipCond = new RelationshipCond(); relationshipCond.setAnyObject(value); leaf = SearchCond.getLeafCond(relationshipCond); break; RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond(); relationshipTypeCond.setRelationshipTypeKey(value); leaf = SearchCond.getLeafCond(relationshipTypeCond); break;
private <E extends Enum<?>> SearchCond complex( final String operator, final String left, final String right, final List<SCIMComplexConf<E>> items) { if (left.endsWith(".type")) { Optional<SCIMComplexConf<E>> item = items.stream(). filter(object -> object.getType().name().equals(StringUtils.strip(right, "\""))).findFirst(); if (item.isPresent()) { AttributeCond attributeCond = new AttributeCond(); attributeCond.setSchema(item.get().getValue()); attributeCond.setType(AttributeCond.Type.ISNOTNULL); return SearchCond.getLeafCond(attributeCond); } } else if (!conf.getUserConf().getEmails().isEmpty() && (MULTIVALUE.contains(left) || left.endsWith(".value"))) { List<SearchCond> orConds = new ArrayList<>(); items.forEach(item -> { AttributeCond cond = new AttributeCond(); cond.setSchema(item.getValue()); cond.setExpression(StringUtils.strip(right, "\"")); orConds.add(setOperator(cond, operator)); }); if (!orConds.isEmpty()) { return SearchCond.getOrCond(orConds); } } return null; }
private SearchCond visitCompount(final SearchCondition<SearchBean> sc) { List<SearchCond> searchConds = new ArrayList<>(); sc.getSearchConditions().forEach(searchCondition -> { searchConds.add(searchCondition.getStatement() == null ? visitCompount(searchCondition) : visitPrimitive(searchCondition)); }); SearchCond compound; switch (sc.getConditionType()) { case AND: compound = SearchCond.getAndCond(searchConds); break; case OR: compound = SearchCond.getOrCond(searchConds); break; default: throw new IllegalArgumentException( String.format("Condition type %s is not supported", sc.getConditionType().name())); } return compound; }
? SearchCond.getNotLeafCond(attributeCond) : SearchCond.getLeafCond(attributeCond);
@Override public int count(final Set<String> adminRealms, final SearchCond cond, final AnyTypeKind kind) { if (adminRealms == null || adminRealms.isEmpty()) { LOG.error("No realms provided"); return 0; } LOG.debug("Search condition:\n{}", cond); if (cond == null || !cond.isValid()) { LOG.error("Invalid search condition:\n{}", cond); return 0; } return doCount(adminRealms, cond, kind); }
public static SearchCond getAndCond(final List<SearchCond> conditions) { if (conditions.size() == 1) { return conditions.get(0); } else if (conditions.size() > 2) { SearchCond removed = conditions.remove(0); return getAndCond(removed, getAndCond(conditions)); } else { return getAndCond(conditions.get(0), conditions.get(1)); } }
/** * Not a simple getter: recursively scans the search condition tree. * * @return the AnyType key or {@code NULL} if no type condition was found */ public String hasAnyTypeCond() { String anyTypeName = null; if (type == null) { return anyTypeName; } switch (type) { case LEAF: case NOT_LEAF: if (anyTypeCond != null) { anyTypeName = anyTypeCond.getAnyTypeKey(); } break; case AND: case OR: if (leftSearchCond != null) { anyTypeName = leftSearchCond.hasAnyTypeCond(); } if (anyTypeName == null && rightSearchCond != null) { anyTypeName = rightSearchCond.hasAnyTypeCond(); } break; default: } return anyTypeName; }
public static SearchCond getNotLeafCond(final MemberCond memberCond) { SearchCond nodeCond = getLeafCond(memberCond); nodeCond.type = Type.NOT_LEAF; return nodeCond; }
private SearchCond addresses( final String operator, final String left, final String right, final List<SCIMUserAddressConf> items) { if (left.endsWith(".type") && "eq".equals(operator)) { Optional<SCIMUserAddressConf> item = items.stream(). filter(object -> object.getType().name().equals(StringUtils.strip(right, "\""))).findFirst(); if (item.isPresent()) { AttributeCond attributeCond = new AttributeCond(); attributeCond.setSchema(item.get().getFormatted()); attributeCond.setType(AttributeCond.Type.ISNOTNULL); return SearchCond.getLeafCond(attributeCond); } } else if (!conf.getUserConf().getEmails().isEmpty() && (MULTIVALUE.contains(left) || left.endsWith(".value"))) { List<SearchCond> orConds = new ArrayList<>(); items.forEach(item -> { AttributeCond cond = new AttributeCond(); cond.setSchema(item.getFormatted()); cond.setExpression(StringUtils.strip(right, "\"")); orConds.add(setOperator(cond, operator)); }); if (!orConds.isEmpty()) { return SearchCond.getOrCond(orConds); } } return null; }
@Override public <T extends Any<?>> List<T> search( final Set<String> adminRealms, final SearchCond cond, final int page, final int itemsPerPage, final List<OrderByClause> orderBy, final AnyTypeKind kind) { if (adminRealms == null || adminRealms.isEmpty()) { LOG.error("No realms provided"); return Collections.<T>emptyList(); } LOG.debug("Search condition:\n{}", cond); if (cond == null || !cond.isValid()) { LOG.error("Invalid search condition:\n{}", cond); return Collections.<T>emptyList(); } List<OrderByClause> effectiveOrderBy; if (orderBy.isEmpty()) { OrderByClause keyClause = new OrderByClause(); keyClause.setField(kind == AnyTypeKind.USER ? "username" : "name"); keyClause.setDirection(OrderByClause.Direction.ASC); effectiveOrderBy = Collections.singletonList(keyClause); } else { effectiveOrderBy = orderBy.stream(). filter(clause -> !ArrayUtils.contains(ORDER_BY_NOT_ALLOWED, clause.getField())). collect(Collectors.toList()); } return doSearch(adminRealms, cond, page, itemsPerPage, effectiveOrderBy, kind); }
@Override public SearchCond visitEXPR_AND_EXPR(final SCIMFilterParser.EXPR_AND_EXPRContext ctx) { return SearchCond.getAndCond(visit(ctx.expression(0)), visit(ctx.expression(1))); }
@Transactional(readOnly = true) @Override public Pair<Integer, List<AnyObjectTO>> search( final SearchCond searchCond, final int page, final int size, final List<OrderByClause> orderBy, final String realm, final boolean details) { if (searchCond.hasAnyTypeCond() == null) { throw new UnsupportedOperationException("Need to specify " + AnyType.class.getSimpleName()); } Set<String> effectiveRealms = RealmUtils.getEffective( AuthContextUtils.getAuthorizations().get(AnyEntitlement.SEARCH.getFor(searchCond.hasAnyTypeCond())), realm); int count = searchDAO.count(effectiveRealms, searchCond, AnyTypeKind.ANY_OBJECT); List<AnyObject> matching = searchDAO.search( effectiveRealms, searchCond, page, size, orderBy, AnyTypeKind.ANY_OBJECT); List<AnyObjectTO> result = matching.stream(). map(anyObject -> binder.getAnyObjectTO(anyObject, details)).collect(Collectors.toList()); return Pair.of(count, result); }
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)); }
public static SearchCond getNotLeafCond(final RelationshipCond relationshipCond) { SearchCond nodeCond = getLeafCond(relationshipCond); nodeCond.type = Type.NOT_LEAF; return nodeCond; }