use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesBySubjectOrUnknownResourceServer.
@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesBySubjectOrUnknownResourceServer() throws Exception {
//Given
Context context = createContext();
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.or(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "SUBJECT_ONE"), QueryFilter.equalTo(new JsonPointer("resourceServer"), "OTHER_CLIENT_ID")));
mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
//When
Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
//Then
assertThat(queryResult.getSecond()).hasSize(1);
}
use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldUpdateUmaPolicy.
@Test
public void shouldUpdateUmaPolicy() throws Exception {
//Given
Context context = createContext();
JsonValue policy = createUmaPolicyJson("RESOURCE_SET_ID", "SCOPE_A", "SCOPE_C");
policy.remove(new JsonPointer("/permissions/0/scopes/1"));
List<ResourceResponse> updatedPolicies = new ArrayList<>();
ResourceResponse updatedPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOneUpdatedPolicyJson());
ResourceResponse updatedPolicy2 = newResourceResponse("ID_2", "REVISION_1", createBackendSubjectTwoPolicyJson());
updatedPolicies.add(updatedPolicy1);
updatedPolicies.add(updatedPolicy2);
Promise<List<ResourceResponse>, ResourceException> updatePolicyPromise = newResultPromise(updatedPolicies);
List<ResourceResponse> currentPolicies = new ArrayList<>();
ResourceResponse currentPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOnePolicyJson());
ResourceResponse currentPolicy2 = newResourceResponse("ID_2", "REVISION_1", createBackendSubjectTwoPolicyJson());
currentPolicies.add(currentPolicy1);
currentPolicies.add(currentPolicy2);
Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> currentPolicyPromise = newResultPromise(Pair.of((QueryResponse) null, currentPolicies));
setupQueries(currentPolicyPromise, updatedPolicy1, updatedPolicy2);
given(policyResourceDelegate.updatePolicies(eq(context), Matchers.<Set<JsonValue>>anyObject())).willReturn(updatePolicyPromise);
//When
UmaPolicy umaPolicy = policyService.updatePolicy(context, "RESOURCE_SET_ID", policy).getOrThrowUninterruptibly();
//Then
InOrder inOrder = inOrder(resourceDelegationFilter, policyResourceDelegate);
inOrder.verify(resourceDelegationFilter).beforeResourceSharedModification(any(UmaPolicy.class), any(UmaPolicy.class));
inOrder.verify(policyResourceDelegate, times(2)).updatePolicies(any(Context.class), anySetOf(JsonValue.class));
assertThat(umaPolicy.getId()).isEqualTo("RESOURCE_SET_ID");
assertThat(umaPolicy.getRevision()).isNotNull();
JsonValue expectedPolicyJson = createUmaPolicyJson("RESOURCE_SET_ID", "SCOPE_A", "SCOPE_C");
expectedPolicyJson.remove(new JsonPointer("/permissions/0/scopes/1"));
assertThat(umaPolicy.asJson().asMap()).isEqualTo(expectedPolicyJson.asMap());
}
use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByUnknownResourceServer.
@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByUnknownResourceServer() throws Exception {
//Given
Context context = createContext();
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.equalTo(new JsonPointer("resourceServer"), "OTHER_CLIENT_ID"));
mockBackendQuery(context);
//When
Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
//Then
assertThat(queryResult.getSecond()).hasSize(0);
}
use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByUnknownSubjectOrResourceServer.
@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByUnknownSubjectOrResourceServer() throws Exception {
//Given
Context context = createContext();
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.or(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "SUBJECT_OTHER"), QueryFilter.equalTo(new JsonPointer("resourceServer"), "CLIENT_ID")));
mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
//When
Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
//Then
assertThat(queryResult.getSecond()).hasSize(1);
}
use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByUnknownSubjectOrUnknownResourceServer.
@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByUnknownSubjectOrUnknownResourceServer() throws Exception {
//Given
Context context = createContext();
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.or(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "SUBJECT_OTHER"), QueryFilter.equalTo(new JsonPointer("resourceServer"), "OTHER_CLIENT_ID")));
mockBackendQuery(context);
//When
Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
//Then
assertThat(queryResult.getSecond()).hasSize(0);
}
Aggregations