Search in sources :

Example 56 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class CrestNoPathDetailsAuditor method postProcessEvent.

/**
     * This wipes out the http request path beyond /sessions, i.e. all information relating to the session id.
     */
@Override
protected void postProcessEvent(AuditEvent auditEvent) {
    final String SESSIONS = "/sessions";
    Reject.ifNull(auditEvent);
    JsonValue jsonValue = auditEvent.getValue();
    JsonPointer pathComponent = new JsonPointer("/http/request/path");
    String path = jsonValue.get(pathComponent).asString();
    if (path != null) {
        int posLast = path.lastIndexOf(SESSIONS);
        if (posLast > 0) {
            path = path.substring(0, posLast + SESSIONS.length());
            jsonValue.remove(pathComponent);
            jsonValue.add(pathComponent, path);
        }
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) JsonPointer(org.forgerock.json.JsonPointer)

Example 57 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class QueryByStringFilterConverterTest method shouldCreateCompoundFilter.

@Test
public void shouldCreateCompoundFilter() {
    // given
    QueryFilter<JsonPointer> filter = and(or(equalTo(new JsonPointer("param1"), "value1"), contains(new JsonPointer("param2"), "value2")), or(equalTo(new JsonPointer("param3"), "value3"), contains(new JsonPointer("param4"), "value4")));
    QueryByStringFilterConverter mockConverter = mock(QueryByStringFilterConverter.class);
    ArgumentCaptor<List> andCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<List> orCaptor = ArgumentCaptor.forClass(List.class);
    when(mockConverter.visitAndFilter(any(Void.class), anyList())).thenCallRealMethod();
    when(mockConverter.visitOrFilter(any(Void.class), anyList())).thenCallRealMethod();
    // when
    filter.accept(mockConverter, null);
    // then
    verify(mockConverter, times(1)).visitAndFilter(any(Void.class), andCaptor.capture());
    assertThat(andCaptor.getValue().size()).isEqualTo(2);
    verify(mockConverter, times(2)).visitOrFilter(any(Void.class), orCaptor.capture());
    assertThat(orCaptor.getAllValues().get(0).size()).isEqualTo(2);
    assertThat(orCaptor.getAllValues().get(1).size()).isEqualTo(2);
    verify(mockConverter, times(2)).visitEqualsFilter(any(Void.class), any(JsonPointer.class), anyObject());
    verify(mockConverter, times(2)).visitContainsFilter(any(Void.class), any(JsonPointer.class), anyObject());
}
Also used : List(java.util.List) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 58 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class PrivilegePolicyStoreTest method shouldRejectUnknownAttributes.

@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*Unknown query field.*")
public void shouldRejectUnknownAttributes() throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(QueryFilter.equalTo(new JsonPointer("unknown"), "a value"));
    // When
    testStore.query(request);
// Then - exception
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 59 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class PrivilegePolicyStoreTest method shouldSupportDateQueries.

@Test(dataProvider = "SupportedQueryOperators")
public void shouldSupportDateQueries(String queryOperator, SearchFilter.Operator expectedOperator) throws Exception {
    // Given
    // Note: only second accuracy supported in timestamp format
    Date value = new Date(123456789000l);
    QueryRequest request = mockQueryRequest(QueryFilter.comparisonFilter(new JsonPointer(DATE_ATTRIBUTE), queryOperator, DateUtils.toUTCDateFormat(value)));
    // When
    testStore.query(request);
    // Then
    // Date should be converted into a time-stamp long value
    verify(mockManager).search(singleton(new SearchFilter(DATE_SEARCH_ATTRIBUTE, value.getTime(), expectedOperator)));
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) JsonPointer(org.forgerock.json.JsonPointer) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 60 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class PrivilegePolicyStoreTest method shouldTranslateSupportedOperators.

@Test(dataProvider = "SupportedQueryOperators")
public void shouldTranslateSupportedOperators(String queryOperator, SearchFilter.Operator expectedOperator) throws Exception {
    // Given
    long value = 123l;
    QueryRequest request = mockQueryRequest(QueryFilter.comparisonFilter(new JsonPointer(NUMERIC_ATTRIBUTE), queryOperator, value));
    // When
    testStore.query(request);
    // Then
    verify(mockManager).search(singleton(new SearchFilter(NUMERIC_SEARCH_ATTRIBUTE, value, expectedOperator)));
}
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)

Aggregations

JsonPointer (org.forgerock.json.JsonPointer)64 Test (org.testng.annotations.Test)40 QueryRequest (org.forgerock.json.resource.QueryRequest)34 JsonValue (org.forgerock.json.JsonValue)21 QueryResponse (org.forgerock.json.resource.QueryResponse)19 Context (org.forgerock.services.context.Context)18 RealmContext (org.forgerock.openam.rest.RealmContext)17 Collection (java.util.Collection)15 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)13 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)13 ClientContext (org.forgerock.services.context.ClientContext)13 Subject (javax.security.auth.Subject)10 ResourceException (org.forgerock.json.resource.ResourceException)10 ResourceResponse (org.forgerock.json.resource.ResourceResponse)10 ArrayList (java.util.ArrayList)9 BadRequestException (org.forgerock.json.resource.BadRequestException)9 SearchFilter (com.sun.identity.entitlement.util.SearchFilter)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 List (java.util.List)7