use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method testSuccessfulJsonificationAndReadAndSubjectNamePropertyRemoved.
@Test
public void testSuccessfulJsonificationAndReadAndSubjectNamePropertyRemoved() throws Exception {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, TEST_CONDITION_WITH_NAME, mockRequest);
//then
assertThat(promise).succeeded().withContent().hasString("title");
assertThat(promise).succeeded().withContent().stringAt("title").isEqualTo(TEST_CONDITION_WITH_NAME);
assertThat(promise).succeeded().withContent().hasBoolean("logical");
assertThat(promise).succeeded().withContent().booleanAt("logical").isFalse();
assertThat(promise.get().getContent().get("config").getObject().toString()).isEqualTo("{\"type\":\"object\",\"properties\":{}}");
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class SmsRouteTreeTest method shouldUseOtherAuthModuleForMatchingPath.
@Test
public void shouldUseOtherAuthModuleForMatchingPath() throws Exception {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
given(requestHandler.handleRead(any(Context.class), any(ReadRequest.class))).willReturn(newResourceResponse("id", "1", json(object())).asPromise());
Promise<AuthorizationResult, ResourceException> successResult = newResultPromise(accessPermitted());
given(defaultAuthModule.authorizeRead(any(Context.class), any(ReadRequest.class))).willReturn(successResult);
Context context = mock(Context.class);
ReadRequest request = Requests.newReadRequest("/service");
//When
routeTree.handles("OTHERSERVICE").addRoute(RoutingMode.STARTS_WITH, "/service", requestHandler);
Promise<ResourceResponse, ResourceException> result = routeTree.handleRead(context, request);
//Then
assertThat(result).succeeded();
verify(defaultAuthModule).authorizeRead(any(Context.class), any(ReadRequest.class));
verifyNoMoreInteractions(authModule);
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class SmsRouteTreeTest method shouldHandleAddingRoutes.
@Test(dataProvider = "handleRoutes")
public void shouldHandleAddingRoutes(String serviceName, String resourcePath) {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
Context context = mock(Context.class);
ReadRequest request = Requests.newReadRequest(resourcePath + "/handler");
Promise<AuthorizationResult, ResourceException> successResult = newResultPromise(accessPermitted());
given(defaultAuthModule.authorizeRead(any(Context.class), any(ReadRequest.class))).willReturn(successResult);
//When
SmsRouteTree handlerTree = routeTree.handles(serviceName);
handlerTree.addRoute(RoutingMode.STARTS_WITH, "/handler", requestHandler);
routeTree.handleRead(context, request);
//Then
verify(requestHandler).handleRead(any(Context.class), any(ReadRequest.class));
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class RealmContextFilter method filterRead.
@Override
public Promise<ResourceResponse, ResourceException> filterRead(Context context, ReadRequest request, RequestHandler next) {
try {
Context newContext = evaluate(context, request);
ReadRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfReadRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
return next.handleRead(newContext, evaluatedRequest);
} catch (ResourceException e) {
return newExceptionPromise(e);
}
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestReadIsAllowed.
@Test
public void crestReadIsAllowed() throws SSOException, DelegationException {
// Given...
final Set<String> actions = new HashSet<>(Arrays.asList("READ"));
final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "read", actions, EXTENSIONS, DUMB_FUNC);
given(factory.newInstance("/abc", "rest", "1.0", "policies", "read", actions, EXTENSIONS)).willReturn(permission);
given(subjectContext.getCallerSSOToken()).willReturn(token);
given(evaluator.isAllowed(token, permission, ENVIRONMENT)).willReturn(true);
JsonValue jsonValue = json(object(field("someKey", "someValue")));
Promise<ResourceResponse, ResourceException> promise = Promises.newResultPromise(Responses.newResourceResponse("1", "1.0", jsonValue));
given(provider.readInstance(isA(Context.class), eq("123"), isA(ReadRequest.class))).willReturn(promise);
// When...
final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
final Router router = new Router();
router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
final RealmContext context = new RealmContext(subjectContext);
final ReadRequest request = Requests.newReadRequest("/policies/123");
context.setSubRealm("abc", "abc");
Promise<ResourceResponse, ResourceException> result = router.handleRead(context, request);
// Then...
assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
Aggregations