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);
}
}
}
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());
}
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
}
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)));
}
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)));
}
Aggregations