use of org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel in project OpenAM by OpenRock.
the class ResourceSetLabelRegistrationTest method shouldUpdateLabelsForExistingResourceSetWithAllLabelsRemoved.
@Test
public void shouldUpdateLabelsForExistingResourceSetWithAllLabelsRemoved() throws Exception {
//Given
givenLabelsForResourceSet("LABEL_ONE", "LABEL_TWO");
ResourceSetDescription resourceSet = newResourceSet();
givenLabelsExist("LABEL_ONE", "LABEL_TWO");
//When
labelRegistration.updateLabelsForExistingResourceSet(resourceSet);
//Then
ArgumentCaptor<ResourceSetLabel> labelCaptor = ArgumentCaptor.forClass(ResourceSetLabel.class);
verify(labelsStore, times(2)).update(eq("REALM"), eq("RESOURCE_OWNER_ID"), labelCaptor.capture());
List<ResourceSetLabel> labels = labelCaptor.getAllValues();
for (ResourceSetLabel label : labels) {
assertThat(label.getResourceSetIds()).isEmpty();
}
}
use of org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel in project OpenAM by OpenRock.
the class ResourceSetResource method getResourceSetJson.
private JsonValue getResourceSetJson(ResourceSetDescription resourceSet, String userId) throws ResourceException {
HashMap<String, Object> content = new HashMap<String, Object>(resourceSet.asMap());
content.put(ID, resourceSet.getId());
content.put("resourceServer", resourceSet.getClientId());
content.put("resourceOwnerId", resourceSet.getResourceOwnerId());
Set<ResourceSetLabel> labels = umaLabelsStore.forResourceSet(resourceSet.getRealm(), resourceSet.getResourceOwnerId(), resourceSet.getId(), false);
Set<String> labelIds = new HashSet<>();
boolean filterOutSystemLabels = userId.equals(resourceSet.getResourceOwnerId());
for (ResourceSetLabel label : labels) {
if (filterOutSystemLabels && label.getType().equals(LabelType.SYSTEM)) {
continue;
} else {
labelIds.add(label.getId());
}
}
content.put("labels", labelIds);
if (resourceSet.getPolicy() != null) {
JsonValue policy = new JsonValue(new HashMap<String, Object>(resourceSet.getPolicy().asMap()));
policy.remove("policyId");
policy.remove("name");
content.put("policy", policy.getObject());
}
return new JsonValue(content);
}
use of org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel in project OpenAM by OpenRock.
the class UmaLabelResource method createInstance.
@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context serverContext, CreateRequest createRequest) {
final JsonValue umaLabel = createRequest.getContent();
try {
validate(umaLabel);
} catch (BadRequestException e) {
return e.asPromise();
}
final String realm = getRealm(serverContext);
final String userName = getUserName(serverContext);
final String labelName = umaLabel.get(NAME_LABEL).asString();
final String labelType = umaLabel.get(TYPE_LABEL).asString();
final ResourceSetLabel label;
try {
label = labelStore.create(realm, userName, new ResourceSetLabel(null, labelName, LabelType.valueOf(labelType), Collections.EMPTY_SET));
return newResultPromise(newResourceResponse(label.getId(), String.valueOf(label.hashCode()), label.asJson()));
} catch (ResourceException e) {
return e.asPromise();
}
}
use of org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel in project OpenAM by OpenRock.
the class UmaLabelResource method deleteInstance.
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context serverContext, String labelId, DeleteRequest deleteRequest) {
try {
ResourceSetLabel resourceSetLabel = labelStore.read(getRealm(serverContext), getUserName(serverContext), labelId);
if (!isSameRevision(deleteRequest, resourceSetLabel)) {
throw new BadRequestException("Revision number doesn't match latest revision.");
}
labelStore.delete(getRealm(serverContext), getUserName(serverContext), labelId);
return newResultPromise(newResourceResponse(labelId, null, resourceSetLabel.asJson()));
} catch (ResourceException e) {
return new BadRequestException("Error deleting label.").asPromise();
}
}
use of org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel in project OpenAM by OpenRock.
the class UmaLabelResourceTest method deleteLabel.
/**
* Should successfully delete a label.
*/
@Test
public void deleteLabel() throws ResourceException {
//Given
final ResourceSetLabel resourceSetLabel = new ResourceSetLabel(LABEL_ID, LABEL_NAME, LabelType.valueOf(LABEL_TYPE), Collections.EMPTY_SET);
given(contextHelper.getRealm(serverContext)).willReturn(REALM_NAME);
given(contextHelper.getUserId(serverContext)).willReturn(RESOURCE_OWNER_ID);
given(umaLabelsStore.read(REALM_NAME, RESOURCE_OWNER_ID, LABEL_ID)).willReturn(resourceSetLabel);
given(deleteRequest.getRevision()).willReturn(String.valueOf(resourceSetLabel.hashCode()));
//When
Promise<ResourceResponse, ResourceException> promise = umaLabelResource.deleteInstance(serverContext, LABEL_ID, deleteRequest);
//Then
verify(umaLabelsStore, Mockito.times(1)).delete(REALM_NAME, RESOURCE_OWNER_ID, LABEL_ID);
assertThat(promise).succeeded();
}
Aggregations