static boolean isFormAuthentication(HttpServerExchange exchange) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); List<AuthenticationMechanism> mechanisms = src.getDeployment().getAuthenticationMechanisms(); for (AuthenticationMechanism mech : mechanisms) { if (mech instanceof ServletFormAuthenticationMechanism) return true; } return false; } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String old = exchange.getAttachment(OLD_RELATIVE_PATH); if(!old.equals(exchange.getRelativePath())) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletPathMatch info = src.getDeployment().getServletPaths().getServletHandlerByPath(exchange.getRelativePath()); src.setCurrentServlet(info.getServletChain()); src.setServletPathMatch(info); } handler.handleRequest(exchange); } };
SecurityContext securityContext = (SecurityContext) messageInfo.getMap().get(JASPICAuthenticationMechanism.SECURITY_CONTEXT_ATTACHMENT_KEY); ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); List<AuthenticationMechanism> mechanisms = src.getDeployment().getAuthenticationMechanisms();
private Executor asyncExecutor() { Executor executor = servletRequestContext.getDeployment().getAsyncExecutor(); if (executor == null) { executor = servletRequestContext.getDeployment().getExecutor(); } if (executor == null) { executor = exchange.getConnection().getWorker(); } return executor; }
static boolean isFormAuthentication(HttpServerExchange exchange) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); List<AuthenticationMechanism> mechanisms = src.getDeployment().getAuthenticationMechanisms(); for (AuthenticationMechanism mech : mechanisms) { if (mech instanceof ServletFormAuthenticationMechanism) return true; } return false; } }
static boolean isFormAuthentication(HttpServerExchange exchange) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); List<AuthenticationMechanism> mechanisms = src.getDeployment().getAuthenticationMechanisms(); for (AuthenticationMechanism mech : mechanisms) { if (mech instanceof ServletFormAuthenticationMechanism) return true; } return false; } }
@Override protected SessionManager getSessionManager() { ServletRequestContext servletRequestContext = httpServerExchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); return servletRequestContext.getDeployment().getSessionManager(); }
@Override public void saveAccountInfo(OidcKeycloakAccount account) { final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); HttpSession session = getSession(true); session.setAttribute(KeycloakUndertowAccount.class.getName(), account); session.setAttribute(KeycloakSecurityContext.class.getName(), account.getKeycloakSecurityContext()); sessionManagement.login(servletRequestContext.getDeployment().getSessionManager()); }
@Override public void saveAccountInfo(OidcKeycloakAccount account) { final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); HttpSession session = getSession(true); session.setAttribute(KeycloakUndertowAccount.class.getName(), account); session.setAttribute(KeycloakSecurityContext.class.getName(), account.getKeycloakSecurityContext()); sessionManagement.login(servletRequestContext.getDeployment().getSessionManager()); }
private void setupRequestContext(final boolean setupRequired) { if (setupRequired) { servletRequestContext.getDeployment().getApplicationListeners().requestInitialized(servletRequest); SecurityActions.setCurrentRequestContext(servletRequestContext); } }
private void tearDownRequestContext(final boolean setupRequired) { if (setupRequired) { servletRequestContext.getDeployment().getApplicationListeners().requestDestroyed(servletRequest); SecurityActions.clearCurrentServletAttachments(); } }
public boolean resolveResource(int type, String name) { Resource resource; try { resource = servletRequestContext.getDeployment().getDeploymentInfo().getResourceManager().getResource(name); } catch (IOException e) { throw new RuntimeException(e); } switch (type) { case 0: return (resource == null); case 1: return (resource != null); case 2: return (resource != null && resource.getContentLength() > 0); default: return false; } }
@Override public boolean resolve(final HttpServerExchange value) { String location = this.location.readAttribute(value); ServletRequestContext src = value.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if(src == null) { return false; } ResourceManager manager = src.getDeployment().getDeploymentInfo().getResourceManager(); if(manager == null) { return false; } try { Resource resource = manager.getResource(location); if(resource == null) { return false; } return resource.isDirectory(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String old = exchange.getAttachment(OLD_RELATIVE_PATH); if(!old.equals(exchange.getRelativePath())) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletPathMatch info = src.getDeployment().getServletPaths().getServletHandlerByPath(exchange.getRelativePath()); src.setCurrentServlet(info.getServletChain()); src.setServletPathMatch(info); } handler.handleRequest(exchange); } };
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { UndertowHttpFacade facade = new OIDCServletUndertowHttpFacade(exchange); final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); SessionManagementBridge bridge = new SessionManagementBridge(userSessionManagement, servletRequestContext.getDeployment().getSessionManager()); PreAuthActionsHandler handler = new PreAuthActionsHandler(bridge, deploymentContext, facade); if (handler.handleRequest()) return; next.handleRequest(exchange); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { UndertowHttpFacade facade = new OIDCServletUndertowHttpFacade(exchange); final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); SessionManagementBridge bridge = new SessionManagementBridge(userSessionManagement, servletRequestContext.getDeployment().getSessionManager()); PreAuthActionsHandler handler = new PreAuthActionsHandler(bridge, deploymentContext, facade); if (handler.handleRequest()) return; next.handleRequest(exchange); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String old = exchange.getAttachment(OLD_RELATIVE_PATH); if(!old.equals(exchange.getRelativePath())) { ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletPathMatch info = src.getDeployment().getServletPaths().getServletHandlerByPath(exchange.getRelativePath()); src.setCurrentServlet(info.getServletChain()); src.setServletPathMatch(info); } handler.handleRequest(exchange); } };
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); final AuthorizationManager authorizationManager = servletRequestContext.getDeployment().getDeploymentInfo().getAuthorizationManager(); TransportGuaranteeType connectionGuarantee = servletRequestContext.getOriginalRequest().isSecure() ? TransportGuaranteeType.CONFIDENTIAL : TransportGuaranteeType.NONE; TransportGuaranteeType transportGuarantee = authorizationManager.transportGuarantee(connectionGuarantee, servletRequestContext.getTransportGuarenteeType(), servletRequestContext.getOriginalRequest()); servletRequestContext.setTransportGuarenteeType(transportGuarantee); if (TransportGuaranteeType.REJECTED == transportGuarantee) { HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse(); response.sendError(StatusCodes.FORBIDDEN); return; } super.handleRequest(exchange); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletRequest request = servletRequestContext.getServletRequest(); if (request.getDispatcherType() == DispatcherType.REQUEST) { List<SingleConstraintMatch> constraints = servletRequestContext.getRequiredConstrains(); SecurityContext sc = exchange.getSecurityContext(); if (!authorizationManager.canAccessResource(constraints, sc.getAuthenticatedAccount(), servletRequestContext.getCurrentServlet().getManagedServlet().getServletInfo(), servletRequestContext.getOriginalRequest(), servletRequestContext.getDeployment())) { HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse(); response.sendError(StatusCodes.FORBIDDEN); return; } } next.handleRequest(exchange); }
/** * {@inheritDoc} */ public void flush() throws IOException { //according to the servlet spec we ignore a flush from within an include if (servletRequestContext.getOriginalRequest().getDispatcherType() == DispatcherType.INCLUDE || servletRequestContext.getOriginalResponse().isTreatAsCommitted()) { return; } if (servletRequestContext.getDeployment().getDeploymentInfo().isIgnoreFlush() && servletRequestContext.getExchange().isRequestComplete() && servletRequestContext.getOriginalResponse().getHeader(Headers.TRANSFER_ENCODING_STRING) == null) { //we mark the stream as flushed, but don't actually flush //because in most cases flush just kills performance //we only do this if the request is fully read, so that http tunneling scenarios still work servletRequestContext.getOriginalResponse().setIgnoredFlushPerformed(true); return; } flushInternal(); }