use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestQueryIsAllowed.
@Test
public void crestQueryIsAllowed() throws SSOException, DelegationException, ResourceException {
// Given...
final Set<String> actions = new HashSet<>(Arrays.asList("READ"));
final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "read", actions, EXTENSIONS, DUMB_FUNC);
given(factory.newInstance("/abc", "rest", "1.0", "policies", "read", actions, EXTENSIONS)).willReturn(permission);
given(subjectContext.getCallerSSOToken()).willReturn(token);
given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
QueryResourceHandler handler = mock(QueryResourceHandler.class);
Promise<QueryResponse, ResourceException> promise = Promises.newResultPromise(Responses.newQueryResponse("abc-def"));
given(provider.queryCollection(isA(Context.class), isA(QueryRequest.class), isA(QueryResourceHandler.class))).willReturn(promise);
// When...
final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
final Router router = new Router();
router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
final RealmContext context = new RealmContext(subjectContext);
context.setSubRealm("abc", "abc");
final QueryRequest request = Requests.newQueryRequest("/policies");
Promise<QueryResponse, ResourceException> result = router.handleQuery(context, request, handler);
// Then...
QueryResponse response = result.getOrThrowUninterruptibly();
assertThat(response.getPagedResultsCookie()).isEqualTo("abc-def");
}
use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class AuditFilterTest method shouldReturnNullForQuerySuccess.
@Test
public void shouldReturnNullForQuerySuccess() {
QueryRequest queryRequest = mock(QueryRequest.class);
QueryResponse queryResponse = mock(QueryResponse.class);
JsonValue filterResponse = auditFilter.getQuerySuccessDetail(queryRequest, queryResponse);
assertThat(filterResponse).isEqualTo(null);
}
use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class UmaPolicyServiceImplDelegationTest method mockPolicyResourceDelegateForUpdatedPolicy.
private void mockPolicyResourceDelegateForUpdatedPolicy() {
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> queryPromise = newResultPromise(Pair.of((QueryResponse) null, currentPolicies));
given(policyResourceDelegate.queryPolicies(any(Context.class), any(QueryRequest.class))).willReturn(queryPromise);
final List<ResourceResponse> updatedPolicies = new ArrayList<>();
ResourceResponse updatedPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOnePolicyJson());
ResourceResponse updatedPolicy3 = newResourceResponse("ID_3", "REVISION_1", createBackendSubjectTwoPolicyJson());
updatedPolicies.add(updatedPolicy1);
updatedPolicies.add(updatedPolicy3);
Promise<List<ResourceResponse>, ResourceException> updatePolicyPromise = newResultPromise(updatedPolicies);
given(policyResourceDelegate.updatePolicies(any(Context.class), Matchers.<Set<JsonValue>>anyObject())).willReturn(updatePolicyPromise);
given(policyResourceDelegate.queryPolicies(any(Context.class), any(QueryRequest.class), any(QueryResourceHandler.class))).willAnswer(new Answer<Promise<QueryResponse, ResourceException>>() {
@Override
public Promise<QueryResponse, ResourceException> answer(InvocationOnMock invocation) throws Throwable {
final PolicyGraph policyGraph = (PolicyGraph) invocation.getArguments()[2];
for (ResourceResponse r : updatedPolicies) {
policyGraph.handleResource(r);
}
policyGraph.handleResult(newQueryResponse());
return newResultPromise(newQueryResponse());
}
});
}
use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldSuccessfullyQueryPolicies.
@Test
public void shouldSuccessfullyQueryPolicies() {
//Given
Context context = mock(Context.class);
QueryRequest request = Requests.newQueryRequest("/policies");
QueryResourceHandler handler = mock(QueryResourceHandler.class);
given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
QueryResponse queryResult = newQueryResponse();
Collection<UmaPolicy> umaPolicies = new HashSet<UmaPolicy>();
UmaPolicy policy1 = mock(UmaPolicy.class);
UmaPolicy policy2 = mock(UmaPolicy.class);
umaPolicies.add(policy1);
umaPolicies.add(policy2);
Promise<Pair<QueryResponse, Collection<UmaPolicy>>, ResourceException> promise = Promises.newResultPromise(Pair.of(queryResult, umaPolicies));
given(policyService.queryPolicies(context, request)).willReturn(promise);
//When
policyResource.queryCollection(context, request, handler);
//Then
verify(handler, times(2)).handleResource(Matchers.<ResourceResponse>anyObject());
}
use of org.forgerock.json.resource.QueryResponse 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);
}
Aggregations