io.undertow.server.session.SessionConfig Java Examples

The following examples show how to use io.undertow.server.session.SessionConfig. 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: CachedAuthenticatedSessionHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    SecurityContext securityContext = exchange.getSecurityContext();
    securityContext.registerNotificationReceiver(NOTIFICATION_RECEIVER);
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        next.handleRequest(exchange);
        return;
    }
    Session session = sessionManager.getSession(exchange, sessionConfig);
    // If there was no existing HttpSession then there could not be a cached AuthenticatedSession so don't bother setting
    // the AuthenticatedSessionManager.
    if (session != null) {
        exchange.putAttachment(AuthenticatedSessionManager.ATTACHMENT_KEY, SESSION_MANAGER);
    }

    next.handleRequest(exchange);
}
 
Example #2
Source File: CachedAuthenticatedSessionHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    SecurityContext securityContext = exchange.getSecurityContext();
    securityContext.registerNotificationReceiver(NOTIFICATION_RECEIVER);
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        next.handleRequest(exchange);
        return;
    }
    Session session = sessionManager.getSession(exchange, sessionConfig);
    // If there was no existing HttpSession then there could not be a cached AuthenticatedSession so don't bother setting
    // the AuthenticatedSessionManager.
    if (session != null) {
        exchange.putAttachment(AuthenticatedSessionManager.ATTACHMENT_KEY, SESSION_MANAGER);
    }

    next.handleRequest(exchange);
}
 
Example #3
Source File: Sessions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static Session getSession(final HttpServerExchange exchange, boolean create) {
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if(sessionManager == null) {
        throw UndertowMessages.MESSAGES.sessionManagerNotFound();
    }
    Session session = sessionManager.getSession(exchange, sessionConfig);
    if(session == null && create) {
        session = sessionManager.createSession(exchange, sessionConfig);
    }
    return session;
}
 
Example #4
Source File: AsyncWebSocketHttpServerExchange.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object getSession() {
    SessionManager sm = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionCookieConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if(sm != null && sessionCookieConfig != null) {
        return sm.getSession(exchange, sessionCookieConfig);
    }
    return null;
}
 
Example #5
Source File: LearningPushHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected Session getSession(HttpServerExchange exchange) {
    SessionConfig sc = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    SessionManager sm = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    if (sc == null || sm == null) {
        return null;
    }
    Session session = sm.getSession(exchange, sc);
    if (session == null) {
        return sm.createSession(exchange, sc);
    }
    return session;
}
 
Example #6
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private SessionConfig.SessionCookieSource sessionCookieSource() {
    HttpSession session = getSession(false);
    if(session == null) {
        return SessionConfig.SessionCookieSource.NONE;
    }
    if(sessionCookieSource == null) {
        sessionCookieSource = originalServletContext.getSessionConfig().sessionCookieSource(exchange);
    }
    return sessionCookieSource;
}
 
Example #7
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getRequestedSessionId() {
    SessionConfig config = originalServletContext.getSessionConfig();
    if(config instanceof ServletContextImpl.ServletContextSessionConfig) {
        return ((ServletContextImpl.ServletContextSessionConfig)config).getDelegate().findSessionId(exchange);
    }
    return config.findSessionId(exchange);
}
 
Example #8
Source File: CachedAuthenticatedSessionHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void clearSession(HttpServerExchange exchange) {
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        return;
    }
    Session httpSession = sessionManager.getSession(exchange, sessionConfig);
    if (httpSession != null) {
        httpSession.removeAttribute(ATTRIBUTE_NAME);
    }
}
 
Example #9
Source File: CachedAuthenticatedSessionHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AuthenticatedSession lookupSession(HttpServerExchange exchange) {

    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        return null;
    }
    Session httpSession = sessionManager.getSession(exchange, sessionConfig);
    if (httpSession != null) {
        return (AuthenticatedSession) httpSession.getAttribute(ATTRIBUTE_NAME);
    }
    return null;
}
 
Example #10
Source File: CachedAuthenticatedSessionHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleNotification(SecurityNotification notification) {
    EventType eventType = notification.getEventType();
    HttpServerExchange exchange = notification.getExchange();
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        return;
    }
    Session httpSession = sessionManager.getSession(exchange, sessionConfig);
    switch (eventType) {
        case AUTHENTICATED:
            if (isCacheable(notification)) {
                if (httpSession == null) {
                    httpSession = sessionManager.createSession(exchange, sessionConfig);
                }

                // It is normal for this notification to be received when using a previously cached session - in that
                // case the IDM would have been given an opportunity to re-load the Account so updating here ready for
                // the next request is desired.
                httpSession.setAttribute(ATTRIBUTE_NAME,
                        new AuthenticatedSession(notification.getAccount(), notification.getMechanism()));
            }
            break;
        case LOGGED_OUT:
            if (httpSession != null) {
                httpSession.removeAttribute(ATTRIBUTE_NAME);
                httpSession.removeAttribute(NO_ID_CHANGE_REQUIRED);
            }
            break;
    }
}
 
Example #11
Source File: Sessions.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private static Session getSession(final HttpServerExchange exchange, boolean create) {
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if(sessionManager == null) {
        throw UndertowMessages.MESSAGES.sessionManagerNotFound();
    }
    Session session = sessionManager.getSession(exchange, sessionConfig);
    if(session == null && create) {
        session = sessionManager.createSession(exchange, sessionConfig);
    }
    return session;
}
 
Example #12
Source File: LearningPushHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
protected Session getSession(HttpServerExchange exchange) {
    SessionConfig sc = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    SessionManager sm = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    if (sc == null || sm == null) {
        return null;
    }
    Session session = sm.getSession(exchange, sc);
    if (session == null) {
        return sm.createSession(exchange, sc);
    }
    return session;
}
 
Example #13
Source File: CachedAuthenticatedSessionHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public void clearSession(HttpServerExchange exchange) {
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        return;
    }
    Session httpSession = sessionManager.getSession(exchange, sessionConfig);
    if (httpSession != null) {
        httpSession.removeAttribute(ATTRIBUTE_NAME);
    }
}
 
Example #14
Source File: CachedAuthenticatedSessionHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public void handleNotification(SecurityNotification notification) {
    EventType eventType = notification.getEventType();
    HttpServerExchange exchange = notification.getExchange();
    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        return;
    }
    Session httpSession = sessionManager.getSession(exchange, sessionConfig);
    switch (eventType) {
        case AUTHENTICATED:
            if (isCacheable(notification)) {
                if (httpSession == null) {
                    httpSession = sessionManager.createSession(exchange, sessionConfig);
                }

                // It is normal for this notification to be received when using a previously cached session - in that
                // case the IDM would have been given an opportunity to re-load the Account so updating here ready for
                // the next request is desired.
                httpSession.setAttribute(ATTRIBUTE_NAME,
                        new AuthenticatedSession(notification.getAccount(), notification.getMechanism()));
            }
            break;
        case LOGGED_OUT:
            if (httpSession != null) {
                httpSession.removeAttribute(ATTRIBUTE_NAME);
                httpSession.removeAttribute(NO_ID_CHANGE_REQUIRED);
            }
            break;
    }
}
 
Example #15
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private SessionConfig.SessionCookieSource sessionCookieSource() {
    HttpSession session = getSession(false);
    if (session == null) {
        return SessionConfig.SessionCookieSource.NONE;
    }
    if (sessionCookieSource == null) {
        sessionCookieSource = originalServletContext.getSessionConfig().sessionCookieSource(exchange);
    }
    return sessionCookieSource;
}
 
Example #16
Source File: CachedAuthenticatedSessionHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public AuthenticatedSession lookupSession(HttpServerExchange exchange) {

    SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
    SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
    if (sessionManager == null || sessionConfig == null) {
        return null;
    }
    Session httpSession = sessionManager.getSession(exchange, sessionConfig);
    if (httpSession != null) {
        return (AuthenticatedSession) httpSession.getAttribute(ATTRIBUTE_NAME);
    }
    return null;
}
 
Example #17
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public String getRequestedSessionId() {
    SessionConfig config = originalServletContext.getSessionConfig();
    if (config instanceof ServletContextImpl.ServletContextSessionConfig) {
        return ((ServletContextImpl.ServletContextSessionConfig) config).getDelegate().findSessionId(exchange);
    }
    return config.findSessionId(exchange);
}
 
Example #18
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public SessionConfig getDelegate() {
    return delegate;
}
 
Example #19
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public SessionConfig getSessionConfig() {
    return sessionConfig;
}
 
Example #20
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
private ServletContextSessionConfig(SessionConfig delegate) {
    this.delegate = delegate;
}
 
Example #21
Source File: SessionCookieConfigImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setFallback(final SessionConfig fallback) {
    this.fallback = fallback;
}
 
Example #22
Source File: SessionCookieConfigImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public SessionConfig getFallback() {
    return fallback;
}
 
Example #23
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public SessionConfig getDelegate() {
    return delegate;
}
 
Example #24
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isRequestedSessionIdFromURL() {
    return sessionCookieSource() == SessionConfig.SessionCookieSource.URL;
}
 
Example #25
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isRequestedSessionIdFromCookie() {
    return sessionCookieSource() == SessionConfig.SessionCookieSource.COOKIE;
}
 
Example #26
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private ServletContextSessionConfig(SessionConfig delegate) {
    this.delegate = delegate;
}
 
Example #27
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public SessionConfig getSessionConfig() {
    return sessionConfig;
}
 
Example #28
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRequestedSessionIdFromCookie() {
    return sessionCookieSource() == SessionConfig.SessionCookieSource.COOKIE;
}
 
Example #29
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRequestedSessionIdFromURL() {
    return sessionCookieSource() == SessionConfig.SessionCookieSource.URL;
}
 
Example #30
Source File: SessionCookieConfigImpl.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public SessionConfig getFallback() {
    return fallback;
}