Search in sources :

Example 6 with SearchFilter

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

the class EntitlementService method getApplicationSearchFilter.

private String getApplicationSearchFilter(Set<SearchFilter> filters) {
    StringBuilder strFilter = new StringBuilder();
    if ((filters == null) || filters.isEmpty()) {
        strFilter.append("(ou=*)");
    } else {
        if (filters.size() == 1) {
            strFilter.append(filters.iterator().next().getFilter());
        } else {
            strFilter.append("(&");
            for (SearchFilter psf : filters) {
                strFilter.append(psf.getFilter());
            }
            strFilter.append(")");
        }
    }
    return strFilter.toString();
}
Also used : SearchFilter(com.sun.identity.entitlement.util.SearchFilter)

Example 7 with SearchFilter

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

the class PrivilegePolicyStoreTest method shouldHandleStringEquality.

@Test
public void shouldHandleStringEquality() throws Exception {
    // Given
    String value = "testValue";
    QueryRequest request = mockQueryRequest(QueryFilter.equalTo(new JsonPointer(STRING_ATTRIBUTE), value));
    // When
    testStore.query(request);
    // Then
    verify(mockManager).search(singleton(new SearchFilter(STRING_SEARCH_ATTRIBUTE, value)));
}
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 8 with SearchFilter

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

the class ApplicationsResourceTest method shouldHandleAndQueries.

@Test
public void shouldHandleAndQueries() throws Exception {
    // Given
    String value1 = "value1";
    String value2 = "value2";
    QueryRequest request = mockQueryRequest(and(equalTo(new JsonPointer(STRING_ATTRIBUTE), value1), equalTo(new JsonPointer(STRING_ATTRIBUTE), value2)));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    SearchFilter searchFilter1 = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value1);
    SearchFilter searchFilter2 = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value2);
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter1, searchFilter2)));
}
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 9 with SearchFilter

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

the class ApplicationsResourceTest 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(comparisonFilter(new JsonPointer(DATE_ATTRIBUTE), queryOperator, DateUtils.toUTCDateFormat(value)));
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    // Date should be converted into a time-stamp long value
    SearchFilter searchFilter = new SearchFilter(new SearchAttribute(DATE_ATTRIBUTE, "ou"), value.getTime(), 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) Date(java.util.Date) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 10 with SearchFilter

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

the class ApplicationsResourceTest method shouldTranslateAlwaysTrueQueryFilterToEmptySearchFilters.

@Test
public void shouldTranslateAlwaysTrueQueryFilterToEmptySearchFilters() throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(QueryFilter.<JsonPointer>alwaysTrue());
    Subject subject = new Subject();
    // When
    applicationsResource.query(request, subject, "/abc");
    // Then
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(Collections.<SearchFilter>emptySet()));
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) 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