Search in sources :

Example 16 with AttributeCond

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

the class SearchCondVisitor method addresses.

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;
}
Also used : Arrays(java.util.Arrays) SCIMUserConf(org.apache.syncope.common.lib.scim.SCIMUserConf) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) List(java.util.List) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) Resource(org.apache.syncope.ext.scimv2.api.type.Resource) SCIMComplexConf(org.apache.syncope.common.lib.scim.SCIMComplexConf) SCIMConf(org.apache.syncope.common.lib.scim.SCIMConf) Map(java.util.Map) Optional(java.util.Optional) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with AttributeCond

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

the class CustomJWTSSOProvider method resolve.

@Transactional(readOnly = true)
@Override
public Pair<User, Set<SyncopeGrantedAuthority>> resolve(final JwtClaims jwtClaims) {
    AttributeCond userIdCond = new AttributeCond();
    userIdCond.setSchema("userId");
    userIdCond.setType(AttributeCond.Type.EQ);
    userIdCond.setExpression(jwtClaims.getSubject());
    List<User> matching = searchDAO.search(SearchCond.getLeafCond(userIdCond), AnyTypeKind.USER);
    if (matching.size() == 1) {
        User user = matching.get(0);
        Set<SyncopeGrantedAuthority> authorities = authDataAccessor.getAuthorities(user.getUsername());
        return Pair.of(user, authorities);
    }
    return null;
}
Also used : SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) User(org.apache.syncope.core.persistence.api.entity.user.User) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with AttributeCond

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

the class SearchCondVisitor method createAttributeCond.

public AttributeCond createAttributeCond(final String schema) {
    AttributeCond attributeCond = null;
    if (schemaEquals(Resource.User, "userName", schema)) {
        attributeCond = new AnyCond();
        attributeCond.setSchema("username");
    } else if (resource == Resource.Group && schemaEquals(Resource.Group, "displayName", schema)) {
        attributeCond = new AnyCond();
        attributeCond.setSchema("name");
    } else if (schemaEquals(null, "meta.created", schema)) {
        attributeCond = new AnyCond();
        attributeCond.setSchema("creationDate");
    } else if (schemaEquals(null, "meta.lastModified", schema)) {
        attributeCond = new AnyCond();
        attributeCond.setSchema("lastChangeDate");
    }
    if (resource == Resource.User) {
        if (conf.getUserConf() != null) {
            if (conf.getUserConf().getName() != null) {
                for (Map.Entry<String, String> entry : conf.getUserConf().getName().asMap().entrySet()) {
                    if (schemaEquals(Resource.User, "name." + entry.getKey(), schema)) {
                        attributeCond = new AttributeCond();
                        attributeCond.setSchema(entry.getValue());
                    }
                }
            }
            for (Map.Entry<String, String> entry : conf.getUserConf().asMap().entrySet()) {
                if (schemaEquals(Resource.User, entry.getKey(), schema)) {
                    attributeCond = new AttributeCond();
                    attributeCond.setSchema(entry.getValue());
                }
            }
            for (SCIMUserAddressConf address : conf.getUserConf().getAddresses()) {
                for (Map.Entry<String, String> entry : address.asMap().entrySet()) {
                    if (schemaEquals(Resource.User, "addresses." + entry.getKey(), schema)) {
                        attributeCond = new AttributeCond();
                        attributeCond.setSchema(entry.getValue());
                    }
                }
            }
        }
        if (conf.getEnterpriseUserConf() != null) {
            for (Map.Entry<String, String> entry : conf.getEnterpriseUserConf().asMap().entrySet()) {
                if (schemaEquals(Resource.EnterpriseUser, entry.getKey(), schema)) {
                    attributeCond = new AttributeCond();
                    attributeCond.setSchema(entry.getValue());
                }
            }
            if (conf.getEnterpriseUserConf().getManager() != null && conf.getEnterpriseUserConf().getManager().getKey() != null) {
                attributeCond = new AttributeCond();
                attributeCond.setSchema(conf.getEnterpriseUserConf().getManager().getKey());
            }
        }
    }
    if (attributeCond == null) {
        throw new IllegalArgumentException("Could not match " + schema + " for " + resource);
    }
    return attributeCond;
}
Also used : AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) Map(java.util.Map)

Example 19 with AttributeCond

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

the class SearchCondVisitor method complex.

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;
}
Also used : Arrays(java.util.Arrays) SCIMUserConf(org.apache.syncope.common.lib.scim.SCIMUserConf) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) List(java.util.List) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) Resource(org.apache.syncope.ext.scimv2.api.type.Resource) SCIMComplexConf(org.apache.syncope.common.lib.scim.SCIMComplexConf) SCIMConf(org.apache.syncope.common.lib.scim.SCIMConf) Map(java.util.Map) Optional(java.util.Optional) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SCIMComplexConf(org.apache.syncope.common.lib.scim.SCIMComplexConf) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with AttributeCond

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

the class SearchCondVisitor method visitATTR_PR.

@Override
public SearchCond visitATTR_PR(final SCIMFilterParser.ATTR_PRContext ctx) {
    AttributeCond cond = createAttributeCond(ctx.ATTRNAME().getText());
    cond.setType(AttributeCond.Type.ISNOTNULL);
    return SearchCond.getLeafCond(cond);
}
Also used : AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond)

Aggregations

AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)35 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)25 Test (org.junit.jupiter.api.Test)25 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)16 User (org.apache.syncope.core.persistence.api.entity.user.User)15 AnyCond (org.apache.syncope.core.persistence.api.dao.search.AnyCond)12 UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)8 ArrayList (java.util.ArrayList)4 MembershipCond (org.apache.syncope.core.persistence.api.dao.search.MembershipCond)4 Map (java.util.Map)3 SCIMUserAddressConf (org.apache.syncope.common.lib.scim.SCIMUserAddressConf)3 SCIMUserConf (org.apache.syncope.common.lib.scim.SCIMUserConf)3 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)3 Group (org.apache.syncope.core.persistence.api.entity.group.Group)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 StringUtils (org.apache.commons.lang3.StringUtils)2 SCIMComplexConf (org.apache.syncope.common.lib.scim.SCIMComplexConf)2 SCIMConf (org.apache.syncope.common.lib.scim.SCIMConf)2