Search in sources :

Example 66 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PolicyResource method queryCollection.

/**
     * {@inheritDoc}
     */
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
    try {
        List<ResourceResponse> results = new ArrayList<>();
        for (Privilege policy : policyStoreProvider.getPolicyStore(context).query(request)) {
            results.add(policyResource(policy));
        }
        QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
        return QueryResponsePresentation.perform(handler, request, results);
    } catch (EntitlementException ex) {
        DEBUG.error("PolicyResource :: QUERY : Error querying policy collection.", ex);
        return resourceErrorHandler.handleError(context, request, ex).asPromise();
    } catch (IllegalArgumentException ex) {
        DEBUG.error("PolicyResource :: QUERY : Error querying policy collection due to bad request.", ex);
        return new BadRequestException(ex.getMessage()).asPromise();
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ArrayList(java.util.ArrayList) BadRequestException(org.forgerock.json.resource.BadRequestException) Privilege(com.sun.identity.entitlement.Privilege)

Example 67 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PolicyResourceTest method shouldAcceptConsistentPolicyNamesFromURLandJSON.

@Test
public void shouldAcceptConsistentPolicyNamesFromURLandJSON() throws Exception {
    // Given
    String policyName = "policyName";
    // Policy name can be specified in *both* URL and JSON so long as it is equal
    JsonValue json = JsonValue.json(JsonValue.object(JsonValue.field("name", policyName)));
    CreateRequest request = mockCreateRequest(policyName, json);
    Privilege policy = mockPrivilege(policyName, 123l);
    given(mockParser.parsePolicy(policyName, json)).willReturn(policy);
    // When
    policyResource.createInstance(mockServerContext, request);
    // Then
    verify(mockParser).parsePolicy(policyName, json);
}
Also used : CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 68 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PolicyResourceTest method shouldReadPoliciesFromStore.

@Test
public void shouldReadPoliciesFromStore() throws Exception {
    // Given
    String id = "testPolicy";
    long lastModified = 1234l;
    Privilege policy = mockPrivilege(id, lastModified);
    ReadRequest request = mock(ReadRequest.class);
    given(mockStore.read(id)).willReturn(policy);
    JsonValue content = new JsonValue("content");
    given(mockParser.printPolicy(policy)).willReturn(content);
    // When
    Promise<ResourceResponse, ResourceException> promise = policyResource.readInstance(mockServerContext, id, request);
    // Then
    assertThat(promise).succeeded().withId().isNotNull();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Privilege(com.sun.identity.entitlement.Privilege) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 69 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PrivilegePolicyStoreTest method shouldDelegateReadsToPrivilegeManager.

@Test
public void shouldDelegateReadsToPrivilegeManager() throws Exception {
    // Given
    String id = "testPolicy";
    Privilege policy = new StubPrivilege();
    given(mockManager.findByName(id)).willReturn(policy);
    // When
    Privilege response = testStore.read(id);
    // Then
    verify(mockManager).findByName(id);
    assertThat(response).isSameAs(policy);
}
Also used : Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 70 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PolicyResourceTest method shouldUpdatePoliciesInStore.

@Test
public void shouldUpdatePoliciesInStore() throws Exception {
    // Given
    String id = "testPolicy";
    long lastModified = 1234l;
    UpdateRequest request = mock(UpdateRequest.class);
    JsonValue content = new JsonValue("content");
    given(request.getContent()).willReturn(content);
    Privilege privilege = mockPrivilege(id, lastModified);
    given(mockParser.parsePolicy(id, content)).willReturn(privilege);
    given(mockStore.update(id, privilege)).willReturn(privilege);
    // When
    Promise<ResourceResponse, ResourceException> promise = policyResource.updateInstance(mockServerContext, id, request);
    // Then
    assertThat(promise).succeeded().withId().isNotNull();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Aggregations

Privilege (com.sun.identity.entitlement.Privilege)122 Test (org.testng.annotations.Test)76 JsonValue (org.forgerock.json.JsonValue)46 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)39 HashSet (java.util.HashSet)30 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)26 EntitlementException (com.sun.identity.entitlement.EntitlementException)23 IPrivilege (com.sun.identity.entitlement.IPrivilege)23 Entitlement (com.sun.identity.entitlement.Entitlement)19 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)18 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)17 HashMap (java.util.HashMap)15 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)13 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)11 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)10 Set (java.util.Set)9 SSOToken (com.iplanet.sso.SSOToken)8 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)8 Subject (javax.security.auth.Subject)8 ResourceResponse (org.forgerock.json.resource.ResourceResponse)8