use of org.forgerock.oauth2.resources.ResourceSetStore in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpoint method updateResourceSet.
@Put
public Representation updateResourceSet(JsonRepresentation entity) throws NotFoundException, ServerException, BadRequestException {
if (!isConditionalRequest()) {
throw new ResourceException(512, "precondition_failed", "Require If-Match header to update Resource Set", null);
}
final Map<String, Object> resourceSetDescriptionAttributes = validator.validate(toMap(entity));
final String resourceSetId = getResourceSetId();
ResourceSetStore store = providerSettingsFactory.get(requestFactory.create(getRequest())).getResourceSetStore();
ResourceSetDescription resourceSetDescription = store.read(resourceSetId, getResourceOwnerId()).update(resourceSetDescriptionAttributes);
JsonValue labels = resourceSetDescription.getDescription().get(OAuth2Constants.ResourceSets.LABELS);
resourceSetDescription.getDescription().remove(OAuth2Constants.ResourceSets.LABELS);
store.update(resourceSetDescription);
if (labels.isNotNull()) {
resourceSetDescription.getDescription().add(OAuth2Constants.ResourceSets.LABELS, labels.asSet());
} else {
resourceSetDescription.getDescription().add(OAuth2Constants.ResourceSets.LABELS, new HashSet<String>());
}
labelRegistration.updateLabelsForExistingResourceSet(resourceSetDescription);
return createJsonResponse(resourceSetDescription, false, true);
}
use of org.forgerock.oauth2.resources.ResourceSetStore in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpoint method listResourceSets.
private Representation listResourceSets() throws ServerException, NotFoundException {
ResourceSetStore store = providerSettingsFactory.get(requestFactory.create(getRequest())).getResourceSetStore();
QueryFilter<String> query = QueryFilter.and(QueryFilter.equalTo(ResourceSetTokenField.CLIENT_ID, getClientId()), QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_OWNER_ID, getResourceOwnerId()));
Set<ResourceSetDescription> resourceSetDescriptions = store.query(query);
Set<String> resourceSetIds = new HashSet<String>();
for (ResourceSetDescription resourceSetDescription : resourceSetDescriptions) {
resourceSetIds.add(resourceSetDescription.getId());
}
return jacksonRepresentationFactory.create(resourceSetIds);
}
use of org.forgerock.oauth2.resources.ResourceSetStore in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpoint method readResourceSet.
private Representation readResourceSet(String resourceSetId) throws NotFoundException, ServerException {
ResourceSetStore store = providerSettingsFactory.get(requestFactory.create(getRequest())).getResourceSetStore();
ResourceSetDescription resourceSetDescription = store.read(resourceSetId, getResourceOwnerId());
Set<String> labels = new HashSet<String>();
try {
Set<ResourceSetLabel> labelSet = umaLabelsStore.forResourceSet(resourceSetDescription.getRealm(), resourceSetDescription.getResourceOwnerId(), resourceSetDescription.getId(), false);
for (ResourceSetLabel label : labelSet) {
labels.add(label.getName());
}
} catch (org.forgerock.json.resource.ResourceException e) {
throw new ServerException(e);
}
resourceSetDescription.getDescription().put("labels", labels);
return createJsonResponse(resourceSetDescription, true, true);
}
use of org.forgerock.oauth2.resources.ResourceSetStore in project OpenAM by OpenRock.
the class UmaPolicyApplicationListener method deleteResourceSets.
private void deleteResourceSets(String realm, String resourceServerId) throws NotFoundException, ServerException {
ResourceSetStore resourceSetStore = resourceSetStoreFactory.create(DNMapper.orgNameToRealmName(realm));
QueryFilter<String> queryFilter = QueryFilter.equalTo(ResourceSetTokenField.CLIENT_ID, resourceServerId);
Set<ResourceSetDescription> results = resourceSetStore.query(queryFilter);
for (ResourceSetDescription resourceSet : results) {
resourceSetStore.delete(resourceSet.getId(), resourceSet.getResourceOwnerId());
}
}
use of org.forgerock.oauth2.resources.ResourceSetStore in project OpenAM by OpenRock.
the class OpenAMOAuth2ProviderSettingsFactory method getProviderSettings.
private OAuth2ProviderSettings getProviderSettings(String realm) throws NotFoundException {
synchronized (providerSettingsMap) {
OAuth2ProviderSettings providerSettings = providerSettingsMap.get(realm);
if (providerSettings == null) {
ResourceSetStore resourceSetStore = resourceSetStoreFactory.create(realm);
providerSettings = new OpenAMOAuth2ProviderSettings(realm, resourceSetStore, cookieExtractor);
if (providerSettings.exists()) {
providerSettingsMap.put(realm, providerSettings);
} else {
throw new NotFoundException("No OpenID Connect provider for realm " + realm);
}
}
return providerSettings;
}
}
Aggregations