注册新的 undertow SessionManager

2024-01-10

我正在运行 Wildfly 8.1 服务器。我有自己的 SessionManager 实现 io.undertow.server.session.SessionManager。我想配置系统以使用我的会话管理器。

我应该在哪里以及如何为我的会话管理器配置/添加新设置?


public class StartupBeanExtension implements Extension, ServletExtension {
    @Override
    public void handleDeployment(DeploymentInfo deployment, ServletContext context) {
        boolean sessionPersistenceEnabled = Boolean.parseBoolean(BeanUtils.getBean(PropertyResolver.class).getValue("UAM.SessionPersistenceEnabled"));
        if (sessionPersistenceEnabled) {
            System.out.println("Overriding default InMemorySessionManager...[" + deployment.getDeploymentName() + ", " + deployment.getDisplayName() + "]");
            deployment.setSessionManagerFactory(new UAMSessionManagerFactory());
        } else {
            System.out.println("InMemorySessionManager IS NOT OVERIDED!");
        }
    }    
}

public class UAMSessionManagerFactory implements SessionManagerFactory {
    @Override
    public SessionManager createSessionManager(Deployment deployment) {
        UAMSessionManager ss = new UAMSessionManager(deployment.getDeploymentInfo().getDeploymentName());
        return ss;
    }
}

public class UAMSessionManager extends InMemorySessionManager {

    public UAMSessionManager(String deploymentName) {
        super(deploymentName);

        UAMSessionListener uamSessionListener = new UAMSessionListener();
        super.registerSessionListener(uamSessionListener);

        System.out.println("New session manager created. Listener activated.");
    }

    // create session
    public Session createSession(final HttpServerExchange serverExchange, final SessionConfig config, String sessionID) {
        config.setSessionId(serverExchange, sessionID);
        Session session = super.createSession(serverExchange, config);
        return session;
    }

    // get session
    public Session getSession(final HttpServerExchange serverExchange, final SessionConfig config) {
        final String sessionId = config.findSessionId(serverExchange);
        Session session = getSession(sessionId);

        if (session == null) {
            // DO SOMETHING TO CREATE SESSION OR RESTORE IT FROM DB
            try {
                UAMService uam = getUAMService();
                if (uam != null) {
                    Sessions storedSession = uam.getSession(sessionId);

                    if (storedSession != null) {
                        String storedSessionId = storedSession.getSessionId();
                        // create new session with storedSessionID
                        session = createSession(serverExchange, config, storedSessionId);

                        // SET session attributes if needed from storedSession to new one

                    } else {
                        // let InMemorySessionManager create new session
                        return null;
                    }
                }
            } catch (Exception ex) {

            }
        }

        return session;
    }
}

public class UAMSessionListener implements SessionListener {

    @Override
    public void sessionCreated(Session session, HttpServerExchange exchange) {

    }

    @Override
    public void sessionDestroyed(Session session, HttpServerExchange exchange, SessionDestroyedReason reason) {

    }

    @Override
    public void attributeAdded(Session session, String name, Object value) {
        UAMService uamService = getUAMService();

        if (uamService != null) {
            Sessions storedSession = uamService.getSession(session.getId());
            boolean isNew = false;
            if (storedSession == null) {
                storedSession = new Sessions();
                storedSession.setSessionId(session.getId());
                storedSession.setActvityDate(new Date());
                isNew = true;
            }

            // STORE SOME INFO FROM value and update/create it in storage
            uamService.updateSession(storedSession, isNew);
        }
    }

    @Override
    public void attributeUpdated(Session session, String name, Object newValue, Object oldValue) {

    }

    @Override
    public void attributeRemoved(Session session, String name, Object oldValue) {

    }

    @Override
    public void sessionIdChanged(Session session, String oldSessionId) {

    }
}

要使用另一个 SessionManager 覆盖默认的 InMemmorySessionManager,应执行以下步骤:

  1. 开发实现 io.undertow.server.session.SessionManager 的 SessionManager
  2. 开发实现 io.undertow.servlet.api.SessionManagerFactory 的 SessionManagerFactory
  3. 开发实现io.undertow.servlet.ServletExtension的启动扩展,并在handleDeployment(Deployment)方法中用新的SessionManagerFactory更改sessionManagerFactory。
  4. 通过添加 ../META-INF/services/io.undertow.servlet.ServletExtension 文件注册新的 ServletExtension(文件应包含新 ServletExtension 的名称。例如 com.my.utils.StartupExtension)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

注册新的 undertow SessionManager 的相关文章

随机推荐

  • 列表的列表的列表

    表示类型的好方法是什么LoL a 是列表的列表 的 的a 嵌套级别是任意的 但总体上是统一的 外部列表的元素 我想到的情况是对 a 的成员进行分组 列表 然后对每个子组应用下一个分组 依此类推 它 事先并不知道需要应用多少个分组 因此 rG
  • Quill 工具栏未渲染(图标路径显示而不是渲染)

    我正在尝试在 React 中运行本机 Quill 我遵循 quill 的快速入门 但不幸的是工具栏渲染存在问题 见下文 显示图标路径而不是渲染图标路径 请给我同样的指示 套筒组件 import Quill from quill core i
  • AttributeError:“Response”对象没有属性“body_as_unicode”scrapy for python

    我正在 scrapy 中处理响应并继续收到此消息 我只给出了发生错误的片段 我正在尝试浏览不同的网页 并且需要获取该特定网页中的页面数 所以我创建了一个响应对象 我在其中获取下一个按钮的 href 但继续获取AttributeError R
  • 如何为不同的构建配置指定不同的nuget包版本?

    我想为不同的项目配置指定不同的包版本 我知道这在我的 csproj 文件中对于非 NuGet 依赖项 裸 DLL 会是什么样子 但我也想尝试让它与 NuGet 包一起使用 问题是 NuGet 依赖项是在 packages config 中指
  • 为什么使用 redux-persist 而不是手动将状态持久化到 localStorage?

    另一种询问方式是 如果您真的只想使用 localStorage 补充 中保存的数据启动应用程序并将每个 redux 状态更改保存到 localStorage 持久 则使用还原 持久化 https github com rt2zz redux
  • Google Action 和 DialogFlow 错误“抱歉,此操作不适用于您的应用”

    我创建了一个 DialogFlow 应用程序 可以在我的开发者帐户中完美运行 但我需要以另一个用户的身份对其进行测试 因此在我的 Google Action 模拟器中 我添加了另一个测试帐户作为项目的所有者 我验证了该用户在 DialogF
  • 使用 MonoDevelop 4.0(又称 Xamarin Studio)重新获得 C/C++ 项目支持

    使用最新的 Xamarin Studio 从 MonoDevelop 4 0 重新标记 我无法打开 cproj不再可以在 MonoDevelop 3 0 4 7 中运行的项目 The 功能列表 http monodevelop com Do
  • 在 iOS Swift 中检测设备上正在播放的音轨

    我正在创建一个情绪跟踪应用程序 除其他外 它应该使用有关用户收听的歌曲的信息 具体来说 我感兴趣的是在播放曲目时提取从锁定屏幕视图中可见的标题 我搜索过互联网 但没有找到使用 Swift 访问这些数据的解决方案 有人可以帮忙吗 最简洁的答案
  • 链接运算符<<和运算符++的问题

    我正在学习C 我遇到了这个问题 include
  • 在循环中追加到数组 - Python

    请参见this https stackoverflow com questions 54983763 appending values to an array within an object looping over objects精简版
  • Neo4j分区

    有一种在 Neo4j 分区之间进行物理分离的方法吗 这意味着以下查询将转到节点1 Match a User Facebook 虽然此查询将转到另一个节点 可能托管在 docker 上 Match b User Google 情况是这样的 我
  • 如何正确地将 Angular index.html 文件替换/重命名为 index.php?

    在我的 Angular 项目中 我需要在 index html 文件中使用 PHP 我已经将其重命名为index php 并更新了 angular json 以在索引属性中使用index php 我的问题是 运行后ng build命令 di
  • 解决方案资源管理器 - 我的文件夹的自定义图标

    有什么方法可以更改文件夹的图标吗 在具有多个区域的大型 MVC 项目中 如果控制器 模型和视图具有不同的图标 或文本 那就太好了 带有 M 或 V 或 C 的文件夹会很好 如果我知道如何替换它们 我就可以创建它们 即使是在基于项目的变更中也
  • 将字符串转换为字符数组 - 多字节

    假设在 2019 年 每个非 UNICODE 安全的解决方案都是错误的 在 PHP 中将字符串转换为 UNICODE 字符数组的最佳方法是什么 显然 这意味着使用大括号语法访问字节是错误的 以及使用str split arr str spl
  • MySQL 中的 True/False 与 0/1

    这是faster在 MySQL 数据库中 布尔值 或者使用零和一来表示布尔值 我的前端只有一个是 否单选按钮 某些启用 使用布尔值 选项的 前端 会将所有 TINYINT 1 列视为布尔值 反之亦然 这允许您在应用程序中使用 TRUE 和
  • 如果 DELETE 不可能,则 REST HTTP 状态代码

    我的问题是关于 HTTP 状态代码的一个非常通用的问题 当DELETE在资源上是不可能的 但不考虑用户的权利 我们对某种类型的资源有一个 RESTful API The DELETE方法已在资源上获得授权 但在某些情况下无法删除资源 如果有
  • 当 dotnet.exe 找不到 DLL 时如何调试?

    我有一个 ASP NET MVC Core 2 0 应用程序 当我构建它时 输出 DLL 文件创建在bin Debug netcoreapp2 0 当我使用默认值发布它时 发布的输出是在bin Debug netcoreapp2 0 Pub
  • 为什么我的 ADODB.Command 的输出参数在执行时没有检索到值?

    我在经典 ASP 和 SQL Server 中有一段代码 这个想法很简单 有一个存储过程 这样你就可以插入一个文件 但在此之前 sp 将检查文件是否已经存在 之后将返回一个输出参数 所以我可以在我的asp页面上查看 问题是输出参数的返回值什
  • Kubernetes:CoreDNS 和解析主机名的问题

    我有两个通过 Rancher 运行的 kubernetes pod 1 繁忙的盒子 2 dnsutils 从 pod 1 开始 cat etc resolv conf nameserver 10 43 0 10 search testspa
  • 注册新的 undertow SessionManager

    我正在运行 Wildfly 8 1 服务器 我有自己的 SessionManager 实现 io undertow server session SessionManager 我想配置系统以使用我的会话管理器 我应该在哪里以及如何为我的会话