Search in sources :

Example 31 with QueryResponse

use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.

the class UmaPolicyServiceImplTest method shouldHandleFailureToDeleteUnderlyingPolicies.

@Test(expectedExceptions = ResourceException.class)
@SuppressWarnings("unchecked")
public void shouldHandleFailureToDeleteUnderlyingPolicies() throws Exception {
    //Given
    Context context = createContext();
    ResourceException exception = mock(ResourceException.class);
    List<ResourceResponse> readPolicies = new ArrayList<>();
    ResourceResponse readPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOnePolicyJson());
    ResourceResponse readPolicy2 = newResourceResponse("ID_2", "REVISION_2", createBackendSubjectTwoPolicyJson());
    readPolicies.add(readPolicy1);
    readPolicies.add(readPolicy2);
    Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> currentPolicyPromise = newResultPromise(Pair.of((QueryResponse) null, readPolicies));
    Promise<List<ResourceResponse>, ResourceException> deletePoliciesPromise = newExceptionPromise(exception);
    given(policyResourceDelegate.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(currentPolicyPromise);
    given(policyResourceDelegate.deletePolicies(eq(context), anyListOf(String.class))).willReturn(deletePoliciesPromise);
    //When
    try {
        policyService.deletePolicy(context, "RESOURCE_SET_ID").getOrThrowUninterruptibly();
    } catch (ResourceException e) {
        //Then
        verify(policyResourceDelegate).deletePolicies(eq(context), anyListOf(String.class));
        throw e;
    }
}
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) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ArrayList(java.util.ArrayList) ResourceException(org.forgerock.json.resource.ResourceException) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Pair(org.forgerock.util.Pair) Test(org.testng.annotations.Test)

Example 32 with QueryResponse

use of org.forgerock.json.resource.QueryResponse 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 33 with QueryResponse

use of org.forgerock.json.resource.QueryResponse 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)

Example 34 with QueryResponse

use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.

the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByResourceServer.

@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByResourceServer() throws Exception {
    //Given
    Context context = createContext();
    QueryRequest request = Requests.newQueryRequest("").setQueryFilter(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)

Example 35 with QueryResponse

use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.

the class ResourceSetServiceTest method getResourceSetsShouldReturnSetWhenResourceSetsExistWithNoPolicyQuery.

@Test
public void getResourceSetsShouldReturnSetWhenResourceSetsExistWithNoPolicyQuery() throws Exception {
    //Given
    Context context = createContext();
    String realm = "REALM";
    ResourceSetWithPolicyQuery query = new ResourceSetWithPolicyQuery();
    String resourceOwnerId = "RESOURCE_OWNER_ID";
    boolean augmentWithPolicies = false;
    QueryFilter<String> resourceSetQuery = mock(QueryFilter.class);
    Set<ResourceSetDescription> queriedResourceSets = new HashSet<>();
    ResourceSetDescription resourceSetOne = new ResourceSetDescription("RS_ID_ONE", "CLIENT_ID_ONE", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
    ResourceSetDescription resourceSetTwo = new ResourceSetDescription("RS_ID_TWO", "CLIENT_ID_TWO", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
    mockResourceOwnerIdentity(resourceOwnerId, realm);
    mockFilteredResourceSetsQueryVisitor(resourceSetQuery, queriedResourceSets);
    query.setResourceSetQuery(resourceSetQuery);
    queriedResourceSets.add(resourceSetOne);
    queriedResourceSets.add(resourceSetTwo);
    given(resourceSetStore.query(resourceSetQuery)).willReturn(queriedResourceSets);
    Collection<UmaPolicy> queriedPolicies = new HashSet<UmaPolicy>();
    Pair<QueryResponse, Collection<UmaPolicy>> queriedPoliciesPair = Pair.of(newQueryResponse(), queriedPolicies);
    Promise<Pair<QueryResponse, Collection<UmaPolicy>>, ResourceException> queriedPoliciesPromise = Promises.newResultPromise(queriedPoliciesPair);
    given(policyService.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(queriedPoliciesPromise);
    //When
    Collection<ResourceSetDescription> resourceSets = service.getResourceSets(context, realm, query, resourceOwnerId, augmentWithPolicies).getOrThrowUninterruptibly();
    //Then
    assertThat(resourceSets).hasSize(2).contains(resourceSetOne, resourceSetTwo);
    assertThat(resourceSetOne.getPolicy()).isNull();
    assertThat(resourceSetTwo.getPolicy()).isNull();
}
Also used : RootContext(org.forgerock.services.context.RootContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Responses.newQueryResponse(org.forgerock.json.resource.Responses.newQueryResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) Collection(java.util.Collection) ResourceException(org.forgerock.json.resource.ResourceException) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) HashSet(java.util.HashSet) Pair(org.forgerock.util.Pair) Test(org.testng.annotations.Test)

Aggregations

QueryResponse (org.forgerock.json.resource.QueryResponse)57 Test (org.testng.annotations.Test)49 ResourceException (org.forgerock.json.resource.ResourceException)43 QueryRequest (org.forgerock.json.resource.QueryRequest)42 Context (org.forgerock.services.context.Context)42 RealmContext (org.forgerock.openam.rest.RealmContext)37 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)26 ClientContext (org.forgerock.services.context.ClientContext)25 ResourceResponse (org.forgerock.json.resource.ResourceResponse)24 Collection (java.util.Collection)23 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)20 JsonPointer (org.forgerock.json.JsonPointer)19 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)19 Pair (org.forgerock.util.Pair)19 UmaPolicy (org.forgerock.openam.uma.UmaPolicy)16 HashSet (java.util.HashSet)14 JsonValue (org.forgerock.json.JsonValue)13 ArrayList (java.util.ArrayList)12 Subject (javax.security.auth.Subject)12 Responses.newQueryResponse (org.forgerock.json.resource.Responses.newQueryResponse)12