@Override public <T, C> Action<T, C> create(Action<T, C> action) { return (exchange, context) -> { UndertowThreadSetupAction.this.action.setup(Collections.emptyMap()); try { return action.call(exchange, context); } finally { UndertowThreadSetupAction.this.action.teardown(Collections.emptyMap()); } }; } }
return null; }).call(null, null); } catch (Exception e) { throw new RuntimeException(e);
}).call(null, null);
}).call(null, null);
return action.call(exchange, context); } finally { if (WildFlySecurityManager.isChecking()) {
return action.call(exchange, context); } finally { if (WildFlySecurityManager.isChecking()) {
}).call(null, null);
}).call(null, null);
return root; }).call(null, null); } catch (ServletException|RuntimeException e) { throw e;
@Override public void undeploy() { try { deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, Object>() { @Override public Void call(HttpServerExchange exchange, Object ignore) throws ServletException { for(ServletContextListener listener : deployment.getDeploymentInfo().getDeploymentCompleteListeners()) { try { listener.contextDestroyed(new ServletContextEvent(deployment.getServletContext())); } catch (Throwable t) { UndertowServletLogger.REQUEST_LOGGER.failedToDestroy(listener, t); } } deployment.destroy(); deployment = null; state = State.UNDEPLOYED; return null; } }).call(null, null); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void sessionDestroyed(final Session session, final HttpServerExchange exchange, final SessionDestroyedReason reason) { if (reason == SessionDestroyedReason.TIMEOUT) { try { //we need to perform thread setup actions destroyedAction.call(exchange, session); } catch (Exception e) { throw new RuntimeException(e); } } else { doDestroy(session); } ServletRequestContext current = SecurityActions.currentServletRequestContext(); Session underlying = null; if (current != null && current.getSession() != null) { if (System.getSecurityManager() == null) { underlying = current.getSession().getSession(); } else { underlying = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(current.getSession())); } } if (current != null && underlying == session) { current.setSession(null); } }
@Override public void stop() throws ServletException { try { deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, Object>() { @Override public Void call(HttpServerExchange exchange, Object ignore) throws ServletException { for (Lifecycle object : deployment.getLifecycleObjects()) { try { object.stop(); } catch (Throwable t) { UndertowServletLogger.ROOT_LOGGER.failedToDestroy(object, t); } } deployment.getSessionManager().stop(); state = State.DEPLOYED; return null; } }).call(null, null); } catch (ServletException|RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public <T, C> Action<T, C> create(final Action<T, C> action) { return (exchange, context) -> { if (exchange == null) { return action.call(exchange, context); } KeycloakSecurityContext c = exchange.getAttachment(OIDCUndertowHttpFacade.KEYCLOAK_SECURITY_CONTEXT_KEY); KeycloakSecurityContextAssociation.associate(c); try { return action.call(exchange, context); } finally { KeycloakSecurityContextAssociation.disassociate(); } }; } }
@Override public T call(HttpServerExchange exchange, C context) throws Exception { if (exchange == null) { return action.call(exchange, context); } KeycloakSecurityContext c = exchange.getAttachment(OIDCUndertowHttpFacade.KEYCLOAK_SECURITY_CONTEXT_KEY); KeycloakSecurityContextAssociation.associate(c); try { return action.call(exchange, context); } finally { KeycloakSecurityContextAssociation.disassociate(); } } };
@Override public T call(HttpServerExchange exchange, C context) throws Exception { if (exchange == null) { return action.call(null, context); } else { ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); final ServletRequestContext old = ServletRequestContext.current(); SecurityActions.setCurrentRequestContext(servletRequestContext); try { return action.call(exchange, context); } finally { ServletRequestContext.setCurrentRequestContext(old); } } } };
void invokeRunnable(HttpServerExchange exchange, Runnable runnable) { final boolean setupRequired = SecurityActions.currentServletRequestContext() == null; if(setupRequired) { try { this.runnableTask.call(exchange, runnable); } catch (Exception e) { throw new RuntimeException(e); } } else { runnable.run(); } } private static final class ReadServletAnnotationsTask implements PrivilegedAction<Void> {
@Override public <T, C> Action<T, C> create(Action<T, C> action) { return (exchange, context) -> { UndertowThreadSetupAction.this.action.setup(Collections.emptyMap()); try { return action.call(exchange, context); } finally { UndertowThreadSetupAction.this.action.teardown(Collections.emptyMap()); } }; } }
void invokeAction(HttpServerExchange exchange, ThreadSetupHandler.Action<Void, Object> listener) { try { this.invokeActionTask.call(exchange, listener); } catch (Exception e) { throw new RuntimeException(e); } }
void invokeOnAllDataRead(HttpServerExchange exchange, ReadListener listener) { try { this.onAllDataReadTask.call(exchange, listener); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public T call(HttpServerExchange exchange, C context) throws Exception { ThreadSetupAction.Handle handle = setupAction.setup(exchange); try { return action.call(exchange, context); } finally { if (handle != null) { handle.tearDown(); } } } };