Search in sources :

Example 1 with SameSite

use of org.springframework.boot.web.server.Cookie.SameSite in project spring-boot by spring-projects.

the class TomcatServletWebServerFactory method configureCookieProcessor.

private void configureCookieProcessor(Context context) {
    SameSite sessionSameSite = getSession().getCookie().getSameSite();
    List<CookieSameSiteSupplier> suppliers = new ArrayList<>();
    if (sessionSameSite != null) {
        suppliers.add(CookieSameSiteSupplier.of(sessionSameSite).whenHasName(() -> SessionConfig.getSessionCookieName(context)));
    }
    if (!CollectionUtils.isEmpty(getCookieSameSiteSuppliers())) {
        suppliers.addAll(getCookieSameSiteSuppliers());
    }
    if (!suppliers.isEmpty()) {
        context.setCookieProcessor(new SuppliedSameSiteCookieProcessor(suppliers));
    }
}
Also used : ArrayList(java.util.ArrayList) SameSite(org.springframework.boot.web.server.Cookie.SameSite) CookieSameSiteSupplier(org.springframework.boot.web.servlet.server.CookieSameSiteSupplier)

Example 2 with SameSite

use of org.springframework.boot.web.server.Cookie.SameSite in project spring-boot by spring-projects.

the class JettyServletWebServerFactory method configureSession.

private void configureSession(WebAppContext context) {
    SessionHandler handler = context.getSessionHandler();
    SameSite sessionSameSite = getSession().getCookie().getSameSite();
    if (sessionSameSite != null) {
        handler.setSameSite(HttpCookie.SameSite.valueOf(sessionSameSite.name()));
    }
    Duration sessionTimeout = getSession().getTimeout();
    handler.setMaxInactiveInterval(isNegative(sessionTimeout) ? -1 : (int) sessionTimeout.getSeconds());
    if (getSession().isPersistent()) {
        DefaultSessionCache cache = new DefaultSessionCache(handler);
        FileSessionDataStore store = new FileSessionDataStore();
        store.setStoreDir(getValidSessionStoreDir());
        cache.setSessionDataStore(store);
        handler.setSessionCache(cache);
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) DefaultSessionCache(org.eclipse.jetty.server.session.DefaultSessionCache) SameSite(org.springframework.boot.web.server.Cookie.SameSite) Duration(java.time.Duration) FileSessionDataStore(org.eclipse.jetty.server.session.FileSessionDataStore)

Example 3 with SameSite

use of org.springframework.boot.web.server.Cookie.SameSite in project spring-boot by spring-projects.

the class UndertowServletWebServerFactory method getCookieHandlerFactory.

private HttpHandlerFactory getCookieHandlerFactory(Deployment deployment) {
    SameSite sessionSameSite = getSession().getCookie().getSameSite();
    List<CookieSameSiteSupplier> suppliers = new ArrayList<>();
    if (sessionSameSite != null) {
        String sessionCookieName = deployment.getServletContext().getSessionCookieConfig().getName();
        suppliers.add(CookieSameSiteSupplier.of(sessionSameSite).whenHasName(sessionCookieName));
    }
    if (!CollectionUtils.isEmpty(getCookieSameSiteSuppliers())) {
        suppliers.addAll(getCookieSameSiteSuppliers());
    }
    return (!suppliers.isEmpty()) ? (next) -> new SuppliedSameSiteCookieHandler(next, suppliers) : null;
}
Also used : ArrayList(java.util.ArrayList) SameSite(org.springframework.boot.web.server.Cookie.SameSite) CookieSameSiteSupplier(org.springframework.boot.web.servlet.server.CookieSameSiteSupplier)

Aggregations

SameSite (org.springframework.boot.web.server.Cookie.SameSite)3 ArrayList (java.util.ArrayList)2 CookieSameSiteSupplier (org.springframework.boot.web.servlet.server.CookieSameSiteSupplier)2 Duration (java.time.Duration)1 DefaultSessionCache (org.eclipse.jetty.server.session.DefaultSessionCache)1 FileSessionDataStore (org.eclipse.jetty.server.session.FileSessionDataStore)1 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)1