【问题标题】:How to make the session cookie secure with Seedstack?如何使用 Seedstack 使会话 cookie 安全?
【发布时间】:2023-04-01 11:17:02
【问题描述】:

我在 SeedStack 应用程序中使用 Web 会话,但需要通过 httpOnly 标志保护会话 cookie。

由于没有配置选项,我如何使用当前版本实现这一点?

【问题讨论】:

  • 感谢您的提问。它已关闭,但我要求重新打开。
  • 它显然已重新打开,如果您对如何执行此操作有任何提示@AdrienLAUER

标签: seedstack


【解决方案1】:

目前无法配置 Undertow 使用的会话 cookie,但我添加了相关选项以使其在即将发布的版本(4 月底的 20.4)中成为可能。

目前,作为一种解决方法,您可以实现 ServletContainerInitializer 来手动配置会话 cookie:

public class MyServletContainerInitializer implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> classes, ServletContext servletContext) {
        servletContext.getSessionCookieConfig().setHttpOnly(true);
    }

您的班级必须在META-INF/services/javax.servlet.ServletContainerInitializer 文件中注册:

org.myorg.myproject.MyServletContainerInitializer

请注意,您可以使用Seed.baseConfiguration() 静态获取配置外观。这使得使用应用配置更改 cookie 选项成为可能。

【讨论】:

    猜你喜欢
    • 2015-06-07
    • 1970-01-01
    • 2023-03-12
    • 2018-10-10
    • 1970-01-01
    • 2013-08-21
    • 2012-09-05
    • 1970-01-01
    • 2021-12-03
    相关资源
    最近更新 更多