public static ServletRequest getActiveRequest() { ServletRequestContext current; if(System.getSecurityManager() == null) { current = ServletRequestContext.current(); } else { current = AccessController.doPrivileged(CURRENT_CONTEXT); } if(current == null) { return null; } return current.getServletRequest(); } }
static String buildApplicationIdentifier(final ServletRequestContext attachment) { ServletRequest servletRequest = attachment.getServletRequest(); return servletRequest.getServletContext().getVirtualServerName() + " " + servletRequest.getServletContext().getContextPath(); }
/** * <p> * Builds the JASPIC application context. * </p> * * @return a {@code String} representing the application context. */ private String buildAppContext() { final ServletRequestContext requestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletRequest servletRequest = requestContext.getServletRequest(); return servletRequest.getServletContext().getVirtualServerName() + " " + servletRequest.getServletContext().getContextPath(); }
private GenericMessageInfo createMessageInfo(final HttpServerExchange exchange, final SecurityContext securityContext) { ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); GenericMessageInfo messageInfo = new GenericMessageInfo(); messageInfo.setRequestMessage(servletRequestContext.getServletRequest()); messageInfo.setResponseMessage(servletRequestContext.getServletResponse()); messageInfo.getMap().put("javax.security.auth.message.MessagePolicy.isMandatory", isMandatory(servletRequestContext).toString()); // additional context data, useful to provide access to Undertow resources during the modules processing messageInfo.getMap().put(SECURITY_CONTEXT_ATTACHMENT_KEY, securityContext); messageInfo.getMap().put(HTTP_SERVER_EXCHANGE_ATTACHMENT_KEY, exchange); return messageInfo; }
@Override public void handleNotification(SecurityNotification notification) { EventType event = notification.getEventType(); if (event == EventType.AUTHENTICATED || event == EventType.FAILED_AUTHENTICATION) { AuditEvent auditEvent = new AuditEvent(event == EventType.AUTHENTICATED ? AuditLevel.SUCCESS : AuditLevel.FAILURE); Map<String, Object> ctxMap = new HashMap<String, Object>(); Account account = notification.getAccount(); if (account != null) { ctxMap.put("principal", account.getPrincipal().getName()); } ctxMap.put("message", notification.getMessage()); ServletRequestContext src = notification.getExchange().getAttachment(ServletRequestContext.ATTACHMENT_KEY); if(src != null) { ServletRequest hsr = src.getServletRequest(); if (hsr instanceof HttpServletRequest) { ctxMap.put("request", deriveUsefulInfo((HttpServletRequest) hsr)); } } ctxMap.put("Source", getClass().getCanonicalName()); auditEvent.setContextMap(ctxMap); auditManager.audit(auditEvent); } }
/** * <p> * Builds the {@code MessageInfo} instance for the {@code cleanSubject()} call. * </p> * * @return the constructed {@code MessageInfo} object. */ private MessageInfo buildMessageInfo() { ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); GenericMessageInfo messageInfo = new GenericMessageInfo(); messageInfo.setRequestMessage(servletRequestContext.getServletRequest()); messageInfo.setResponseMessage(servletRequestContext.getServletResponse()); // when calling cleanSubject, isMandatory must be set to true. messageInfo.getMap().put("javax.security.auth.message.MessagePolicy.isMandatory", "true"); return messageInfo; }
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if(src != null) { src.getServletRequest().setAttribute(ORG_WILDFLY_SUSPENDED, "true");
protected HttpSession getSession(boolean create) { final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); HttpServletRequest req = (HttpServletRequest) servletRequestContext.getServletRequest(); return req.getSession(create); }
protected HttpSession getSession(boolean create) { final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); HttpServletRequest req = (HttpServletRequest) servletRequestContext.getServletRequest(); return req.getSession(create); } }
/** * Extracts the HTTP servlet request from the HTTP server exchange. * * @param exchange the HTTP server exchange. * @return the HTTP servlet request. */ private static HttpServletRequest extractHttpServletRequest(HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); return (HttpServletRequest) context.getServletRequest(); }
@Override public String readAttribute(final HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if (context != null) { Object result = context.getServletRequest().getParameter(attributeName); if (result != null) { return result.toString(); } } return null; }
@Override public String readAttribute(final HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if (context != null) { ServletRequest req = context.getServletRequest(); if (req instanceof HttpServletRequest) { return ((HttpServletRequest) req).getRequestedSessionId(); } } return null; }
@Override public String readAttribute(final HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if (context != null) { ServletRequest req = context.getServletRequest(); if (req instanceof HttpServletRequest) { return Boolean.toString(((HttpServletRequest) req).isRequestedSessionIdFromCookie()); } } return null; }
@Override public String readAttribute(final HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if (context != null) { ServletRequest req = context.getServletRequest(); return req.getLocale().toString(); } return null; }
@Override public String readAttribute(final HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if (context != null) { ServletRequest req = context.getServletRequest(); if (req instanceof HttpServletRequest) { return Boolean.toString(((HttpServletRequest) req).isRequestedSessionIdValid()); } } return null; }
@Override public String readAttribute(final HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); if (context != null) { ServletRequest req = context.getServletRequest(); return req.getCharacterEncoding(); } return null; }
@Override protected void propagateKeycloakContext(KeycloakUndertowAccount account) { super.propagateKeycloakContext(account); final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); HttpServletRequest req = (HttpServletRequest) servletRequestContext.getServletRequest(); req.setAttribute(KeycloakSecurityContext.class.getName(), account.getKeycloakSecurityContext()); }
public ServletHttpFacade(HttpServerExchange exchange) { super(exchange); final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); request = (HttpServletRequest)servletRequestContext.getServletRequest(); response = (HttpServletResponse)servletRequestContext.getServletResponse(); }
/** * <p> * Builds the JASPIC application context. * </p> * * @return a {@code String} representing the application context. */ private String buildAppContext() { final ServletRequestContext requestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletRequest servletRequest = requestContext.getServletRequest(); return servletRequest.getServletContext().getVirtualServerName() + " " + servletRequest.getServletContext().getContextPath(); }
@Override public AsyncContext startAsync() throws IllegalStateException { if (!isAsyncSupported()) { throw UndertowServletMessages.MESSAGES.startAsyncNotAllowed(); } else if (asyncStarted) { throw UndertowServletMessages.MESSAGES.asyncAlreadyStarted(); } asyncStarted = true; final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); return asyncContext = new AsyncContextImpl(exchange, servletRequestContext.getServletRequest(), servletRequestContext.getServletResponse(), servletRequestContext, false, asyncContext); }