added list all by owner
parent
8d22ad03e2
commit
4878e88d4f
|
@ -28,12 +28,19 @@ import javax.persistence.GeneratedValue;
|
|||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "resource_set")
|
||||
@NamedQueries (
|
||||
@NamedQuery(name = ResourceSet.QUERY_BY_OWNER, query = "select r from ResourceSet r where r.owner = :owner")
|
||||
)
|
||||
public class ResourceSet {
|
||||
|
||||
public static final String QUERY_BY_OWNER = "ResourceSet.queryByOwner";
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String uri;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*******************************************************************************/
|
||||
package org.mitre.openid.connect.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
|
||||
/**
|
||||
|
@ -35,4 +37,6 @@ public interface ResourceSetService {
|
|||
|
||||
public void remove(ResourceSet rs);
|
||||
|
||||
public Collection<ResourceSet> getAllForOwner(String owner);
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
|
||||
/**
|
||||
|
@ -31,4 +33,6 @@ public interface ResourceSetRepository {
|
|||
|
||||
public void remove(ResourceSet rs);
|
||||
|
||||
public Collection<ResourceSet> getAllForOwner(String owner);
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,11 @@
|
|||
|
||||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
import org.mitre.openid.connect.repository.ResourceSetRepository;
|
||||
|
@ -61,4 +64,11 @@ public class JpaResourceSetRepository implements ResourceSetRepository {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceSet> getAllForOwner(String owner) {
|
||||
TypedQuery<ResourceSet> query = em.createNamedQuery(ResourceSet.QUERY_BY_OWNER, ResourceSet.class);
|
||||
query.setParameter("owner", owner);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.mitre.openid.connect.service.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
import org.mitre.openid.connect.repository.ResourceSetRepository;
|
||||
import org.mitre.openid.connect.service.ResourceSetService;
|
||||
|
@ -77,6 +79,11 @@ public class DefaultResourceSetService implements ResourceSetService {
|
|||
public void remove(ResourceSet rs) {
|
||||
repository.remove(rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceSet> getAllForOwner(String owner) {
|
||||
return repository.getAllForOwner(owner);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,11 +20,16 @@ import static org.mitre.util.JsonUtils.getAsLong;
|
|||
import static org.mitre.util.JsonUtils.getAsString;
|
||||
import static org.mitre.util.JsonUtils.getAsStringSet;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mitre.oauth2.service.SystemScopeService;
|
||||
import org.mitre.openid.connect.config.ConfigurationPropertiesBean;
|
||||
import org.mitre.openid.connect.model.ResourceSet;
|
||||
import org.mitre.openid.connect.service.ResourceSetService;
|
||||
import org.mitre.openid.connect.view.HttpCodeView;
|
||||
import org.mitre.openid.connect.view.JsonEntityView;
|
||||
import org.mitre.openid.connect.view.JsonErrorView;
|
||||
import org.mitre.openid.connect.view.ResourceSetEntityAbbreviatedView;
|
||||
import org.mitre.openid.connect.view.ResourceSetEntityView;
|
||||
|
@ -199,6 +204,25 @@ public class ResourceSetRegistrationEndpoint {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
|
||||
public String listResourceSets(Model m, Authentication auth) {
|
||||
ensureOAuthScope(auth);
|
||||
|
||||
String owner = auth.getName();
|
||||
|
||||
Collection<ResourceSet> resourceSets = resourceSetService.getAllForOwner(owner);
|
||||
|
||||
// build the entity here and send to the display
|
||||
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (ResourceSet resourceSet : resourceSets) {
|
||||
ids.add(resourceSet.getId().toString()); // add them all as strings so that gson renders them properly
|
||||
}
|
||||
|
||||
m.addAttribute("entity", ids);
|
||||
return JsonEntityView.VIEWNAME;
|
||||
}
|
||||
|
||||
private void ensureOAuthScope(Authentication auth) {
|
||||
// if auth is OAuth, make sure we've got the right scope
|
||||
|
|
Loading…
Reference in New Issue