use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldHandleUnknownAction.
@Test
public void shouldHandleUnknownAction() {
// Given...
given(request.getAction()).willReturn("unknownAction");
// When...
Context context = buildContextStructure("/abc");
policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
//verify(jsonHandler).handleError(isA(NotSupportedException.class));
verifyNoMoreInteractions(request, subjectContext, requestFactory, policyRequest, factory, evaluator, parser);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyRequestFactoryTest method shouldRetrieveBatchRequest.
@Test
public void shouldRetrieveBatchRequest() throws EntitlementException {
// When...
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("resources", Arrays.asList("/resource/a", "/resource/b"));
given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
// Given...
Context context = buildContextStructure("/abc");
PolicyRequest request = factory.buildRequest(PolicyAction.EVALUATE, context, actionRequest);
// Then...
assertThat(request).isNotNull();
assertThat(request.getRealm()).isEqualTo("/abc");
assertThat(request).isInstanceOfAny(BatchPolicyRequest.class);
BatchPolicyRequest batchRequest = (BatchPolicyRequest) request;
assertThat(batchRequest.getResources()).containsOnly("/resource/a", "/resource/b");
verify(subjectContext).getCallerSubject();
verify(actionRequest, times(2)).getContent();
verifyNoMoreInteractions(subjectContext, actionRequest);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RealmContextFilter method filterUpdate.
@Override
public Promise<ResourceResponse, ResourceException> filterUpdate(Context context, UpdateRequest request, RequestHandler next) {
try {
Context newContext = evaluate(context, request);
UpdateRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfUpdateRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
return next.handleUpdate(newContext, evaluatedRequest);
} catch (ResourceException e) {
return newExceptionPromise(e);
}
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RealmContextFilter method filterCreate.
@Override
public Promise<ResourceResponse, ResourceException> filterCreate(Context context, CreateRequest request, RequestHandler next) {
try {
Context newContext = evaluate(context, request);
CreateRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfCreateRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
return next.handleCreate(evaluate(context, request), evaluatedRequest);
} catch (ResourceException e) {
return newExceptionPromise(e);
}
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldAllowJwtSubject.
@Test
public void shouldAllowJwtSubject() throws Exception {
// Given
final String subjectName = "test";
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Jwt jwt = getJwtSubject(subjectName);
given(actionRequest.getContent()).willReturn(json(object(field("subject", object(field("jwt", jwt.build()))))));
// When
Context context = buildContextStructure("/abc");
PolicyRequest request = getRequest(context, actionRequest);
// Then
Subject policySubject = request.getPolicySubject();
Set<JwtPrincipal> jwtPrincipals = policySubject.getPrincipals(JwtPrincipal.class);
assertThat(jwtPrincipals).hasSize(1);
assertThat(jwtPrincipals).contains(new JwtPrincipal(getJsonSubject(subjectName)));
}
Aggregations