Search in sources :

Example 11 with ResourceType

use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.

the class RemoveReferralsStep method instateAssociatedResourceType.

private String instateAssociatedResourceType(String resourceTypeId, String sourceRealm, String destinationRealm) throws EntitlementException, UpgradeException {
    Pair<String, String> key = Pair.of(destinationRealm, resourceTypeId);
    if (clonedResourceTypes.containsKey(key)) {
        return clonedResourceTypes.get(key);
    }
    ResourceType resourceType = resourceTypeService.getResourceType(getAdminSubject(), sourceRealm, resourceTypeId);
    if (resourceType == null) {
        throw new UpgradeException(format("Expected resource type %s in realm %s", resourceTypeId, sourceRealm));
    }
    ResourceType clonedResourceType = cloneResourceType(resourceType);
    resourceTypeService.saveResourceType(getAdminSubject(), destinationRealm, clonedResourceType);
    clonedResourceTypes.put(key, clonedResourceType.getUUID());
    return clonedResourceType.getUUID();
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ResourceType(org.forgerock.openam.entitlement.ResourceType)

Example 12 with ResourceType

use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.

the class ConstraintValidatorImplTest method subsetActionsPass.

@Test
public void subsetActionsPass() {
    // Given
    ResourceType resourceType = ResourceType.builder().setName("test").setUUID("abc").addAction("GET", true).addAction("POST", true).addAction("DELETE", true).addAction("PATCH", 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 13 with ResourceType

use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.

the class ConstraintValidatorImplTest method throwsExceptionWhenActionsFail.

@Test(expectedExceptions = ConstraintFailureException.class, expectedExceptionsMessageRegExp = "Invalid value DELETE for property actionValues")
public void throwsExceptionWhenActionsFail() throws ConstraintFailureException {
    // Given
    ResourceType resourceType = ResourceType.builder().setName("test").setUUID("abc").addAction("GET", true).addAction("POST", true).build();
    // When
    Set<String> actions = CollectionUtils.asSet("GET", "POST", "DELETE");
    validator.verifyActions(actions).against(resourceType).throwExceptionIfFailure();
}
Also used : ResourceType(org.forgerock.openam.entitlement.ResourceType) Test(org.testng.annotations.Test)

Example 14 with ResourceType

use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.

the class ConstraintValidatorImplTest method validResourcesPass.

@Test
public void validResourcesPass() {
    // 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", "d://fried:egg/test/home");
    boolean successful = validator.verifyResources(resources).using(new URLResourceName()).against(resourceType).isSuccessful();
    // Then
    assertThat(successful).isTrue();
}
Also used : URLResourceName(com.sun.identity.entitlement.URLResourceName) ResourceType(org.forgerock.openam.entitlement.ResourceType) Test(org.testng.annotations.Test)

Example 15 with ResourceType

use of org.forgerock.openam.entitlement.ResourceType in project OpenAM by OpenRock.

the class ConstraintValidatorImplTest method throwsExceptionWhenResourcesFail.

@Test(expectedExceptions = ConstraintFailureException.class, expectedExceptionsMessageRegExp = "Invalid value fail://uri:blah/goodbye for property resources")
public void throwsExceptionWhenResourcesFail() throws ConstraintFailureException {
    // 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");
    validator.verifyResources(resources).using(new URLResourceName()).against(resourceType).throwExceptionIfFailure();
}
Also used : URLResourceName(com.sun.identity.entitlement.URLResourceName) ResourceType(org.forgerock.openam.entitlement.ResourceType) 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