Search in sources :

Example 6 with PolicyGraph

use of org.forgerock.openam.uma.rest.PolicyGraph in project OpenAM by OpenRock.

the class PolicyGraphTest method shouldSwitchAllScopesInvalid.

/*
      Dave had removed Ed's ability to DELETE, so Ed's resharing policy to Bob had been
      made inactive. Dave has re-granted Ed's DELETE, so the inactive policy can be made
      active again.
     */
@Test
public void shouldSwitchAllScopesInvalid() throws Exception {
    // Given
    List<ResourceResponse> policies = excludePolicies(ED, BOB);
    policies.add(makePolicy(ED, BOB, false, DELETE));
    PolicyGraph graph = makePolicyGraph(policies);
    graph.computeGraph();
    given(delegate.updatePolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
    // When
    Promise<List<List<ResourceResponse>>, ResourceException> promise = graph.update(null, delegate);
    // Then
    AssertJPromiseAssert.assertThat(promise).succeeded();
    assertThat(policyUpdated().get("active").asBoolean()).isTrue();
    verifyNoMoreInteractions(delegate);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) ArrayList(java.util.ArrayList) List(java.util.List) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 7 with PolicyGraph

use of org.forgerock.openam.uma.rest.PolicyGraph in project OpenAM by OpenRock.

the class PolicyGraphTest method shouldUpdateInvalidRightsTree.

/*
      Dave had previously re-shared VIEW scope to ED, but that was made invalid when
      he lost that scope himself. He has been re-granted that scope so the VIEW scope
      should move the active policy and the empty inactive policy should be deleted.
     */
@Test
public void shouldUpdateInvalidRightsTree() throws Exception {
    // Given
    List<ResourceResponse> policies = excludePolicies(DAVE, ED);
    policies.add(makePolicy(DAVE, ED, true, DELETE));
    policies.add(makePolicy(DAVE, ED, false, VIEW));
    PolicyGraph graph = makePolicyGraph(policies);
    graph.computeGraph();
    given(delegate.updatePolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
    given(delegate.deletePolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
    // When
    Promise<List<List<ResourceResponse>>, ResourceException> promise = graph.update(null, delegate);
    // Then
    AssertJPromiseAssert.assertThat(promise).succeeded();
    assertThat(UmaPolicyUtils.getPolicyScopes(policyUpdated())).containsOnly(VIEW, DELETE);
    assertThat(policyDeleted()).isEqualTo("Dave-Ed-false");
    verifyNoMoreInteractions(delegate);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) ArrayList(java.util.ArrayList) List(java.util.List) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 8 with PolicyGraph

use of org.forgerock.openam.uma.rest.PolicyGraph in project OpenAM by OpenRock.

the class PolicyGraphTest method makePolicyGraph.

private PolicyGraph makePolicyGraph(List<ResourceResponse> policies) {
    PolicyGraph graph = new PolicyGraph(RESOURCE_SET);
    for (ResourceResponse policy : policies) {
        graph.handleResource(policy);
    }
    graph.handleResult(Responses.newQueryResponse());
    return graph;
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph)

Aggregations

PolicyGraph (org.forgerock.openam.uma.rest.PolicyGraph)8 ResourceResponse (org.forgerock.json.resource.ResourceResponse)7 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ResourceException (org.forgerock.json.resource.ResourceException)4 Context (org.forgerock.services.context.Context)4 JsonValue (org.forgerock.json.JsonValue)2 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)2