Search in sources :

Example 61 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class PrivilegePolicyStoreTest method shouldRejectUnsupportedQueryOperators.

@Test(dataProvider = "UnsupportedOperators", expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*not supported.*")
public void shouldRejectUnsupportedQueryOperators(String queryOperator) throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(QueryFilter.comparisonFilter(new JsonPointer(NUMERIC_ATTRIBUTE), queryOperator, 123l));
    // When
    testStore.query(request);
// Then - exception
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 62 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class JsonPolicyParserTest method shouldPrintSimpleSubjects.

@Test
public void shouldPrintSimpleSubjects() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    policy.setSubject(new AuthenticatedUsers());
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get(new JsonPointer("subject/type")).asString()).isEqualTo("AuthenticatedUsers");
}
Also used : AuthenticatedUsers(org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers) JsonValue(org.forgerock.json.JsonValue) JsonPointer(org.forgerock.json.JsonPointer) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 63 with JsonPointer

use of org.forgerock.json.JsonPointer in project OpenAM by OpenRock.

the class JsonPolicyParserTest method shouldPrintResourceAttributes.

@Test
public void shouldPrintResourceAttributes() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    ResourceAttribute userAttrs = new UserAttributes();
    String userAttrName = "testUserAttribute";
    userAttrs.setPropertyName(userAttrName);
    StaticAttributes staticAttributes = new StaticAttributes();
    String staticAttrName = "testStaticAttribute";
    staticAttributes.setPropertyName(staticAttrName);
    Set<String> staticAttrValue = CollectionUtils.asSet("one", "two", "three");
    staticAttributes.setPropertyValues(staticAttrValue);
    policy.setResourceAttributes(new LinkedHashSet<ResourceAttribute>(Arrays.asList(userAttrs, staticAttributes)));
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("resourceAttributes").asList()).hasSize(2);
    assertThat(result.get(new JsonPointer("resourceAttributes/0/type")).asString()).isEqualTo("User");
    assertThat(result.get(new JsonPointer("resourceAttributes/0/propertyName")).asString()).isEqualTo(userAttrName);
    assertThat(result.get(new JsonPointer("resourceAttributes/1/type")).asString()).isEqualTo("Static");
    assertThat(result.get(new JsonPointer("resourceAttributes/1/propertyName")).asString()).isEqualTo(staticAttrName);
    assertThat(result.get(new JsonPointer("resourceAttributes/1/propertyValues")).asList(String.class)).containsOnly(staticAttrValue.toArray());
}
Also used : JsonValue(org.forgerock.json.JsonValue) StaticAttributes(com.sun.identity.entitlement.StaticAttributes) JsonPointer(org.forgerock.json.JsonPointer) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) UserAttributes(com.sun.identity.entitlement.UserAttributes) Test(org.testng.annotations.Test)

Example 64 with JsonPointer

use of org.forgerock.json.JsonPointer 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

JsonPointer (org.forgerock.json.JsonPointer)64 Test (org.testng.annotations.Test)40 QueryRequest (org.forgerock.json.resource.QueryRequest)34 JsonValue (org.forgerock.json.JsonValue)21 QueryResponse (org.forgerock.json.resource.QueryResponse)19 Context (org.forgerock.services.context.Context)18 RealmContext (org.forgerock.openam.rest.RealmContext)17 Collection (java.util.Collection)15 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)13 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)13 ClientContext (org.forgerock.services.context.ClientContext)13 Subject (javax.security.auth.Subject)10 ResourceException (org.forgerock.json.resource.ResourceException)10 ResourceResponse (org.forgerock.json.resource.ResourceResponse)10 ArrayList (java.util.ArrayList)9 BadRequestException (org.forgerock.json.resource.BadRequestException)9 SearchFilter (com.sun.identity.entitlement.util.SearchFilter)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 List (java.util.List)7