use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.
the class SelfServiceRequestHandler method getService.
private RequestHandler getService(Context context) throws NotSupportedException {
String realm = RealmContext.getRealm(context);
RequestHandler service = serviceCache.get(realm);
if (service == null) {
synchronized (serviceCache) {
service = serviceCache.get(realm);
if (service == null) {
service = createNewService(context, realm);
serviceCache.put(realm, service);
}
}
}
return service;
}
use of org.forgerock.json.resource.RequestHandler 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.RequestHandler 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.RequestHandler in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromCRUDPAQRequestWithInvalidSubrealm.
@Test(dataProvider = "CRUDPAQ")
public void filterShouldConsumeRealmFromCRUDPAQRequestWithInvalidSubrealm(Request request, String postURIString) throws Exception {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
String path = INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT;
Context context = mockContext(path);
request.setUri(createRequestURI(HOSTNAME, path, postURIString));
mockDnsAlias(HOSTNAME, "/");
mockInvalidRealmAlias(INVALID_SUB_REALM);
//When
Handler httpHandler = getHttpHandler(requestHandler);
httpHandler.handle(context, request).getOrThrowUninterruptibly();
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
ArgumentCaptor<org.forgerock.json.resource.Request> requestCaptor = ArgumentCaptor.forClass(org.forgerock.json.resource.Request.class);
collectCRUDPAQArguments(requestHandler, contextCaptor, requestCaptor);
verifyRealmContext(contextCaptor.getValue(), "", "/", null);
verifyUriRouterContextForInvalidRealm(contextCaptor.getValue());
verifyResolvedResourcePath(requestCaptor.getValue(), INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
}
use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromCRUDPAQRequest.
@Test(dataProvider = "CRUDPAQ")
public void filterShouldConsumeRealmFromCRUDPAQRequest(Request request, String postURIString) throws Exception {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
String path = ENDPOINT_PATH_ELEMENT;
Context context = mockContext(path);
request.setUri(createRequestURI(HOSTNAME, path, postURIString));
mockDnsAlias(HOSTNAME, "/");
//When
Handler httpHandler = getHttpHandler(requestHandler);
httpHandler.handle(context, request).getOrThrowUninterruptibly();
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
ArgumentCaptor<org.forgerock.json.resource.Request> requestCaptor = ArgumentCaptor.forClass(org.forgerock.json.resource.Request.class);
collectCRUDPAQArguments(requestHandler, contextCaptor, requestCaptor);
verifyRealmContext(contextCaptor.getValue(), "", "/", null);
verifyUriRouterContext(contextCaptor.getValue(), "");
verifyResolvedResourcePath(requestCaptor.getValue(), ENDPOINT_PATH_ELEMENT);
}
Aggregations