Search in sources :

Example 1 with ResourceSetStore

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);
}
Also used : ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.restlet.resource.ResourceException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Put(org.restlet.resource.Put)

Example 2 with ResourceSetStore

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);
}
Also used : ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) HashSet(java.util.HashSet)

Example 3 with ResourceSetStore

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);
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) HashSet(java.util.HashSet) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)

Example 4 with ResourceSetStore

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());
    }
}
Also used : ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription)

Example 5 with ResourceSetStore

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;
    }
}
Also used : ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings)

Aggregations

ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)14 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)11 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 HashSet (java.util.HashSet)3 Subject (javax.security.auth.Subject)3 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)3 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)3 ExtensionFilterManager (org.forgerock.openam.oauth2.extensions.ExtensionFilterManager)3 Evaluator (com.sun.identity.entitlement.Evaluator)2 HashMap (java.util.HashMap)2 JsonValue (org.forgerock.json.JsonValue)2 AccessToken (org.forgerock.oauth2.core.AccessToken)2 OAuth2ProviderSettingsFactory (org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory)2 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)2 ResourceSetRegistrationHook (org.forgerock.oauth2.restlet.resources.ResourceSetRegistrationHook)2 ResourceSetStoreFactory (org.forgerock.openam.oauth2.resources.ResourceSetStoreFactory)2 UmaAuditLogger (org.forgerock.openam.uma.audit.UmaAuditLogger)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Request (org.restlet.Request)2