Search in sources :

Example 1 with ProcessCors

use of org.webpieces.router.api.routebldr.ProcessCors in project webpieces by deanhiller.

the class EScopedRouter method isFailSecurityCheck.

private boolean isFailSecurityCheck(AbstractRouter router, RequestContext ctx, ProxyStreamHandle handler) {
    if (!(router instanceof FContentRouter)) {
        // we only do CORS for content requests(json/xml/etc)
        send403Response(handler, "Only content routes allow CORS requests. Router not supported=" + router.getClass());
        return true;
    }
    FContentRouter contentRouter = (FContentRouter) router;
    ProcessCors corsProcessor = contentRouter.getCorsProcessor();
    if (corsProcessor == null) {
        send403Response(handler, "This method and path did not support CORS");
        return true;
    }
    AccessResult accessResult = corsProcessor.isAccessAllowed(ctx);
    if (!accessResult.isAllowed()) {
        send403Response(handler, accessResult.getReasonForDenial());
        return true;
    }
    return false;
}
Also used : ProcessCors(org.webpieces.router.api.routebldr.ProcessCors) AccessResult(org.webpieces.router.api.routebldr.AccessResult)

Example 2 with ProcessCors

use of org.webpieces.router.api.routebldr.ProcessCors in project webpieces by deanhiller.

the class EScopedRouter method doCorsProessing.

private void doCorsProessing(RequestContext ctx, ProxyStreamHandle handler, List<FContentRouter> matchingMethods) {
    ProcessCors corsProcessor = matchingMethods.get(0).getCorsProcessor();
    List<HttpMethod> methodsSupported = new ArrayList<>();
    for (FContentRouter r : matchingMethods) {
        HttpMethod httpMethod = r.matchInfo.getHttpMethod();
        methodsSupported.add(httpMethod);
        if (corsProcessor != r.getCorsProcessor()) {
            throw new IllegalStateException("Developer has a mistake in routes file adding different ProcessCors to different methods of same url and port types");
        }
    }
    try {
        corsProcessor.processOptionsCors(ctx.getRequest().originalRequest, methodsSupported, handler);
    } catch (Throwable e) {
        log.error("Customer code for class=" + corsProcessor + " failed", e);
    }
}
Also used : ProcessCors(org.webpieces.router.api.routebldr.ProcessCors) ArrayList(java.util.ArrayList) HttpMethod(org.webpieces.ctx.api.HttpMethod)

Aggregations

ProcessCors (org.webpieces.router.api.routebldr.ProcessCors)2 ArrayList (java.util.ArrayList)1 HttpMethod (org.webpieces.ctx.api.HttpMethod)1 AccessResult (org.webpieces.router.api.routebldr.AccessResult)1