added list all by owner

pull/708/merge
Justin Richer 2015-02-24 17:41:05 -05:00
parent 8d22ad03e2
commit 4878e88d4f
6 changed files with 56 additions and 0 deletions

View File

@ -28,12 +28,19 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table; import javax.persistence.Table;
@Entity @Entity
@Table(name = "resource_set") @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 class ResourceSet {
public static final String QUERY_BY_OWNER = "ResourceSet.queryByOwner";
private Long id; private Long id;
private String name; private String name;
private String uri; private String uri;

View File

@ -16,6 +16,8 @@
*******************************************************************************/ *******************************************************************************/
package org.mitre.openid.connect.service; package org.mitre.openid.connect.service;
import java.util.Collection;
import org.mitre.openid.connect.model.ResourceSet; import org.mitre.openid.connect.model.ResourceSet;
/** /**
@ -35,4 +37,6 @@ public interface ResourceSetService {
public void remove(ResourceSet rs); public void remove(ResourceSet rs);
public Collection<ResourceSet> getAllForOwner(String owner);
} }

View File

@ -17,6 +17,8 @@
package org.mitre.openid.connect.repository; package org.mitre.openid.connect.repository;
import java.util.Collection;
import org.mitre.openid.connect.model.ResourceSet; import org.mitre.openid.connect.model.ResourceSet;
/** /**
@ -31,4 +33,6 @@ public interface ResourceSetRepository {
public void remove(ResourceSet rs); public void remove(ResourceSet rs);
public Collection<ResourceSet> getAllForOwner(String owner);
} }

View File

@ -17,8 +17,11 @@
package org.mitre.openid.connect.repository.impl; package org.mitre.openid.connect.repository.impl;
import java.util.Collection;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.mitre.openid.connect.model.ResourceSet; import org.mitre.openid.connect.model.ResourceSet;
import org.mitre.openid.connect.repository.ResourceSetRepository; 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();
}
} }

View File

@ -17,6 +17,8 @@
package org.mitre.openid.connect.service.impl; package org.mitre.openid.connect.service.impl;
import java.util.Collection;
import org.mitre.openid.connect.model.ResourceSet; import org.mitre.openid.connect.model.ResourceSet;
import org.mitre.openid.connect.repository.ResourceSetRepository; import org.mitre.openid.connect.repository.ResourceSetRepository;
import org.mitre.openid.connect.service.ResourceSetService; import org.mitre.openid.connect.service.ResourceSetService;
@ -78,6 +80,11 @@ public class DefaultResourceSetService implements ResourceSetService {
repository.remove(rs); repository.remove(rs);
} }
@Override
public Collection<ResourceSet> getAllForOwner(String owner) {
return repository.getAllForOwner(owner);
}
} }

View File

@ -20,11 +20,16 @@ import static org.mitre.util.JsonUtils.getAsLong;
import static org.mitre.util.JsonUtils.getAsString; import static org.mitre.util.JsonUtils.getAsString;
import static org.mitre.util.JsonUtils.getAsStringSet; 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.oauth2.service.SystemScopeService;
import org.mitre.openid.connect.config.ConfigurationPropertiesBean; import org.mitre.openid.connect.config.ConfigurationPropertiesBean;
import org.mitre.openid.connect.model.ResourceSet; import org.mitre.openid.connect.model.ResourceSet;
import org.mitre.openid.connect.service.ResourceSetService; import org.mitre.openid.connect.service.ResourceSetService;
import org.mitre.openid.connect.view.HttpCodeView; 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.JsonErrorView;
import org.mitre.openid.connect.view.ResourceSetEntityAbbreviatedView; import org.mitre.openid.connect.view.ResourceSetEntityAbbreviatedView;
import org.mitre.openid.connect.view.ResourceSetEntityView; import org.mitre.openid.connect.view.ResourceSetEntityView;
@ -200,6 +205,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) { private void ensureOAuthScope(Authentication auth) {
// if auth is OAuth, make sure we've got the right scope // if auth is OAuth, make sure we've got the right scope
if (auth instanceof OAuth2Authentication) { if (auth instanceof OAuth2Authentication) {