use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.
the class ConstraintValidatorImplTest method invalidResourcesFail.
@Test
public void invalidResourcesFail() {
// Given
ResourceType resourceType = ResourceType.builder().setName("test").setUUID("abc").addPattern("a://b:c/*").addPattern("d://*:*/*").build();
// When
Set<String> resources = CollectionUtils.asSet("a://b:c/def/hij", "fail://uri:blah/goodbye");
boolean successful = validator.verifyResources(resources).using(new URLResourceName()).against(resourceType).isSuccessful();
// Then
assertThat(successful).isFalse();
}
use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.
the class ConstraintValidatorImplTest method exactActionsPass.
@Test
public void exactActionsPass() {
// Given
ResourceType resourceType = ResourceType.builder().setName("test").setUUID("abc").addAction("GET", true).addAction("POST", true).build();
// When
Set<String> actions = CollectionUtils.asSet("GET", "POST");
boolean successful = validator.verifyActions(actions).against(resourceType).isSuccessful();
// Then
assertThat(successful).isTrue();
}
use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.
the class ResourceTypesResource method updateInstance.
/**
* Update a {@link org.forgerock.openam.entitlement.ResourceType} in the system.
*
* The user's {@link org.forgerock.json.resource.SecurityContext} must indicate they are a user with
* administrator-level access.
*
* @param context {@inheritDoc}
* @param request {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId, UpdateRequest request) {
String principalName = "unknown";
try {
final Subject subject = getSubject(context);
principalName = PrincipalRestUtils.getPrincipalNameFromSubject(subject);
final JsonResourceType jsonWrapper = createJsonResourceType(request.getContent());
if (StringUtils.isEmpty(jsonWrapper.getName())) {
throw new EntitlementException(MISSING_RESOURCE_TYPE_NAME);
}
ResourceType resourceTypeToUpdate = jsonWrapper.getResourceType(false);
if (!StringUtils.isEqualTo(resourceId, resourceTypeToUpdate.getUUID())) {
throw new EntitlementException(RESOURCE_TYPE_ID_MISMATCH);
}
final ResourceType updatedResourceType = resourceTypeService.updateResourceType(subject, getRealm(context), resourceTypeToUpdate);
if (logger.messageEnabled()) {
logger.message("ResourceTypeResource :: UPDATE by " + principalName + ": for Resource Type: " + jsonWrapper.getName());
}
return newResultPromise(newResourceResponse(updatedResourceType.getUUID(), null, new JsonResourceType(updatedResourceType).toJsonValue()));
} catch (EntitlementException e) {
if (logger.errorEnabled()) {
logger.error("ResourceTypeResource :: UPDATE by " + principalName + ": Resource Type update failed. ", e);
}
return exceptionMappingHandler.handleError(context, request, e).asPromise();
}
}
use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.
the class ApplicationV1FilterTest method resourceTypeAssociationOnCreate.
/**
* Verifies that the appropriate resource type is associated with the application being created.
*/
@Test
public void resourceTypeAssociationOnCreate() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
// Build application JSON representation.
JsonValue jsonValue = json(object(TestData.DATA_SET_1.getResources().asJson(), TestData.DATA_SET_1.getActions().asJson(), field("realm", "/abc")));
CreateRequest createRequest = mock(CreateRequest.class);
given(createRequest.getContent()).willReturn(jsonValue);
Set<ResourceType> resourceTypes = CollectionUtils.asSet(ResourceType.builder().setName("test").setUUID(TestData.DATA_SET_1.getResourceTypeUuid()).build());
given(resourceTypeService.getResourceTypes(queryFilterCaptor.capture(), eq(subject), eq("/abc"))).willReturn(resourceTypes);
given(requestHandler.handleCreate(eq(context), eq(createRequest))).willReturn(mockPromise);
// When
Promise<ResourceResponse, ResourceException> result = filter.filterCreate(context, createRequest, requestHandler);
// Then
assertThat(jsonValue.get("resourceTypeUuids").asSet(String.class)).containsOnly(TestData.DATA_SET_1.getResourceTypeUuid());
verify(requestHandler).handleCreate(eq(context), eq(createRequest));
}
use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.
the class ApplicationV1FilterTest method updateModifiesUnderlyingResourceType.
/**
* Verifies that the underlying associated resource type is updated to reflect changes in a v1.0 application.
*/
@Test
public void updateModifiesUnderlyingResourceType() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
// Build application JSON representation.
JsonValue jsonValue = json(object(TestData.DATA_SET_1.getResources().asJson(), TestData.DATA_SET_1.getActions().asJson(), field("realm", "/abc")));
UpdateRequest updateRequest = mock(UpdateRequest.class);
given(updateRequest.getContent()).willReturn(jsonValue);
given(updateRequest.getResourcePath()).willReturn("testApplication");
given(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
Application application = mock(Application.class);
given(applicationService.getApplication("testApplication")).willReturn(application);
Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-ghi"));
given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
ResourceType resourceType = ResourceType.builder().setName("test").setUUID("abc-def-ghi").setActions(TestData.DATA_SET_2.getActions().getUnderlyingMap()).setPatterns(TestData.DATA_SET_2.getResources().getUnderlyingSet()).build();
given(resourceTypeService.getResourceType(subject, "/abc", "abc-def-ghi")).willReturn(resourceType);
// When
filter.filterUpdate(context, updateRequest, requestHandler);
// Then
assertThat(jsonValue.get("resourceTypeUuids").asSet(String.class)).containsOnly("abc-def-ghi");
verify(resourceTypeService).updateResourceType(eq(subject), eq("/abc"), resourceTypeCaptor.capture());
verify(requestHandler).handleUpdate(eq(context), eq(updateRequest));
ResourceType capturedResourceType = resourceTypeCaptor.getValue();
assertThat(capturedResourceType.getUUID()).isEqualTo("abc-def-ghi");
assertThat(capturedResourceType.getActions()).isEqualTo(TestData.DATA_SET_1.getActions().getUnderlyingMap());
assertThat(capturedResourceType.getPatterns()).isEqualTo(TestData.DATA_SET_1.getResources().getUnderlyingSet());
}
Aggregations