Java Code Examples for org.apache.catalina.Context#getAuthenticator()

The following examples show how to use org.apache.catalina.Context#getAuthenticator() . 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: SingleSignOnListener.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void sessionEvent(SessionEvent event) {
    if (!Session.SESSION_DESTROYED_EVENT.equals(event.getType())) {
        return;
    }

    Session session = event.getSession();
    Manager manager = session.getManager();
    if (manager == null) {
        return;
    }
    Context context = manager.getContext();
    Authenticator authenticator = context.getAuthenticator();
    if (!(authenticator instanceof AuthenticatorBase)) {
        return;
    }
    SingleSignOn sso = ((AuthenticatorBase) authenticator).sso;
    if (sso == null) {
        return;
    }
    sso.sessionDestroyed(ssoId, session);
}
 
Example 2
Source File: SingleSignOnListener.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void sessionEvent(SessionEvent event) {
    if (!Session.SESSION_DESTROYED_EVENT.equals(event.getType())) {
        return;
    }

    Session session = event.getSession();
    Manager manager = session.getManager();
    if (manager == null) {
        return;
    }
    Context context = (Context) manager.getContainer();
    if (context == null) {
        return;
    }
    Authenticator authenticator = context.getAuthenticator();
    if (!(authenticator instanceof AuthenticatorBase)) {
        return;
    }
    SingleSignOn sso = ((AuthenticatorBase) authenticator).sso;
    if (sso == null) {
        return;
    }
    sso.sessionDestroyed(ssoId, session);
}
 
Example 3
Source File: SingleSignOnListener.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void sessionEvent(SessionEvent event) {
    if (!Session.SESSION_DESTROYED_EVENT.equals(event.getType())) {
        return;
    }

    Session session = event.getSession();
    Manager manager = session.getManager();
    if (manager == null) {
        return;
    }
    Context context = (Context) manager.getContainer();
    Authenticator authenticator = context.getAuthenticator();
    if (!(authenticator instanceof AuthenticatorBase)) {
        return;
    }
    SingleSignOn sso = ((AuthenticatorBase) authenticator).sso;
    if (sso == null) {
        return;
    }
    sso.sessionDestroyed(ssoId, session);
}
 
Example 4
Source File: ApplicationPushBuilder.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
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");
        }
    }