Java Code Examples for io.undertow.servlet.handlers.ServletRequestContext#getCurrentServletContext()

The following examples show how to use io.undertow.servlet.handlers.ServletRequestContext#getCurrentServletContext() . 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: ChangeSessionId.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public static String changeSessionId(HttpServerExchange exchange, boolean create) {
    final ServletRequestContext sc = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    ServletContextImpl currentServletContext = sc.getCurrentServletContext();
    HttpSessionImpl session = currentServletContext.getSession(exchange, create);
    if (session == null) {
        return null;
    }
    Session underlyingSession;
    if(System.getSecurityManager() == null) {
        underlyingSession = session.getSession();
    } else {
        underlyingSession = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(session));
    }


    return underlyingSession.changeSessionId(exchange, currentServletContext.getSessionConfig());
}
 
Example 2
Source File: RequestDispatcherImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private void forwardImplSetup(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
    final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
    if(servletRequestContext == null) {
        UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
        mock(request, response);
        return;
    }

    ThreadSetupAction.Handle handle = null;
    ServletContextImpl oldServletContext = null;
    HttpSessionImpl oldSession = null;
    if (servletRequestContext.getCurrentServletContext() != this.servletContext) {

        try {
            //cross context request, we need to run the thread setup actions
            oldServletContext = servletRequestContext.getCurrentServletContext();
            oldSession = servletRequestContext.getSession();
            servletRequestContext.setSession(null);
            servletRequestContext.setCurrentServletContext(this.servletContext);
            this.servletContext.invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
                @Override
                public Void call(HttpServerExchange exchange, Object context) throws Exception {
                    forwardImpl(request, response, servletRequestContext);
                    return null;
                }
            });

        } finally {
            servletRequestContext.setSession(oldSession);
            servletRequestContext.setCurrentServletContext(oldServletContext);
            // update time in old context and run the requestDone for the session
            servletRequestContext.getCurrentServletContext().updateSessionAccessTime(servletRequestContext.getExchange());
        }
    } else {
        forwardImpl(request, response, servletRequestContext);
    }

}
 
Example 3
Source File: RequestDispatcherImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private void setupIncludeImpl(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
    final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
    if(servletRequestContext == null) {
        UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
        mock(request, response);
        return;
    }
    final HttpServletRequestImpl requestImpl = servletRequestContext.getOriginalRequest();
    final HttpServletResponseImpl responseImpl = servletRequestContext.getOriginalResponse();
    ServletContextImpl oldServletContext = null;
    HttpSessionImpl oldSession = null;
    if (servletRequestContext.getCurrentServletContext() != this.servletContext) {
        //cross context request, we need to run the thread setup actions
        oldServletContext = servletRequestContext.getCurrentServletContext();
        oldSession = servletRequestContext.getSession();
        servletRequestContext.setSession(null);
        servletRequestContext.setCurrentServletContext(this.servletContext);
        try {
            servletRequestContext.getCurrentServletContext().invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
                @Override
                public Void call(HttpServerExchange exchange, Object context) throws Exception {
                    includeImpl(request, response, servletRequestContext, requestImpl, responseImpl);
                    return null;
                }
            });
        } finally {
            // update time in new context and run the requestDone for the session
            servletRequestContext.getCurrentServletContext().updateSessionAccessTime(servletRequestContext.getExchange());
            servletRequestContext.setSession(oldSession);
            servletRequestContext.setCurrentServletContext(oldServletContext);
        }
    } else {
        includeImpl(request, response, servletRequestContext, requestImpl, responseImpl);
    }
}
 
Example 4
Source File: RequestDispatcherImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void forwardImplSetup(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
    final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
    if(servletRequestContext == null) {
        UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
        mock(request, response);
        return;
    }

    ThreadSetupAction.Handle handle = null;
    ServletContextImpl oldServletContext = null;
    HttpSessionImpl oldSession = null;
    if (servletRequestContext.getCurrentServletContext() != this.servletContext) {

        try {
            //cross context request, we need to run the thread setup actions
            oldServletContext = servletRequestContext.getCurrentServletContext();
            oldSession = servletRequestContext.getSession();
            servletRequestContext.setSession(null);
            servletRequestContext.setCurrentServletContext(this.servletContext);
            this.servletContext.invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
                @Override
                public Void call(HttpServerExchange exchange, Object context) throws Exception {
                    forwardImpl(request, response, servletRequestContext);
                    return null;
                }
            });

        } finally {
                servletRequestContext.setSession(oldSession);
                servletRequestContext.setCurrentServletContext(oldServletContext);
        }
    } else {
        forwardImpl(request, response, servletRequestContext);
    }

}
 
Example 5
Source File: RequestDispatcherImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void setupIncludeImpl(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
    final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
    if(servletRequestContext == null) {
        UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
        mock(request, response);
        return;
    }
    final HttpServletRequestImpl requestImpl = servletRequestContext.getOriginalRequest();
    final HttpServletResponseImpl responseImpl = servletRequestContext.getOriginalResponse();
    ServletContextImpl oldServletContext = null;
    HttpSessionImpl oldSession = null;
    if (servletRequestContext.getCurrentServletContext() != this.servletContext) {
        //cross context request, we need to run the thread setup actions
        oldServletContext = servletRequestContext.getCurrentServletContext();
        oldSession = servletRequestContext.getSession();
        servletRequestContext.setSession(null);
        servletRequestContext.setCurrentServletContext(this.servletContext);
        try {
            servletRequestContext.getCurrentServletContext().invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
                @Override
                public Void call(HttpServerExchange exchange, Object context) throws Exception {
                    includeImpl(request, response, servletRequestContext, requestImpl, responseImpl);
                    return null;
                }
            });
        } finally {
            servletRequestContext.setSession(oldSession);
            servletRequestContext.setCurrentServletContext(oldServletContext);
        }
    } else {
        includeImpl(request, response, servletRequestContext, requestImpl, responseImpl);
    }
}