parent
4bdf2fe21d
commit
434cc7c711
4 changed files with 15 additions and 15 deletions
|
@ -65,7 +65,7 @@ import org.hibernate.annotations.FetchMode;
|
||||||
@NamedQuery(name="findResourceIdByTypeNoOwner", query="select r from ResourceEntity r left join fetch r.scopes s where r.resourceServer = :serverId and r.type = :type"),
|
@NamedQuery(name="findResourceIdByTypeNoOwner", query="select r from ResourceEntity r left join fetch r.scopes s where r.resourceServer = :serverId and r.type = :type"),
|
||||||
@NamedQuery(name="findResourceIdByTypeInstance", query="select r from ResourceEntity r left join fetch r.scopes s where r.resourceServer = :serverId and r.type = :type and r.owner <> :serverId"),
|
@NamedQuery(name="findResourceIdByTypeInstance", query="select r from ResourceEntity r left join fetch r.scopes s where r.resourceServer = :serverId and r.type = :type and r.owner <> :serverId"),
|
||||||
@NamedQuery(name="findResourceIdByServerId", query="select r.id from ResourceEntity r where r.resourceServer = :serverId "),
|
@NamedQuery(name="findResourceIdByServerId", query="select r.id from ResourceEntity r where r.resourceServer = :serverId "),
|
||||||
@NamedQuery(name="findResourceIdByScope", query="select r from ResourceEntity r inner join r.scopes s where r.resourceServer = :serverId and (s.resourceServer = :serverId and s.id in (:scopeIds))"),
|
@NamedQuery(name="findResourceIdByScope", query="select r from ResourceEntity r inner join r.scopes s where r.resourceServer = :serverId and (s.resourceServer.id = :serverId and s.id in (:scopeIds))"),
|
||||||
@NamedQuery(name="deleteResourceByResourceServer", query="delete from ResourceEntity r where r.resourceServer = :serverId")
|
@NamedQuery(name="deleteResourceByResourceServer", query="delete from ResourceEntity r where r.resourceServer = :serverId")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -64,16 +64,16 @@ public class JPAPermissionTicketStore implements PermissionTicketStore {
|
||||||
@Override
|
@Override
|
||||||
public long count(ResourceServer resourceServer, Map<PermissionTicket.FilterOption, String> attributes) {
|
public long count(ResourceServer resourceServer, Map<PermissionTicket.FilterOption, String> attributes) {
|
||||||
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
CriteriaQuery<Long> querybuilder = builder.createQuery(Long.class);
|
CriteriaQuery<String> querybuilder = builder.createQuery(String.class);
|
||||||
Root<PermissionTicketEntity> root = querybuilder.from(PermissionTicketEntity.class);
|
Root<PermissionTicketEntity> root = querybuilder.from(PermissionTicketEntity.class);
|
||||||
|
|
||||||
querybuilder.select(root.get("id"));
|
querybuilder.select(root.get("id"));
|
||||||
|
|
||||||
List<Predicate> predicates = getPredicates(builder, root, resourceServer, attributes);
|
List<Predicate> predicates = getPredicates(builder, root, resourceServer, attributes);
|
||||||
|
|
||||||
querybuilder.where(predicates.toArray(new Predicate[predicates.size()])).orderBy(builder.asc(root.get("id")));
|
querybuilder.where(predicates.toArray(new Predicate[0])).orderBy(builder.asc(root.get("id")));
|
||||||
|
|
||||||
TypedQuery query = entityManager.createQuery(querybuilder);
|
TypedQuery<String> query = entityManager.createQuery(querybuilder);
|
||||||
|
|
||||||
return closing(query.getResultStream()).count();
|
return closing(query.getResultStream()).count();
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,10 +154,10 @@ public class JPAResourceStore implements ResourceStore {
|
||||||
@Override
|
@Override
|
||||||
public List<Resource> find(RealmModel realm, ResourceServer resourceServer, Map<Resource.FilterOption, String[]> attributes, Integer firstResult, Integer maxResults) {
|
public List<Resource> find(RealmModel realm, ResourceServer resourceServer, Map<Resource.FilterOption, String[]> attributes, Integer firstResult, Integer maxResults) {
|
||||||
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
CriteriaQuery<ResourceEntity> querybuilder = builder.createQuery(ResourceEntity.class);
|
CriteriaQuery<String> querybuilder = builder.createQuery(String.class);
|
||||||
Root<ResourceEntity> root = querybuilder.from(ResourceEntity.class);
|
Root<ResourceEntity> root = querybuilder.from(ResourceEntity.class);
|
||||||
querybuilder.select(root.get("id"));
|
querybuilder.select(root.get("id"));
|
||||||
List<Predicate> predicates = new ArrayList();
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
|
||||||
if (resourceServer != null) {
|
if (resourceServer != null) {
|
||||||
predicates.add(builder.equal(root.get("resourceServer"), resourceServer.getId()));
|
predicates.add(builder.equal(root.get("resourceServer"), resourceServer.getId()));
|
||||||
|
@ -196,9 +196,9 @@ public class JPAResourceStore implements ResourceStore {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
querybuilder.where(predicates.toArray(new Predicate[predicates.size()])).orderBy(builder.asc(root.get("name")));
|
querybuilder.where(predicates.toArray(new Predicate[0])).orderBy(builder.asc(root.get("name")));
|
||||||
|
|
||||||
TypedQuery query = entityManager.createQuery(querybuilder);
|
TypedQuery<String> query = entityManager.createQuery(querybuilder);
|
||||||
|
|
||||||
List<String> result = paginateQuery(query, firstResult, maxResults).getResultList();
|
List<String> result = paginateQuery(query, firstResult, maxResults).getResultList();
|
||||||
List<Resource> list = new LinkedList<>();
|
List<Resource> list = new LinkedList<>();
|
||||||
|
|
|
@ -133,10 +133,10 @@ public class JPAScopeStore implements ScopeStore {
|
||||||
@Override
|
@Override
|
||||||
public List<Scope> findByResourceServer(ResourceServer resourceServer, Map<Scope.FilterOption, String[]> attributes, Integer firstResult, Integer maxResults) {
|
public List<Scope> findByResourceServer(ResourceServer resourceServer, Map<Scope.FilterOption, String[]> attributes, Integer firstResult, Integer maxResults) {
|
||||||
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
CriteriaQuery<ScopeEntity> querybuilder = builder.createQuery(ScopeEntity.class);
|
CriteriaQuery<String> querybuilder = builder.createQuery(String.class);
|
||||||
Root<ScopeEntity> root = querybuilder.from(ScopeEntity.class);
|
Root<ScopeEntity> root = querybuilder.from(ScopeEntity.class);
|
||||||
querybuilder.select(root.get("id"));
|
querybuilder.select(root.get("id"));
|
||||||
List<Predicate> predicates = new ArrayList();
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
|
||||||
predicates.add(builder.equal(root.get("resourceServer").get("id"), resourceServer.getId()));
|
predicates.add(builder.equal(root.get("resourceServer").get("id"), resourceServer.getId()));
|
||||||
|
|
||||||
|
@ -153,14 +153,14 @@ public class JPAScopeStore implements ScopeStore {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
querybuilder.where(predicates.toArray(new Predicate[predicates.size()])).orderBy(builder.asc(root.get("name")));
|
querybuilder.where(predicates.toArray(new Predicate[0])).orderBy(builder.asc(root.get("name")));
|
||||||
|
|
||||||
TypedQuery query = entityManager.createQuery(querybuilder);
|
TypedQuery<String> query = entityManager.createQuery(querybuilder);
|
||||||
|
|
||||||
List result = paginateQuery(query, firstResult, maxResults).getResultList();
|
List<String> result = paginateQuery(query, firstResult, maxResults).getResultList();
|
||||||
List<Scope> list = new LinkedList<>();
|
List<Scope> list = new LinkedList<>();
|
||||||
for (Object id : result) {
|
for (String id : result) {
|
||||||
list.add(provider.getStoreFactory().getScopeStore().findById(JPAAuthorizationStoreFactory.NULL_REALM, resourceServer, (String)id));
|
list.add(provider.getStoreFactory().getScopeStore().findById(JPAAuthorizationStoreFactory.NULL_REALM, resourceServer, id));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue