use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class OpenAMOAuth2ProviderSettings method getJWKSet.
public JsonValue getJWKSet() throws ServerException {
synchronized (jwks) {
if (jwks.isEmpty()) {
PublicKey key = getServerKeyPair().getPublic();
jwks.add(createRSAJWK((RSAPublicKey) key, KeyUse.SIG, JwsAlgorithm.RS256.name()));
}
}
return new JsonValue(Collections.singletonMap("keys", jwks));
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class PolicyResourceDelegateTest method shouldHandleFailureToDeleteFailedCreationOfPolicies.
@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToDeleteFailedCreationOfPolicies() throws ResourceException {
//Given
//Given
Context context = mock(Context.class);
Set<JsonValue> policies = new HashSet<JsonValue>();
JsonValue policyOne = json(object(field("name", "POLICY_ONE")));
JsonValue policyTwo = json(object(field("name", "POLICY_TWO")));
policies.add(policyOne);
policies.add(policyTwo);
ResourceResponse createdPolicyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
ResourceException createException = mock(ResourceException.class);
ResourceException deleteException = mock(ResourceException.class);
Promise<ResourceResponse, ResourceException> createPolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
Promise<ResourceResponse, ResourceException> createPolicyTwoPromise = Promises.newExceptionPromise(createException);
Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newExceptionPromise(deleteException);
given(policyResource.handleCreate(eq(context), Matchers.<CreateRequest>anyObject())).willReturn(createPolicyOnePromise).willReturn(createPolicyTwoPromise);
given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())).willReturn(deletePolicyOnePromise);
//When
try {
delegate.createPolicies(context, policies).getOrThrowUninterruptibly();
} catch (ResourceException e) {
//Then
ArgumentCaptor<DeleteRequest> requestCaptor = ArgumentCaptor.forClass(DeleteRequest.class);
verify(policyResource).handleDelete(eq(context), requestCaptor.capture());
assertThat(requestCaptor.getValue().getResourcePathObject().leaf()).isEqualTo("ID_1");
assertThat(e).isEqualTo(deleteException);
throw e;
}
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class ResourceSetResourceTest method shouldRevokeAllUserPolicies.
@Test
public void shouldRevokeAllUserPolicies() throws ResourceException {
//Given
Context context = mock(Context.class);
ActionRequest request = mock(ActionRequest.class);
given(contextHelper.getRealm(context)).willReturn("REALM");
given(contextHelper.getUserId(context)).willReturn("RESOURCE_OWNER_ID");
given(request.getAction()).willReturn("revokeAll");
given(resourceSetService.revokeAllPolicies(context, "REALM", "RESOURCE_OWNER_ID")).willReturn(Promises.<Void, ResourceException>newResultPromise(null));
//When
Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
//Then
assertThat(promise).succeeded().withObject().isNotNull();
JsonValue jsonContent = promise.getOrThrowUninterruptibly().getJsonContent();
assertThat(jsonContent.asMap()).isEmpty();
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class PolicyGraphTest method makePolicy.
private static ResourceResponse makePolicy(String owner, String subject, boolean active, String... scopes) {
String policyId = owner + "-" + subject + "-" + active;
JsonValue policy = json(object(field("_id", policyId), field(PolicyGraph.OWNER_KEY, owner), field(SUBJECT_KEY, object(field(BACKEND_POLICY_SUBJECT_CLAIM_VALUE_KEY, subject))), field(PolicyGraph.ACTIVE_KEY, active)));
for (String scope : scopes) {
policy.putPermissive(new JsonPointer(BACKEND_POLICY_ACTION_VALUES_KEY + "/" + scope), true);
}
return Responses.newResourceResponse(policyId, String.valueOf(policyId.hashCode()), policy);
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class PolicyGraphTest method shouldCreatePolicyWhenMakingValid.
/*
Alice had removed Dave's ability to VIEW, EDIT and DELETE, so Dave's resharing
policies to Ed had been made inactive. Alice has re-granted Dave's VIEW and DELETE,
so those need to be active, while EDIT stays inactive.
*/
@Test
public void shouldCreatePolicyWhenMakingValid() throws Exception {
// Given
List<ResourceResponse> policies = excludePolicies(DAVE, ED);
policies.add(makePolicy(DAVE, ED, false, 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(VIEW, DELETE);
assertThat(created.get("active").asBoolean()).isTrue();
assertThat(UmaPolicyUtils.getPolicyScopes(policyUpdated())).containsOnly(EDIT);
verifyNoMoreInteractions(delegate);
}
Aggregations