Search in sources :

Example 6 with RequestHandler

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;
}
Also used : RequestHandler(org.forgerock.json.resource.RequestHandler) AbstractRequestHandler(org.forgerock.json.resource.AbstractRequestHandler)

Example 7 with RequestHandler

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);
}
Also used : Context(org.forgerock.services.context.Context) RequestHandler(org.forgerock.json.resource.RequestHandler) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 8 with RequestHandler

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));
}
Also used : Context(org.forgerock.services.context.Context) RequestHandler(org.forgerock.json.resource.RequestHandler) SmsRouteTree(org.forgerock.openam.core.rest.sms.SmsRouteTree) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 9 with RequestHandler

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);
}
Also used : RootContext(org.forgerock.services.context.RootContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) AttributesContext(org.forgerock.services.context.AttributesContext) RequestHandler(org.forgerock.json.resource.RequestHandler) CreateRequest(org.forgerock.json.resource.CreateRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) DeleteRequest(org.forgerock.json.resource.DeleteRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) PatchRequest(org.forgerock.json.resource.PatchRequest) Request(org.forgerock.http.protocol.Request) QueryRequest(org.forgerock.json.resource.QueryRequest) RequestHandler(org.forgerock.json.resource.RequestHandler) QueryResponseHandler(org.forgerock.openam.rest.query.QueryResponseHandler) Handler(org.forgerock.http.Handler) Test(org.testng.annotations.Test)

Example 10 with RequestHandler

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);
}
Also used : RootContext(org.forgerock.services.context.RootContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) AttributesContext(org.forgerock.services.context.AttributesContext) RequestHandler(org.forgerock.json.resource.RequestHandler) CreateRequest(org.forgerock.json.resource.CreateRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) DeleteRequest(org.forgerock.json.resource.DeleteRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) PatchRequest(org.forgerock.json.resource.PatchRequest) Request(org.forgerock.http.protocol.Request) QueryRequest(org.forgerock.json.resource.QueryRequest) RequestHandler(org.forgerock.json.resource.RequestHandler) QueryResponseHandler(org.forgerock.openam.rest.query.QueryResponseHandler) Handler(org.forgerock.http.Handler) Test(org.testng.annotations.Test)

Aggregations

RequestHandler (org.forgerock.json.resource.RequestHandler)11 ReadRequest (org.forgerock.json.resource.ReadRequest)8 Context (org.forgerock.services.context.Context)8 Test (org.testng.annotations.Test)6 ActionRequest (org.forgerock.json.resource.ActionRequest)5 CreateRequest (org.forgerock.json.resource.CreateRequest)5 DeleteRequest (org.forgerock.json.resource.DeleteRequest)5 PatchRequest (org.forgerock.json.resource.PatchRequest)5 QueryRequest (org.forgerock.json.resource.QueryRequest)5 UpdateRequest (org.forgerock.json.resource.UpdateRequest)5 RootContext (org.forgerock.services.context.RootContext)4 AuthorizationResult (org.forgerock.authz.filter.api.AuthorizationResult)3 Handler (org.forgerock.http.Handler)3 Request (org.forgerock.http.protocol.Request)3 UriRouterContext (org.forgerock.http.routing.UriRouterContext)3 ResourceException (org.forgerock.json.resource.ResourceException)3 QueryResponseHandler (org.forgerock.openam.rest.query.QueryResponseHandler)3 AttributesContext (org.forgerock.services.context.AttributesContext)3 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)2 ResourceResponse (org.forgerock.json.resource.ResourceResponse)2