use of org.forgerock.openam.uma.UmaPolicy in project OpenAM by OpenRock.
the class UmaPolicyServiceImplDelegationTest method bobShouldBeAbleToReadPolicyForResourceSharedByAlice.
@Test
public void bobShouldBeAbleToReadPolicyForResourceSharedByAlice() throws Exception {
//Given
userIsLoggedIn("bob", "REALM");
accessingUriForUser("bob");
String resourceSetId = registerResourceSet("alice");
createPolicyFor("bob", resourceSetId, "SCOPE_A", "SCOPE_B");
createPolicyFor("charlie", resourceSetId, "SCOPE_A", "SCOPE_B");
setResharingModeToImplicit();
JsonValue policy = policyToUpdate(resourceSetId);
Context context = getContext();
//When
Promise<UmaPolicy, ResourceException> promise = policyService.updatePolicy(context, resourceSetId, policy);
//Then
assertThat(promise).succeeded();
}
use of org.forgerock.openam.uma.UmaPolicy in project OpenAM by OpenRock.
the class UmaPolicyServiceImplDelegationTest method bobShouldNotBeAbleToCreatePolicyForResourceWithMoreScopesThanSharedByAlice.
@Test
public void bobShouldNotBeAbleToCreatePolicyForResourceWithMoreScopesThanSharedByAlice() throws Exception {
//Given
userIsLoggedIn("bob", "REALM");
accessingUriForUser("bob");
String resourceSetId = registerResourceSet("alice");
createPolicyFor("bob", resourceSetId, "SCOPE_A");
JsonValue policy = policyToCreate(resourceSetId);
Context context = getContext();
//When
Promise<UmaPolicy, ResourceException> promise = policyService.createPolicy(context, policy);
//Then
assertThat(promise).failedWithException().isInstanceOf(ForbiddenException.class);
verifyPolicyIsNotCreatedForLoggedInUser();
verifyAuditLogNotCreatedForLoggedInUser(resourceSetId);
}
use of org.forgerock.openam.uma.UmaPolicy in project OpenAM by OpenRock.
the class UmaPolicyServiceImplDelegationTest method bobShouldBeAbleToCreatePolicyForResourceSharedByAlice.
@Test
public void bobShouldBeAbleToCreatePolicyForResourceSharedByAlice() throws Exception {
//Given
AMIdentity loggedInUser = userIsLoggedIn("bob", "REALM");
accessingUriForUser("bob");
String resourceSetId = registerResourceSet("alice");
createPolicyFor("bob", resourceSetId, "SCOPE_A", "SCOPE_B");
JsonValue policy = policyToCreate(resourceSetId);
setResharingModeToImplicit();
Context context = getContext();
//When
Promise<UmaPolicy, ResourceException> promise = policyService.createPolicy(context, policy);
//Then
assertThat(promise).succeeded();
verifyPolicyIsCreatedForLoggedInUser();
verifyAuditLogCreatedForLoggedInUser(resourceSetId, loggedInUser);
}
use of org.forgerock.openam.uma.UmaPolicy in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldReadUmaPolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldReadUmaPolicy() throws Exception {
//Given
Context context = createContext();
QueryResponse queryResult = newQueryResponse();
List<ResourceResponse> policies = new ArrayList<>();
ResourceResponse readPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOnePolicyJson());
ResourceResponse readPolicy2 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectTwoPolicyJson());
policies.add(readPolicy1);
policies.add(readPolicy2);
UmaPolicy expectedUmaPolicy = UmaPolicy.fromUnderlyingPolicies(resourceSet, policies);
Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> queryPromise = newResultPromise(Pair.of(queryResult, policies));
given(policyResourceDelegate.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(queryPromise);
//When
UmaPolicy umaPolicy = policyService.readPolicy(context, "RESOURCE_SET_ID").getOrThrowUninterruptibly();
//Then
assertThat(umaPolicy).isEqualTo(expectedUmaPolicy);
}
Aggregations