Search in sources :

Example 46 with QueryRequest

use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.

the class PrivilegePolicyStoreTest method shouldHandleAndQueries.

@Test
public void shouldHandleAndQueries() throws Exception {
    // Given
    String value1 = "value1";
    String value2 = "value2";
    QueryRequest request = mockQueryRequest(QueryFilter.and(QueryFilter.equalTo(new JsonPointer(STRING_ATTRIBUTE), value1), QueryFilter.equalTo(new JsonPointer(STRING_ATTRIBUTE), value2)));
    // When
    testStore.query(request);
    // Then
    verify(mockManager).search(asSet(new SearchFilter(STRING_SEARCH_ATTRIBUTE, value1), new SearchFilter(STRING_SEARCH_ATTRIBUTE, value2)));
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 47 with QueryRequest

use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.

the class PrivilegePolicyStoreTest method shouldSendAllMatchingPoliciesToQueryHandler.

@Test
public void shouldSendAllMatchingPoliciesToQueryHandler() throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(QueryFilter.alwaysTrue());
    List<Privilege> policies = Arrays.<Privilege>asList(new StubPrivilege("one"), new StubPrivilege("two"), new StubPrivilege("three"));
    given(mockManager.search(anySetOf(SearchFilter.class))).willReturn(policies);
    // When
    List<Privilege> result = testStore.query(request);
    // Then
    assertThat(result).isEqualTo(policies);
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 48 with QueryRequest

use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.

the class PrivilegePolicyStoreTest method shouldTranslateAlwaysTrueQueryFilterToEmptySearchFilters.

@Test
public void shouldTranslateAlwaysTrueQueryFilterToEmptySearchFilters() throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(QueryFilter.alwaysTrue());
    // When
    testStore.query(request);
    // Then
    verify(mockManager).search(Collections.<SearchFilter>emptySet());
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) Test(org.testng.annotations.Test)

Example 49 with QueryRequest

use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.

the class PolicyResourceWithCopyMoveSupport method copyOrMovePoliciesByApplication.

private ActionResponse copyOrMovePoliciesByApplication(Context context, ActionRequest request, PolicyAction copyOrMoveAction) throws ResourceException {
    JsonValue payload = request.getContent();
    JsonValue from = payload.get("from");
    JsonValue to = payload.get("to");
    if (from.isNull()) {
        throw new BadRequestException("from definition is missing");
    }
    if (!from.isDefined("application")) {
        throw new BadRequestException("from application definition is missing");
    }
    String sourceApplication = from.get("application").asString();
    if (to.isNull()) {
        throw new BadRequestException("to definition is missing");
    }
    String sourceRealm = RealmContext.getRealm(context);
    String destinationRealm = to.get("realm").defaultTo(sourceRealm).asString();
    String destinationApplication = to.get("application").defaultTo(sourceApplication).asString();
    JsonValue resourceTypeMapping = payload.get("resourceTypeMapping").defaultTo(Collections.emptyMap());
    String namePostfix = to.get("namePostfix").defaultTo("").asString();
    QueryRequest queryRequest = Requests.newQueryRequest("policies");
    queryRequest.setQueryFilter(QueryFilter.equalTo(new JsonPointer("applicationName"), sourceApplication));
    final List<JsonValue> policies = new ArrayList<>();
    router.handleQuery(context, queryRequest, new QueryResourceHandler() {

        @Override
        public boolean handleResource(ResourceResponse resourceResponse) {
            policies.add(resourceResponse.getContent());
            return true;
        }
    }).getOrThrowUninterruptibly();
    JsonValue actionResponseContent = json(array());
    for (JsonValue policy : policies) {
        ActionResponse response = copyOrMoveGivenPolicy(context, policy, destinationRealm, destinationApplication, namePostfix, resourceTypeMapping, copyOrMoveAction);
        actionResponseContent.add(response.getJsonContent().asMap());
    }
    return Responses.newActionResponse(actionResponseContent);
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) ArrayList(java.util.ArrayList) BadRequestException(org.forgerock.json.resource.BadRequestException) JsonPointer(org.forgerock.json.JsonPointer) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) ActionResponse(org.forgerock.json.resource.ActionResponse)

Example 50 with QueryRequest

use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldHandleStringEquality.

@Test
public void shouldHandleStringEquality() throws Exception {
    // Given
    String value = "testValue";
    QueryRequest request = mockQueryRequest(equalTo(new JsonPointer(STRING_ATTRIBUTE), value));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    SearchFilter searchFilter = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value);
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
Also used : SearchAttribute(com.sun.identity.entitlement.util.SearchAttribute) QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) Matchers.anyString(org.mockito.Matchers.anyString) JsonPointer(org.forgerock.json.JsonPointer) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Aggregations

QueryRequest (org.forgerock.json.resource.QueryRequest)79 Test (org.testng.annotations.Test)68 QueryResponse (org.forgerock.json.resource.QueryResponse)40 JsonPointer (org.forgerock.json.JsonPointer)34 Context (org.forgerock.services.context.Context)34 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)29 ResourceException (org.forgerock.json.resource.ResourceException)28 Subject (javax.security.auth.Subject)26 RealmContext (org.forgerock.openam.rest.RealmContext)26 ResourceResponse (org.forgerock.json.resource.ResourceResponse)24 ClientContext (org.forgerock.services.context.ClientContext)22 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)20 Collection (java.util.Collection)15 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)15 SearchFilter (com.sun.identity.entitlement.util.SearchFilter)10 Matchers.anyString (org.mockito.Matchers.anyString)9 JsonValue (org.forgerock.json.JsonValue)8 ArrayList (java.util.ArrayList)7 Set (java.util.Set)7 EntitlementException (com.sun.identity.entitlement.EntitlementException)6