Search in sources :

Example 1 with PolicyGraph

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

the class PolicyGraphTest method shouldCreatePolicyWhenMakingValid.

/*
      Alice had removed Dave's ability to VIEW, EDIT and DELETE, so Dave's resharing
      policies to Ed had been made inactive. Alice has re-granted Dave's VIEW and DELETE,
      so those need to be active, while EDIT stays inactive.
     */
@Test
public void shouldCreatePolicyWhenMakingValid() throws Exception {
    // Given
    List<ResourceResponse> policies = excludePolicies(DAVE, ED);
    policies.add(makePolicy(DAVE, ED, false, VIEW, DELETE, EDIT));
    PolicyGraph graph = makePolicyGraph(policies);
    graph.computeGraph();
    given(resourceSetStore.read(anyString(), anyString())).willReturn(new ResourceSetDescription(RESOURCE_SET_ID, "RESOURCE_SERVER_ID", ALICE, null));
    given(delegate.updatePolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
    given(delegate.createPolicies(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();
    JsonValue created = policyCreated();
    assertThat(UmaPolicyUtils.getPolicyScopes(created)).containsOnly(VIEW, DELETE);
    assertThat(created.get("active").asBoolean()).isTrue();
    assertThat(UmaPolicyUtils.getPolicyScopes(policyUpdated())).containsOnly(EDIT);
    verifyNoMoreInteractions(delegate);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) JsonValue(org.forgerock.json.JsonValue) ArrayList(java.util.ArrayList) List(java.util.List) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

Example 2 with PolicyGraph

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

the class PolicyGraphTest method shouldDetectInvalidRightsTree.

/*
      VIEW scope is accessible to Dave, so his VIEW reshare to Ed should be active, not inactive.
     */
@Test
public void shouldDetectInvalidRightsTree() 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);
    // When
    graph.computeGraph();
    // Then
    assertThat(graph.isValid()).isFalse();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) Test(org.testng.annotations.Test)

Example 3 with PolicyGraph

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

the class PolicyGraphTest method shouldDetectValidRights.

@Test
public void shouldDetectValidRights() throws Exception {
    // Given
    List<ResourceResponse> policies = VALID_POLICIES;
    PolicyGraph graph = makePolicyGraph(policies);
    // When
    graph.computeGraph();
    // Then
    assertThat(graph.isValid()).isTrue();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) Test(org.testng.annotations.Test)

Example 4 with PolicyGraph

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

the class PolicyGraphTest method shouldRequireComputeGraphCall.

@Test(expectedExceptions = IllegalStateException.class)
public void shouldRequireComputeGraphCall() throws Exception {
    // Given
    PolicyGraph graph = new PolicyGraph(RESOURCE_SET);
    // When
    graph.isValid();
}
Also used : PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) Test(org.testng.annotations.Test)

Example 5 with PolicyGraph

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

the class PolicyGraphTest method shouldRemoveLostRights.

/*
      Alice has removed Dave's rights to EDIT, so EDIT needs removing from the
      active Dave -> Ed policy, and adding to an inactive policy.
     */
@Test
public void shouldRemoveLostRights() throws Exception {
    // Given
    List<ResourceResponse> policies = excludePolicies(DAVE, ED);
    policies.add(makePolicy(DAVE, ED, true, VIEW, DELETE, EDIT));
    PolicyGraph graph = makePolicyGraph(policies);
    graph.computeGraph();
    given(resourceSetStore.read(anyString(), anyString())).willReturn(new ResourceSetDescription(RESOURCE_SET_ID, "RESOURCE_SERVER_ID", ALICE, null));
    given(delegate.updatePolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
    given(delegate.createPolicies(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();
    JsonValue created = policyCreated();
    assertThat(UmaPolicyUtils.getPolicyScopes(created)).containsOnly(EDIT);
    assertThat(created.get("active").asBoolean()).isFalse();
    assertThat(UmaPolicyUtils.getPolicyScopes(policyUpdated())).containsOnly(VIEW, DELETE);
    verifyNoMoreInteractions(delegate);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) PolicyGraph(org.forgerock.openam.uma.rest.PolicyGraph) JsonValue(org.forgerock.json.JsonValue) ArrayList(java.util.ArrayList) List(java.util.List) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

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