/** * Returns a new predicate handler, that will delegate to one of the two provided handlers based on the value of the * provided predicate. * * @param predicate The predicate * @param trueHandler The handler that will be executed if the predicate is true * @param falseHandler The handler that will be exected if the predicate is false * @return A new predicate handler * @see Predicate * @see io.undertow.predicate.Predicates */ public static PredicateHandler predicate(final Predicate predicate, final HttpHandler trueHandler, final HttpHandler falseHandler) { return new PredicateHandler(predicate, trueHandler, falseHandler); }
@Override public HttpHandler wrap(final HttpHandler handler) { //we only run this on REQUEST or ASYNC invocations return new PredicateHandler(Predicates.or(DispatcherTypePredicate.REQUEST, DispatcherTypePredicate.ASYNC), new SecurityContextAssociationHandler(runAsIdentityMetaDataMap, handler), handler); } };
@Override public HttpHandler wrap(final HttpHandler handler) { //we only run this on REQUEST or ASYNC invocations return new PredicateHandler(Predicates.or(DispatcherTypePredicate.REQUEST, DispatcherTypePredicate.ASYNC), new JACCContextIdHandler(contextId, handler), handler); } };
@Override public HttpHandler createHttpHandler(Predicate predicate, final HttpHandler next) { //this is a bit of a hack at the moment. Basically we only want to create a single mod_cluster instance //not matter how many filter refs use it, also mod_cluster at this point has no way //to specify the next handler. To get around this we invoke the mod_proxy handler //and then if it has not dispatched or handled the request then we know that we can //just pass it on to the next handler final HttpHandler proxyHandler = modCluster.createProxyHandler(next); final HttpHandler realNext = new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { proxyHandler.handleRequest(exchange); if(!exchange.isDispatched() && !exchange.isComplete()) { exchange.setStatusCode(200); next.handleRequest(exchange); } } }; final HttpHandler mcmp = managementAccessPredicate != null ? Handlers.predicate(managementAccessPredicate, config.create(modCluster, realNext), next) : config.create(modCluster, realNext); UndertowLogger.ROOT_LOGGER.debug("HttpHandler for mod_cluster MCMP created."); if (predicate != null) { return new PredicateHandler(predicate, mcmp, next); } else { return mcmp; } }
/** * Returns a new predicate handler, that will delegate to one of the two provided handlers based on the value of the * provided predicate. * * @param predicate The predicate * @param trueHandler The handler that will be executed if the predicate is true * @param falseHandler The handler that will be exected if the predicate is false * @return A new predicate handler * @see Predicate * @see io.undertow.predicate.Predicates */ public static PredicateHandler predicate(final Predicate predicate, final HttpHandler trueHandler, final HttpHandler falseHandler) { return new PredicateHandler(predicate, trueHandler, falseHandler); }
/** * Returns a new predicate handler, that will delegate to one of the two provided handlers based on the value of the * provided predicate. * * @param predicate The predicate * @param trueHandler The handler that will be executed if the predicate is true * @param falseHandler The handler that will be exected if the predicate is false * @return A new predicate handler * @see Predicate * @see io.undertow.predicate.Predicates */ public static PredicateHandler predicate(final Predicate predicate, final HttpHandler trueHandler, final HttpHandler falseHandler) { return new PredicateHandler(predicate, trueHandler, falseHandler); }
@Override public HttpHandler wrap(final HttpHandler handler) { //we only run this on REQUEST or ASYNC invocations return new PredicateHandler(Predicates.or(DispatcherTypePredicate.REQUEST, DispatcherTypePredicate.ASYNC), new SecurityContextAssociationHandler(runAsIdentityMetaDataMap, handler), handler); } };
@Override public HttpHandler wrap(final HttpHandler handler) { //we only run this on REQUEST or ASYNC invocations return new PredicateHandler(Predicates.or(DispatcherTypePredicate.REQUEST, DispatcherTypePredicate.ASYNC), new JACCContextIdHandler(contextId, handler), handler); } };
@Override public HttpHandler wrap(final HttpHandler handler) { //we only run this on REQUEST or ASYNC invocations return new PredicateHandler(Predicates.or(DispatcherTypePredicate.REQUEST, DispatcherTypePredicate.ASYNC), new JACCContextIdHandler(contextId, handler), handler); } };
@Override public HttpHandler wrap(final HttpHandler handler) { //we only run this on REQUEST or ASYNC invocations return new PredicateHandler(Predicates.or(DispatcherTypePredicate.REQUEST, DispatcherTypePredicate.ASYNC), new SecurityContextAssociationHandler(runAsIdentityMetaDataMap, handler), handler); } };
.setDirectoryListingEnabled(false); return new PredicateHandler(new Predicate() { @Override public boolean resolve(HttpServerExchange value) {
@Override public HttpHandler createHttpHandler(Predicate predicate, final HttpHandler next) { //this is a bit of a hack at the moment. Basically we only want to create a single mod_cluster instance //not matter how many filter refs use it, also mod_cluster at this point has no way //to specify the next handler. To get around this we invoke the mod_proxy handler //and then if it has not dispatched or handled the request then we know that we can //just pass it on to the next handler final HttpHandler proxyHandler = modCluster.createProxyHandler(next); final HttpHandler realNext = new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { proxyHandler.handleRequest(exchange); if(!exchange.isDispatched() && !exchange.isComplete()) { exchange.setStatusCode(200); next.handleRequest(exchange); } } }; final HttpHandler mcmp = managementAccessPredicate != null ? Handlers.predicate(managementAccessPredicate, config.create(modCluster, realNext), next) : config.create(modCluster, realNext); UndertowLogger.ROOT_LOGGER.debug("HttpHandler for mod_cluster MCMP created."); if (predicate != null) { return new PredicateHandler(predicate, mcmp, next); } else { return mcmp; } }
@Override public HttpHandler createHttpHandler(Predicate predicate, final HttpHandler next) { //this is a bit of a hack at the moment. Basically we only want to create a single mod_cluster instance //not matter how many filter refs use it, also mod_cluster at this point has no way //to specify the next handler. To get around this we invoke the mod_proxy handler //and then if it has not dispatched or handled the request then we know that we can //just pass it on to the next handler final HttpHandler proxyHandler = modCluster.createProxyHandler(next); final HttpHandler realNext = new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { proxyHandler.handleRequest(exchange); if(!exchange.isDispatched() && !exchange.isComplete()) { exchange.setStatusCode(200); next.handleRequest(exchange); } } }; final HttpHandler mcmp = managementAccessPredicate != null ? Handlers.predicate(managementAccessPredicate, config.create(modCluster, realNext), next) : config.create(modCluster, realNext); UndertowLogger.ROOT_LOGGER.debug("HttpHandler for mod_cluster MCMP created."); if (predicate != null) { return new PredicateHandler(predicate, mcmp, next); } else { return mcmp; } }
handler = new PredicateHandler(exchange -> { if (!monitor.getSecurityRealm().isPresent()) { return false;
handler = new PredicateHandler(exchange -> { if (!monitor.getSecurityRealm().isPresent()) { return false;
public static HttpHandler createErrorContext(final String slot) throws ModuleLoadException { final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), ""); final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource) .setAllowed(not(path("META-INF"))) .setDirectoryListingEnabled(false) .setCachable(Predicates.<HttpServerExchange>falsePredicate()); //we also need to setup the default resource redirect return new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(ERROR_CONTEXT + DEFAULT_RESOURCE)), handler); }
static ResourceHandlerDefinition createConsoleHandler(String slot, String resource) throws ModuleLoadException { final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), ""); final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource) .setAllowed(not(path("META-INF"))) .setResourceManager(cpresource) .setDirectoryListingEnabled(false) .setCachable(Predicates.<HttpServerExchange>falsePredicate()); //we also need to setup the default resource redirect PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(CONTEXT + resource)), handler); return new ResourceHandlerDefinition(CONTEXT, resource, predicateHandler); }
static ResourceHandlerDefinition createStaticContentHandler(ResourceManager resource, String context) { final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(resource) .setCacheTime(60 * 60 * 24 * 31) .setAllowed(not(path("META-INF"))) .setResourceManager(resource) .setDirectoryListingEnabled(false) .setCachable(not(suffixes(NOCACHE_JS, APP_HTML, INDEX_HTML))); // avoid clickjacking attacks: console must not be included in (i)frames SetHeaderHandler frameHandler = new SetHeaderHandler(handler, "X-Frame-Options", "SAMEORIGIN"); // we also need to setup the default resource redirect PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(context + DEFAULT_RESOURCE)), frameHandler); return new ResourceHandlerDefinition(context, DEFAULT_RESOURCE, predicateHandler); }
wrappedHandlers = wrapHandlers(wrappedHandlers, deploymentInfo.getInnerHandlerChainWrappers()); HttpHandler securityHandler = setupSecurityHandlers(wrappedHandlers); wrappedHandlers = new PredicateHandler(DispatcherTypePredicate.REQUEST, securityHandler, wrappedHandlers); wrappedHandlers = new PredicateHandler(DispatcherTypePredicate.REQUEST, outerHandlers, wrappedHandlers); wrappedHandlers = handleDevelopmentModePersistentSessions(wrappedHandlers, deploymentInfo, deployment.getSessionManager(), servletContext);
wrappedHandlers = wrapHandlers(wrappedHandlers, deploymentInfo.getInnerHandlerChainWrappers()); HttpHandler securityHandler = setupSecurityHandlers(wrappedHandlers); wrappedHandlers = new PredicateHandler(DispatcherTypePredicate.REQUEST, securityHandler, wrappedHandlers); wrappedHandlers = new PredicateHandler(DispatcherTypePredicate.REQUEST, outerHandlers, wrappedHandlers); wrappedHandlers = handleDevelopmentModePersistentSessions(wrappedHandlers, deploymentInfo, deployment.getSessionManager(), servletContext);