Java Code Examples for org.apache.catalina.connector.Request#getPrincipal()
The following examples show how to use
org.apache.catalina.connector.Request#getPrincipal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthenticatorBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void logout(Request request) { AuthConfigProvider provider = getJaspicProvider(); if (provider != null) { MessageInfo messageInfo = new MessageInfoImpl(request, request.getResponse(), true); Subject client = (Subject) request.getNote(Constants.REQ_JASPIC_SUBJECT_NOTE); if (client != null) { ServerAuthContext serverAuthContext; try { ServerAuthConfig serverAuthConfig = provider.getServerAuthConfig("HttpServlet", jaspicAppContextID, CallbackHandlerImpl.getInstance()); String authContextID = serverAuthConfig.getAuthContextID(messageInfo); serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null, null); serverAuthContext.cleanSubject(messageInfo, client); } catch (AuthException e) { log.debug(sm.getString("authenticator.jaspicCleanSubjectFail"), e); } } } Principal p = request.getPrincipal(); if (p instanceof TomcatPrincipal) { try { ((TomcatPrincipal) p).logout(); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.debug(sm.getString("authenticator.tomcatPrincipalLogoutFail"), t); } } register(request, request.getResponse(), null, null, null, null); }
Example 2
Source File: ApplicationPushBuilder.java From Tomcat8-Source-Read with MIT License | 4 votes |
public ApplicationPushBuilder(Request catalinaRequest, HttpServletRequest request) { baseRequest = request; this.catalinaRequest = catalinaRequest; coyoteRequest = catalinaRequest.getCoyoteRequest(); // Populate the initial list of HTTP headers Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); List<String> values = new ArrayList<>(); headers.put(headerName, values); Enumeration<String> headerValues = request.getHeaders(headerName); while (headerValues.hasMoreElements()) { values.add(headerValues.nextElement()); } } // Remove the headers headers.remove("if-match"); headers.remove("if-none-match"); headers.remove("if-modified-since"); headers.remove("if-unmodified-since"); headers.remove("if-range"); headers.remove("range"); headers.remove("expect"); headers.remove("authorization"); headers.remove("referer"); // Also remove the cookie header since it will be regenerated headers.remove("cookie"); // set the referer header StringBuffer referer = request.getRequestURL(); if (request.getQueryString() != null) { referer.append('?'); referer.append(request.getQueryString()); } addHeader("referer", referer.toString()); // Session Context context = catalinaRequest.getContext(); sessionCookieName = SessionConfig.getSessionCookieName(context); sessionPathParameterName = SessionConfig.getSessionUriParamName(context); HttpSession session = request.getSession(false); if (session != null) { sessionId = session.getId(); } if (sessionId == null) { sessionId = request.getRequestedSessionId(); } if (!request.isRequestedSessionIdFromCookie() && !request.isRequestedSessionIdFromURL() && sessionId != null) { Set<SessionTrackingMode> sessionTrackingModes = request.getServletContext().getEffectiveSessionTrackingModes(); addSessionCookie = sessionTrackingModes.contains(SessionTrackingMode.COOKIE); addSessionPathParameter = sessionTrackingModes.contains(SessionTrackingMode.URL); } else { addSessionCookie = request.isRequestedSessionIdFromCookie(); addSessionPathParameter = request.isRequestedSessionIdFromURL(); } // Cookies if (request.getCookies() != null) { for (Cookie requestCookie : request.getCookies()) { cookies.add(requestCookie); } } for (Cookie responseCookie : catalinaRequest.getResponse().getCookies()) { if (responseCookie.getMaxAge() < 0) { // Path information not available so can only remove based on // name. Iterator<Cookie> cookieIterator = cookies.iterator(); while (cookieIterator.hasNext()) { Cookie cookie = cookieIterator.next(); if (cookie.getName().equals(responseCookie.getName())) { cookieIterator.remove(); } } } else { cookies.add(new Cookie(responseCookie.getName(), responseCookie.getValue())); } } List<String> cookieValues = new ArrayList<>(1); cookieValues.add(generateCookieHeader(cookies, catalinaRequest.getContext().getCookieProcessor())); headers.put("cookie", cookieValues); // Authentication if (catalinaRequest.getPrincipal() != null) { if ((session == null) || catalinaRequest.getSessionInternal(false).getPrincipal() == null || !(context.getAuthenticator() instanceof AuthenticatorBase) || !((AuthenticatorBase) context.getAuthenticator()).getCache()) { // Set a username only if there is no session cache for the principal userName = catalinaRequest.getPrincipal().getName(); } setHeader("authorization", "x-push"); } }