Search in sources :

Example 11 with SearchFilter

use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.

the class SearchFilterFactory method getFilter.

/**
     * Returns a SearchFilter that matches the search string provided.
     *
     * Supports the following syntax:
     * [attribute name][operator][attribute value]
     *
     * Where operator can be one of the following:
     * Equals - =
     * Less Than - <
     * Greater Than - >
     *
     * @param filter Non null String representing a search filter.
     * @return Non null parsed SearchFilter.
     * @throws EntitlementException If there was an error pasing the filter.
     */
public SearchFilter getFilter(String filter) throws EntitlementException {
    Object[] parts = parseFilter(filter);
    String name = (String) parts[0];
    SearchFilter.Operator operator = (SearchFilter.Operator) parts[1];
    String value = (String) parts[2];
    if (isAttributeNumeric(name)) {
        // The < and > operators only apply to numeric attributes
        try {
            return new SearchFilter(getSearchAttribute(name), Long.parseLong(value), operator);
        } catch (NumberFormatException e) {
            throw new EntitlementException(INVALID_SEARCH_FILTER, new Object[] { "Invalid value for attribute", name, value });
        }
    } else {
        // Everything else is assumed to be equals.
        return new SearchFilter(getSearchAttribute(name), value);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SearchFilter(com.sun.identity.entitlement.util.SearchFilter)

Example 12 with SearchFilter

use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.

the class SearchFilterFactoryTest method shouldConsiderWhiteSpaceOK.

@Test
public void shouldConsiderWhiteSpaceOK() throws EntitlementException {
    String filter = "badger = another badger";
    SearchFilter result = factory.getFilter(filter);
    assertThat(result.getName()).isEqualTo("badger");
}
Also used : SearchFilter(com.sun.identity.entitlement.util.SearchFilter) Test(org.testng.annotations.Test)

Example 13 with SearchFilter

use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.

the class SearchFilterFactoryTest method shouldParseEquals.

@Test
public void shouldParseEquals() throws EntitlementException {
    String filter = "badger=mammal";
    SearchFilter result = factory.getFilter(filter);
    assertThat(result.getOperator()).isEqualTo(SearchFilter.Operator.EQUALS_OPERATOR);
}
Also used : SearchFilter(com.sun.identity.entitlement.util.SearchFilter) Test(org.testng.annotations.Test)

Example 14 with SearchFilter

use of com.sun.identity.entitlement.util.SearchFilter 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)

Example 15 with SearchFilter

use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldTranslateSupportedOperators.

@Test(dataProvider = "SupportedQueryOperators")
public void shouldTranslateSupportedOperators(String queryOperator, SearchFilter.Operator expectedOperator) throws Exception {
    // Given
    long value = 123l;
    QueryRequest request = mockQueryRequest(comparisonFilter(new JsonPointer(NUMERIC_ATTRIBUTE), queryOperator, value));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    SearchFilter searchFilter = new SearchFilter(new SearchAttribute(NUMERIC_ATTRIBUTE, "ou"), value, expectedOperator);
    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) JsonPointer(org.forgerock.json.JsonPointer) Subject(javax.security.auth.Subject) 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