Search in sources :

Example 41 with QueryResponse

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

the class UmaPolicyServiceImplTest method shouldReadUmaPolicy.

@Test
@SuppressWarnings("unchecked")
public void shouldReadUmaPolicy() throws Exception {
    //Given
    Context context = createContext();
    QueryResponse queryResult = newQueryResponse();
    List<ResourceResponse> policies = new ArrayList<>();
    ResourceResponse readPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOnePolicyJson());
    ResourceResponse readPolicy2 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectTwoPolicyJson());
    policies.add(readPolicy1);
    policies.add(readPolicy2);
    UmaPolicy expectedUmaPolicy = UmaPolicy.fromUnderlyingPolicies(resourceSet, policies);
    Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> queryPromise = newResultPromise(Pair.of(queryResult, policies));
    given(policyResourceDelegate.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(queryPromise);
    //When
    UmaPolicy umaPolicy = policyService.readPolicy(context, "RESOURCE_SET_ID").getOrThrowUninterruptibly();
    //Then
    assertThat(umaPolicy).isEqualTo(expectedUmaPolicy);
}
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) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) Pair(org.forgerock.util.Pair) Test(org.testng.annotations.Test)

Example 42 with QueryResponse

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

the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesBySubjectOrResourceServer.

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

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

the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByUnknownSubjectAndUnknownResourceServer.

@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByUnknownSubjectAndUnknownResourceServer() throws Exception {
    //Given
    Context context = createContext();
    QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "SUBJECT_OTHER"), QueryFilter.equalTo(new JsonPointer("resourceServer"), "OTHER_CLIENT_ID")));
    mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
    //When
    Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
    //Then
    assertThat(queryResult.getSecond()).hasSize(0);
}
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 44 with QueryResponse

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

the class UmaPolicyServiceImplTest method shouldHandleFailureToUpdateUnderlyingPolicies.

@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToUpdateUnderlyingPolicies() throws Exception {
    //Given
    Context context = createContext();
    JsonValue policy = createUmaPolicyJson("RESOURCE_SET_ID", "SCOPE_A", "SCOPE_B");
    ResourceException exception = mock(ResourceException.class);
    Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> currentPolicyPromise = newResultPromise(Pair.of((QueryResponse) null, Collections.<ResourceResponse>emptyList()));
    Promise<List<ResourceResponse>, ResourceException> updatePoliciesPromise = newExceptionPromise(exception);
    given(policyResourceDelegate.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(currentPolicyPromise);
    given(policyResourceDelegate.updatePolicies(eq(context), Matchers.<Set<JsonValue>>anyObject())).willReturn(updatePoliciesPromise);
    //When
    policyService.updatePolicy(context, "RESOURCE_SET_ID", policy).getOrThrowUninterruptibly();
//Then
//Expected ResourceException
}
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) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) List(java.util.List) ArrayList(java.util.ArrayList) Pair(org.forgerock.util.Pair) Test(org.testng.annotations.Test)

Example 45 with QueryResponse

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

the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByUnknownSubjectAndResourceServer.

@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByUnknownSubjectAndResourceServer() throws Exception {
    //Given
    Context context = createContext();
    QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "OTHER_SUBJECT"), 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(0);
}
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

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