use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method matchFilter.
private boolean matchFilter(Privilege p, Set<SearchFilter> filters) {
for (SearchFilter filter : filters) {
filter.getFilter();
String filterName = filter.getName();
if (filterName.equals(Privilege.NAME_ATTRIBUTE)) {
if (attrCompare(p.getName(), filter)) {
return true;
}
} else if (filterName.equals(Privilege.DESCRIPTION_ATTRIBUTE)) {
if (attrCompare(p.getDescription(), filter)) {
return true;
}
} else if (filterName.equals(Privilege.CREATED_BY_ATTRIBUTE)) {
if (attrCompare(p.getCreatedBy(), filter)) {
return true;
}
} else if (filterName.equals(Privilege.LAST_MODIFIED_BY_ATTRIBUTE)) {
if (attrCompare(p.getLastModifiedBy(), filter)) {
return true;
}
} else if (filterName.equals(Privilege.CREATION_DATE_ATTRIBUTE)) {
if (attrCompare(p.getCreationDate(), filter)) {
return true;
}
} else if (filterName.equals(Privilege.LAST_MODIFIED_DATE_ATTRIBUTE)) {
if (attrCompare(p.getLastModifiedDate(), filter)) {
return true;
}
}
}
return false;
}
use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.
the class PrivilegeResource method getNumericSearchFilter.
private SearchFilter getNumericSearchFilter(String f, boolean greaterThan) throws EntitlementException {
SearchFilter sf = null;
int idx = (greaterThan) ? f.indexOf('>') : f.indexOf('<');
if (idx != -1) {
String attrName = f.substring(0, idx);
if ((attrName.equals(Privilege.LAST_MODIFIED_DATE_ATTRIBUTE)) || (attrName.equals(Privilege.CREATION_DATE_ATTRIBUTE))) {
try {
sf = new SearchFilter(SearchFilterFactory.getSearchAttribute(attrName), Long.parseLong(f.substring(idx + 1)), SearchFilter.Operator.EQUALS_OPERATOR);
} catch (NumberFormatException e) {
String[] param = { f };
throw new EntitlementException(328, param);
}
} else {
String[] param = { f };
throw new EntitlementException(328, param);
}
}
return sf;
}
use of com.sun.identity.entitlement.util.SearchFilter 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 com.sun.identity.entitlement.util.SearchFilter 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)));
}
use of com.sun.identity.entitlement.util.SearchFilter 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)));
}
Aggregations