Search in sources :

Example 1 with RequestHandler

use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldConsumeRealmFromCRUDPAQRequestWithSubrealm.

@Test(dataProvider = "CRUDPAQ")
public void filterShouldConsumeRealmFromCRUDPAQRequestWithSubrealm(Request request, String postURIString) throws Exception {
    //Given
    RequestHandler requestHandler = mock(RequestHandler.class);
    String path = SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT;
    Context context = mockContext(path);
    request.setUri(createRequestURI(HOSTNAME, path, postURIString));
    mockDnsAlias(HOSTNAME, "/");
    mockRealmAlias("/" + SUB_REALM, "/" + 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(), "", "/" + SUB_REALM, null);
    verifyUriRouterContext(contextCaptor.getValue(), SUB_REALM);
    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)

Example 2 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 3 with RequestHandler

use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.

the class STSPublishServiceHttpRouteProvider method getHandler.

private Handler getHandler() {
    final RequestHandler restPublishRequestHandler = new RestSTSPublishServiceRequestHandler(STSPublishInjectorHolder.getInstance(Key.get(RestSTSInstancePublisher.class)), STSPublishInjectorHolder.getInstance(Key.get(RestRealmValidator.class)), STSPublishInjectorHolder.getInstance(Key.get(new TypeLiteral<InstanceConfigMarshaller<RestSTSInstanceConfig>>() {
    })), STSPublishInjectorHolder.getInstance(Key.get(Logger.class)));
    rootRouter.route("rest").auditAs(STS).authorizeWith(STSPublishServiceAuthzModule.class).toRequestHandler(STARTS_WITH, restPublishRequestHandler);
    final RequestHandler soapPublishRequestHandler = new SoapSTSPublishServiceRequestHandler(STSPublishInjectorHolder.getInstance(Key.get(SoapSTSInstancePublisher.class)), STSPublishInjectorHolder.getInstance(Key.get(RestRealmValidator.class)), STSPublishInjectorHolder.getInstance(Key.get(new TypeLiteral<InstanceConfigMarshaller<SoapSTSInstanceConfig>>() {
    })), STSPublishInjectorHolder.getInstance(Key.get(Logger.class)));
    rootRouter.route("soap").auditAs(STS).authorizeWith(STSPublishServiceAuthzModule.class).toRequestHandler(STARTS_WITH, soapPublishRequestHandler);
    return Handlers.chainOf(newHttpHandler(rootRouter.getRouter()), authenticationFilter);
}
Also used : RequestHandler(org.forgerock.json.resource.RequestHandler) InstanceConfigMarshaller(org.forgerock.openam.sts.InstanceConfigMarshaller) STSPublishServiceAuthzModule(org.forgerock.openam.rest.authz.STSPublishServiceAuthzModule)

Example 4 with RequestHandler

use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.

the class SmsRouteTreeTest method shouldUseProvidedAuthModuleForMatchingPath.

@Test
public void shouldUseProvidedAuthModuleForMatchingPath() throws Exception {
    //Given
    RequestHandler requestHandler = mock(RequestHandler.class);
    Context context = mock(Context.class);
    ReadRequest request = Requests.newReadRequest("/not-authorized/service");
    Promise<AuthorizationResult, ResourceException> failResult = newResultPromise(accessDenied("no"));
    given(authModule.authorizeRead(any(Context.class), any(ReadRequest.class))).willReturn(failResult);
    //When
    routeTree.handles("NOT_AUTHORIZED").addRoute(RoutingMode.STARTS_WITH, "/service", requestHandler);
    Promise<ResourceResponse, ResourceException> result = routeTree.handleRead(context, request);
    //Then
    assertThat(result).failedWithException();
    verify(authModule).authorizeRead(any(Context.class), any(ReadRequest.class));
    verifyNoMoreInteractions(requestHandler, defaultAuthModule);
}
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 5 with RequestHandler

use of org.forgerock.json.resource.RequestHandler in project OpenAM by OpenRock.

the class SmsRequestHandler method addPaths.

/**
     * Recursively adds routes for the schema paths found in the schema instance.
     *
     * @param parentPath The parent route path to add new routes beneath.
     * @param schemaPath The path for schema that is built up as we navigate through the Schema and SubSchema
     *                   declarations for the service.
     * @param schema The Schema or SubSchema instance for this iteration of the method.
     * @param dynamicSchema The dynamic Schema instance, or {@code null} if no dynamic schema is defined.
     * @param serviceRoutes Routes added for the service are added for later removal if needed.
     * @param ignoredRoutes Any routes to be ignored.
     * @param routeTree The tree to add routes to. If null, the root tree will be used to find the appropriate node.
     * @throws SMSException From downstream service manager layer.
     */
private void addPaths(String parentPath, List<ServiceSchema> schemaPath, ServiceSchema schema, ServiceSchema dynamicSchema, Map<SmsRouteTree, Set<RouteMatcher<Request>>> serviceRoutes, List<Pattern> ignoredRoutes, SmsRouteTree routeTree) throws SMSException {
    String schemaName = schema.getResourceName();
    String path = getPath(parentPath, schemaName, schemaPath, schema);
    if (!schema.getAttributeSchemas().isEmpty() || schema.supportsMultipleConfigurations()) {
        if (schema.supportsMultipleConfigurations() && !excludeCollection(schema.getServiceName())) {
            RequestHandler handler = Resources.newCollection(collectionProviderFactory.create(new SmsJsonConverter(schema), schema, schemaType, new ArrayList<ServiceSchema>(schemaPath), parentPath, true));
            debug.message("Adding collection path {}", path);
            serviceRoutes.putAll(addRoute(schema, STARTS_WITH, path, handler, ignoredRoutes, routeTree));
            parentPath = path + "/{" + schemaName + "}";
        } else if (!excludeSingleton(schema.getServiceName())) {
            RequestHandler handler = singletonProviderFactory.create(new SmsJsonConverter(schema), schema, dynamicSchema, schemaType, new ArrayList<ServiceSchema>(schemaPath), parentPath, true);
            debug.message("Adding singleton path {}", path);
            serviceRoutes.putAll(addRoute(schema, EQUALS, path, handler, ignoredRoutes, routeTree));
            parentPath = path;
        }
    }
    addPaths(parentPath, schemaPath, schema, serviceRoutes, ignoredRoutes, routeTree);
}
Also used : RequestHandler(org.forgerock.json.resource.RequestHandler) ArrayList(java.util.ArrayList)

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