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.MongoResourceStore.java

License:Open Source License

@Override
public List<Resource> findByScope(String... id) {
    DBObject query = new QueryBuilder().and("scopes").in(id).get();

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

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

License:Open Source License

@Override
public Resource findByName(String name, String resourceServerId) {
    DBObject query = new QueryBuilder().and("name").is(name).and("resourceServerId").is(resourceServerId).get();

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

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

License:Open Source License

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

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

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

License:Open Source License

@Override
public Scope findByName(String name, String resourceServerId) {
    DBObject query = new QueryBuilder().and("resourceServerId").is(resourceServerId).and("name").is(name).get();

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

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

License:Open Source License

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

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

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

License:Open Source License

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

    attributes.forEach((name, value) -> {
        queryBuilder.and(name).regex(Pattern.compile(".*" + value[0] + ".*", Pattern.CASE_INSENSITIVE));
    });/*from   w  w w  .j  av  a2 s. c  o  m*/

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

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

From source file:org.keycloak.models.mongo.keycloak.adapters.GroupAdapter.java

License:Apache License

@Override
public Set<GroupModel> getSubGroups() {
    DBObject query = new QueryBuilder().and("realmId").is(realm.getId()).and("parentId").is(getId()).get();
    List<MongoGroupEntity> groups = getMongoStore().loadEntities(MongoGroupEntity.class, query,
            invocationContext);//from w w  w  .  j a  v  a2 s.  c  o  m

    Set<GroupModel> subGroups = new HashSet<>();

    if (groups == null)
        return subGroups;
    for (MongoGroupEntity group : groups) {
        subGroups.add(realm.getGroupById(group.getId()));
    }

    return subGroups;
}

From source file:org.keycloak.models.mongo.keycloak.adapters.MongoUserSessionPersisterProvider.java

License:Apache License

@Override
public void removeClientSession(String clientSessionId, boolean offline) {
    DBObject query = new QueryBuilder().and("clientSessions.clientSessionId").is(clientSessionId).get();
    Class<? extends MongoUserSessionEntity> clazz = offline ? MongoOfflineUserSessionEntity.class
            : MongoOnlineUserSessionEntity.class;
    MongoUserSessionEntity userSession = getMongoStore().loadSingleEntity(clazz, query, invocationContext);
    if (userSession != null) {

        PersistentClientSessionEntity found = null;
        for (PersistentClientSessionEntity clientSession : userSession.getClientSessions()) {
            if (clientSession.getClientSessionId().equals(clientSessionId)) {
                found = clientSession;//from   w  w w  . jav  a 2 s  .  co  m
                break;
            }
        }

        if (found != null) {
            userSession.getClientSessions().remove(found);

            // Remove userSession if it was last clientSession attached
            if (userSession.getClientSessions().size() == 0) {
                getMongoStore().removeEntity(userSession, invocationContext);
            } else {
                getMongoStore().updateEntity(userSession, invocationContext);
            }
        }
    }
}

From source file:org.keycloak.models.mongo.keycloak.adapters.MongoUserSessionPersisterProvider.java

License:Apache License

@Override
public void onRealmRemoved(RealmModel realm) {
    DBObject query = new QueryBuilder().and("realmId").is(realm.getId()).get();
    getMongoStore().removeEntities(MongoOnlineUserSessionEntity.class, query, false, invocationContext);
    getMongoStore().removeEntities(MongoOfflineUserSessionEntity.class, query, false, invocationContext);
}

From source file:org.keycloak.models.mongo.keycloak.adapters.MongoUserSessionPersisterProvider.java

License:Apache License

@Override
public void onClientRemoved(RealmModel realm, ClientModel client) {
    DBObject query = new QueryBuilder().and("clientSessions.clientId").is(client.getId()).get();

    List<MongoOnlineUserSessionEntity> userSessions = getMongoStore()
            .loadEntities(MongoOnlineUserSessionEntity.class, query, invocationContext);
    for (MongoOnlineUserSessionEntity userSession : userSessions) {
        removeClientSessionOfClient(userSession, client.getId());
    }//from w w  w .  j a va 2s .  c  om

    List<MongoOfflineUserSessionEntity> userSessions2 = getMongoStore()
            .loadEntities(MongoOfflineUserSessionEntity.class, query, invocationContext);
    for (MongoOfflineUserSessionEntity userSession : userSessions2) {
        removeClientSessionOfClient(userSession, client.getId());
    }
}