Search in sources :

Example 16 with SearchFilter

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;
}
Also used : SearchFilter(com.sun.identity.entitlement.util.SearchFilter)

Example 17 with SearchFilter

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;
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SearchFilter(com.sun.identity.entitlement.util.SearchFilter)

Example 18 with SearchFilter

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)));
}
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 19 with SearchFilter

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)));
}
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 20 with SearchFilter

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

SearchFilter (com.sun.identity.entitlement.util.SearchFilter)26 Test (org.testng.annotations.Test)18 QueryRequest (org.forgerock.json.resource.QueryRequest)9 HashSet (java.util.HashSet)8 JsonPointer (org.forgerock.json.JsonPointer)8 SSOException (com.iplanet.sso.SSOException)7 IdRepoException (com.sun.identity.idm.IdRepoException)7 Subject (javax.security.auth.Subject)6 EntitlementException (com.sun.identity.entitlement.EntitlementException)4 SearchAttribute (com.sun.identity.entitlement.util.SearchAttribute)4 SMSException (com.sun.identity.sm.SMSException)4 SSOToken (com.iplanet.sso.SSOToken)3 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)2 Date (java.util.Date)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AfterTest (org.testng.annotations.AfterTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 CLIException (com.sun.identity.cli.CLIException)1 IPrivilege (com.sun.identity.entitlement.IPrivilege)1 IPrivilegeManager (com.sun.identity.entitlement.IPrivilegeManager)1