use of org.forgerock.oauth2.resources.ResourceSetDescription 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();
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class PolicySearchTest method setup.
@BeforeMethod
public void setup() {
resourceSet1 = new ResourceSetDescription("RESOURCE_SET_ID_1", "CLIENT_ID_1", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
resourceSet1.setDescription(json(object(field("name", "NAME_1"))));
resourceSet2 = new ResourceSetDescription("RESOURCE_SET_ID_2", "CLIENT_ID_2", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
resourceSet2.setDescription(json(object(field("name", "NAME_2"))));
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class PolicyGraphTest method shouldRemoveLostRights.
/*
Alice has removed Dave's rights to EDIT, so EDIT needs removing from the
active Dave -> Ed policy, and adding to an inactive policy.
*/
@Test
public void shouldRemoveLostRights() throws Exception {
// Given
List<ResourceResponse> policies = excludePolicies(DAVE, ED);
policies.add(makePolicy(DAVE, ED, true, VIEW, DELETE, EDIT));
PolicyGraph graph = makePolicyGraph(policies);
graph.computeGraph();
given(resourceSetStore.read(anyString(), anyString())).willReturn(new ResourceSetDescription(RESOURCE_SET_ID, "RESOURCE_SERVER_ID", ALICE, null));
given(delegate.updatePolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
given(delegate.createPolicies(isNull(Context.class), anySet())).willReturn(Promises.<List<ResourceResponse>, ResourceException>newResultPromise(Collections.<ResourceResponse>emptyList()));
// When
Promise<List<List<ResourceResponse>>, ResourceException> promise = graph.update(null, delegate);
// Then
AssertJPromiseAssert.assertThat(promise).succeeded();
JsonValue created = policyCreated();
assertThat(UmaPolicyUtils.getPolicyScopes(created)).containsOnly(EDIT);
assertThat(created.get("active").asBoolean()).isFalse();
assertThat(UmaPolicyUtils.getPolicyScopes(policyUpdated())).containsOnly(VIEW, DELETE);
verifyNoMoreInteractions(delegate);
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldThrowInvalidScopeExceptionWhenScopeIsNotASetOfStrings.
@Test(expectedExceptions = UmaException.class)
public void shouldThrowInvalidScopeExceptionWhenScopeIsNotASetOfStrings() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("{\"resource_set_id\":\"RESOURCE_SET_ID\", \"scopes\":\"SCOPE\"}");
given(resourceSetStore.read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID")).willReturn(resourceSetDescription);
//When
try {
endpoint.registerPermissionRequest(entity);
} catch (UmaException e) {
//Then
assertThat(e.getStatusCode()).isEqualTo(400);
assertThat(e.getError()).isEqualTo("invalid_scope");
assertThat(e.getMessage()).contains("Required attribute", "'scopes'", "must be an array of Strings");
throw e;
}
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method setupResourceSetStore.
private void setupResourceSetStore() throws NotFoundException, ServerException {
JsonValue description = json(object(field("scopes", array("SCOPE_A", "SCOPE_B"))));
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", description.asMap());
given(resourceSetStore.read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID")).willReturn(resourceSetDescription);
}
Aggregations