Search in sources :

Example 36 with JsonPointer

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

the class ResourceSetResourceTest method nameQueryShouldBeSupported.

@Test
public void nameQueryShouldBeSupported() throws Exception {
    //Given
    Context context = mock(Context.class);
    QueryRequest request = mock(QueryRequest.class);
    given(request.getFields()).willReturn(Arrays.asList(new JsonPointer("/fred")));
    QueryResourceHandler handler = mock(QueryResourceHandler.class);
    ResourceSetDescription resourceSet = mock(ResourceSetDescription.class);
    QueryFilter<JsonPointer> queryFilter = QueryFilter.and(QueryFilter.equalTo(new JsonPointer("/name"), "NAME"), QueryFilter.equalTo(new JsonPointer("/resourceServer"), "myclient"), QueryFilter.equalTo(new JsonPointer("/policy/permissions/subject"), "SUBJECT"));
    Promise<Collection<ResourceSetDescription>, ResourceException> resourceSetsPromise = Promises.newResultPromise((Collection<ResourceSetDescription>) asSet(resourceSet));
    given(contextHelper.getRealm(context)).willReturn("REALM");
    given(contextHelper.getUserId(context)).willReturn("RESOURCE_OWNER_ID");
    given(request.getQueryFilter()).willReturn(queryFilter);
    given(resourceSetService.getResourceSets(eq(context), eq("REALM"), Matchers.<ResourceSetWithPolicyQuery>anyObject(), eq("RESOURCE_OWNER_ID"), eq(false))).willReturn(resourceSetsPromise);
    //When
    Promise<QueryResponse, ResourceException> promise = resource.queryCollection(context, request, handler);
    //Then
    ArgumentCaptor<ResourceSetWithPolicyQuery> queryCaptor = ArgumentCaptor.forClass(ResourceSetWithPolicyQuery.class);
    verify(resourceSetService).getResourceSets(eq(context), eq("REALM"), queryCaptor.capture(), eq("RESOURCE_OWNER_ID"), eq(false));
    assertThat(queryCaptor.getValue().getOperator()).isEqualTo(AggregateQuery.Operator.AND);
    assertThat(queryCaptor.getValue().getPolicyQuery()).isEqualTo(QueryFilter.equalTo(new JsonPointer("/permissions/subject"), "SUBJECT"));
    assertThat(queryCaptor.getValue().getResourceSetQuery()).isEqualTo(QueryFilter.and(QueryFilter.equalTo("name", "NAME"), QueryFilter.equalTo("clientId", "myclient")));
    assertThat(promise).succeeded().withObject().isNotNull();
}
Also used : Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) JsonPointer(org.forgerock.json.JsonPointer) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) QueryResponse(org.forgerock.json.resource.QueryResponse) Collection(java.util.Collection) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) Test(org.testng.annotations.Test)

Example 37 with JsonPointer

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

the class PolicySearchTest method shouldSearchBasedOnSubject.

@Test
public void shouldSearchBasedOnSubject() throws Exception {
    //Given
    JsonValue policy1 = createUmaPolicyJson("SUBJECT_ONE");
    JsonValue policy2 = createUmaPolicyJson("SUBJECT_THREE");
    UmaPolicy umaPolicy1 = UmaPolicy.valueOf(resourceSet1, policy1);
    UmaPolicy umaPolicy2 = UmaPolicy.valueOf(resourceSet2, policy2);
    Set<UmaPolicy> policies = new HashSet<UmaPolicy>();
    policies.add(umaPolicy1);
    policies.add(umaPolicy2);
    //When
    PolicySearch search = new PolicySearch(policies).equals(new JsonPointer("/permissions/subject"), "SUBJECT_ONE");
    //Then
    assertThat(search.getPolicies()).hasSize(1).contains(umaPolicy1);
}
Also used : JsonValue(org.forgerock.json.JsonValue) JsonPointer(org.forgerock.json.JsonPointer) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 38 with JsonPointer

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

the class PolicySearchTest method shouldSearchBasedOnResourceServer.

@Test
public void shouldSearchBasedOnResourceServer() throws Exception {
    //Given
    JsonValue policy1 = createUmaPolicyJson("SUBJECT_ONE");
    JsonValue policy2 = createUmaPolicyJson("SUBJECT_THREE");
    UmaPolicy umaPolicy1 = UmaPolicy.valueOf(resourceSet1, policy1);
    UmaPolicy umaPolicy2 = UmaPolicy.valueOf(resourceSet2, policy2);
    Set<UmaPolicy> policies = new HashSet<UmaPolicy>();
    policies.add(umaPolicy1);
    policies.add(umaPolicy2);
    //When
    PolicySearch search = new PolicySearch(policies).equals(new JsonPointer("/resourceServer"), "CLIENT_ID_2");
    //Then
    assertThat(search.getPolicies()).hasSize(1).contains(umaPolicy2);
}
Also used : JsonValue(org.forgerock.json.JsonValue) JsonPointer(org.forgerock.json.JsonPointer) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 39 with JsonPointer

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

the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesBySubject.

@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesBySubject() throws Exception {
    //Given
    Context context = createContext();
    QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "SUBJECT_ONE"));
    mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
    //When
    Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
    //Then
    assertThat(queryResult.getSecond()).hasSize(1);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) QueryResponse(org.forgerock.json.resource.QueryResponse) Collection(java.util.Collection) JsonPointer(org.forgerock.json.JsonPointer) Test(org.testng.annotations.Test)

Example 40 with JsonPointer

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

the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesBySubjectAndResourceServer.

@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesBySubjectAndResourceServer() throws Exception {
    //Given
    Context context = createContext();
    QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "SUBJECT_ONE"), QueryFilter.equalTo(new JsonPointer("resourceServer"), "CLIENT_ID")));
    mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
    //When
    Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
    //Then
    assertThat(queryResult.getSecond()).hasSize(1);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) QueryResponse(org.forgerock.json.resource.QueryResponse) Collection(java.util.Collection) 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