Example usage for com.mongodb QueryBuilder QueryBuilder

List of usage examples for com.mongodb QueryBuilder QueryBuilder

Introduction

In this page you can find the example usage for com.mongodb QueryBuilder QueryBuilder.

Prototype

public QueryBuilder() 

Source Link

Document

Creates a builder with an empty query

Usage

From source file:org.keycloak.authorization.mongo.store.MongoPolicyStore.java

License:Open Source License

@Override
public List<Policy> findByResourceServer(Map<String, String[]> attributes, String resourceServerId,
        int firstResult, int maxResult) {
    QueryBuilder queryBuilder = new QueryBuilder().and("resourceServerId").is(resourceServerId);

    attributes.forEach((name, value) -> {
        if ("permission".equals(name)) {
            if (Boolean.valueOf(value[0])) {
                queryBuilder.and("type").in(new String[] { "resource", "scope" });
            } else {
                queryBuilder.and("type").notIn(new String[] { "resource", "scope" });
            }/*w w  w .j  a v  a  2  s.co  m*/
        } else if ("id".equals(name)) {
            queryBuilder.and("_id").in(value);
        } else {
            queryBuilder.and(name).regex(Pattern.compile(".*" + value[0] + ".*", Pattern.CASE_INSENSITIVE));
        }
    });

    DBObject sort = new BasicDBObject("name", 1);

    return getMongoStore().loadEntities(PolicyEntity.class, queryBuilder.get(), sort, firstResult, maxResult,
            invocationContext).stream().map(policy -> findById(policy.getId())).collect(toList());
}

From source file:org.keycloak.authorization.mongo.store.MongoPolicyStore.java

License:Open Source License

@Override
public List<Policy> findByResource(String resourceId) {
    DBObject query = new QueryBuilder().and("resources").is(resourceId).get();

    return getMongoStore().loadEntities(PolicyEntity.class, query, getInvocationContext()).stream()
            .map(policyEntity -> findById(policyEntity.getId())).collect(toList());
}

From source file:org.keycloak.authorization.mongo.store.MongoPolicyStore.java

License:Open Source License

@Override
public List<Policy> findByResourceType(String resourceType, String resourceServerId) {
    DBObject query = new QueryBuilder().and("resourceServerId").is(resourceServerId).get();

    return getMongoStore().loadEntities(PolicyEntity.class, query, getInvocationContext()).stream()
            .filter(policyEntity -> {
                String defaultResourceType = policyEntity.getConfig().get("defaultResourceType");
                return defaultResourceType != null && defaultResourceType.equals(resourceType);
            }).map(policyEntity -> findById(policyEntity.getId())).collect(toList());
}

From source file:org.keycloak.authorization.mongo.store.MongoPolicyStore.java

License:Open Source License

@Override
public List<Policy> findByScopeIds(List<String> scopeIds, String resourceServerId) {
    DBObject query = new QueryBuilder().and("resourceServerId").is(resourceServerId).and("scopes").in(scopeIds)
            .get();/*  ww  w.ja  v a 2s  .  com*/

    return getMongoStore().loadEntities(PolicyEntity.class, query, getInvocationContext()).stream()
            .map(policyEntity -> findById(policyEntity.getId())).collect(toList());
}

From source file:org.keycloak.authorization.mongo.store.MongoPolicyStore.java

License:Open Source License

@Override
public List<Policy> findByType(String type) {
    DBObject query = new QueryBuilder().and("type").is(type).get();

    return getMongoStore().loadEntities(PolicyEntity.class, query, getInvocationContext()).stream()
            .map(policyEntity -> findById(policyEntity.getId())).collect(toList());
}

From source file:org.keycloak.authorization.mongo.store.MongoPolicyStore.java

License:Open Source License

@Override
public List<Policy> findDependentPolicies(String policyId) {
    DBObject query = new QueryBuilder().and("associatedPolicies").is(policyId).get();

    return getMongoStore().loadEntities(PolicyEntity.class, query, getInvocationContext()).stream()
            .map(policyEntity -> findById(policyEntity.getId())).collect(toList());
}

From source file:org.keycloak.authorization.mongo.store.MongoResourceServerStore.java

License:Open Source License

@Override
public ResourceServer findByClient(String clientId) {
    DBObject query = new QueryBuilder().and("clientId").is(clientId).get();

    return getMongoStore().loadEntities(ResourceServerEntity.class, query, getInvocationContext()).stream()
            .map(resourceServer -> findById(resourceServer.getId())).findFirst().orElse(null);
}

From source file:org.keycloak.authorization.mongo.store.MongoResourceStore.java

License:Open Source License

@Override
public List<Resource> findByOwner(String ownerId) {
    DBObject query = new QueryBuilder().and("owner").is(ownerId).get();

    return getMongoStore().loadEntities(ResourceEntity.class, query, getInvocationContext()).stream()
            .map(scope -> findById(scope.getId())).collect(toList());
}

From source file:org.keycloak.authorization.mongo.store.MongoResourceStore.java

License:Open Source License

@Override
public List findByResourceServer(String resourceServerId) {
    DBObject query = new QueryBuilder().and("resourceServerId").is(resourceServerId).get();

    return getMongoStore().loadEntities(ResourceEntity.class, query, getInvocationContext()).stream()
            .map(scope -> findById(scope.getId())).collect(toList());
}

From source file:org.keycloak.authorization.mongo.store.MongoResourceStore.java

License:Open Source License

@Override
public List<Resource> findByResourceServer(Map<String, String[]> attributes, String resourceServerId,
        int firstResult, int maxResult) {
    QueryBuilder queryBuilder = new QueryBuilder().and("resourceServerId").is(resourceServerId);

    attributes.forEach((name, value) -> {
        if ("scope".equals(name)) {
            queryBuilder.and("scopes").in(value);
        } else {// w  w w  .ja va  2  s . co m
            queryBuilder.and(name).regex(Pattern.compile(".*" + value[0] + ".*", Pattern.CASE_INSENSITIVE));
        }
    });

    DBObject sort = new BasicDBObject("name", 1);

    return getMongoStore().loadEntities(ResourceEntity.class, queryBuilder.get(), sort, firstResult, maxResult,
            invocationContext).stream().map(scope -> findById(scope.getId())).collect(toList());
}