Search in sources :

Example 26 with ResourceType

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();
}
Also used : URLResourceName(com.sun.identity.entitlement.URLResourceName) ResourceType(org.forgerock.openam.entitlement.ResourceType) Test(org.testng.annotations.Test)

Example 27 with ResourceType

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();
}
Also used : ResourceType(org.forgerock.openam.entitlement.ResourceType) Test(org.testng.annotations.Test)

Example 28 with ResourceType

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();
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) JsonResourceType(org.forgerock.openam.entitlement.rest.wrappers.JsonResourceType) JsonResourceType(org.forgerock.openam.entitlement.rest.wrappers.JsonResourceType) ResourceType(org.forgerock.openam.entitlement.ResourceType) Subject(javax.security.auth.Subject)

Example 29 with ResourceType

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));
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 30 with ResourceType

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());
}
Also used : UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceType(org.forgerock.openam.entitlement.ResourceType) Application(com.sun.identity.entitlement.Application) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ResourceType (org.forgerock.openam.entitlement.ResourceType)34 EntitlementException (com.sun.identity.entitlement.EntitlementException)15 Test (org.testng.annotations.Test)13 Subject (javax.security.auth.Subject)9 HashSet (java.util.HashSet)7 JsonValue (org.forgerock.json.JsonValue)7 Application (com.sun.identity.entitlement.Application)6 JsonResourceType (org.forgerock.openam.entitlement.rest.wrappers.JsonResourceType)4 URLResourceName (com.sun.identity.entitlement.URLResourceName)3 HashMap (java.util.HashMap)3 BadRequestException (org.forgerock.json.resource.BadRequestException)3 ResourceResponse (org.forgerock.json.resource.ResourceResponse)3 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)3 QueryFilter (org.forgerock.util.query.QueryFilter)3 Set (java.util.Set)2 CreateRequest (org.forgerock.json.resource.CreateRequest)2 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)2 ApplicationService (org.forgerock.openam.entitlement.service.ApplicationService)2 SSOToken (com.iplanet.sso.SSOToken)1 ApplicationType (com.sun.identity.entitlement.ApplicationType)1