Wildfly刷新安全域缓存

5

我有一个使用JAX-RS接口部署在wildfly上的战争项目,并配置了安全领域,它从数据库加载用户密码和角色。 安全领域使用cache-type=default。 因为旧数据被缓存,所以不会识别已认证用户的更新。 我使用jboss-cli.sh验证了这一点。 那么如何从缓存中删除特定用户? 我想通过已部署的应用程序而不是通过jboss-cli.sh执行此操作。


你使用的是哪个版本的WildFly? - Harald Wellmann
它是WildFly 8.2.0.Final。 - user3909622
3个回答

6

您遇到的问题可能与WildFly中的错误相关:https://issues.jboss.org/browse/WFLY-3221

有一个解决方法可以显式刷新身份验证缓存:

@WebListener
public class SessionInvalidationListener implements HttpSessionListener {

    @Inject
    private Principal principal;

    @Resource(name = "java:jboss/jaas/mydomain/authenticationMgr")
    private CacheableManager<?, Principal> authenticationManager;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        // not used
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        authenticationManager.flushCache(principal);
    }
}

我曾在一个稍微不同的应用场景中测试过这种方法。有趣的是访问authenticationManager - 很容易根据你的情况进行调整。

这个错误应该在WildFly 9.x中得到修复(我没有检查)。


我不使用会话,所以这个错误不影响我的问题。我只想刷新我的安全域的缓存,你的解决方案完全做到了这一点 :) 谢谢!我遇到了一个新问题,因此开了一个新的线程。 - user3909622
有没有想法如何在多个Wildfly实例之间清除缓存?无论是独立模式还是域模式下运行。 - SamF
这是我在Wildfly11上遇到的缓存问题最准确的答案。 - Amr Eladawy

1
在Wildfly 10中,使用域模式可以通过以下方式使用jboss-cli轻松清除安全域缓存:
首先,使用以下命令连接到域控制器:
./jboss-cli.sh --connect controller={domainhost}:9990 --user={username} --password={password}

然后执行命令。
/host={hostname}/server={instancename}/subsystem=security/security-domain={securityname}:flush-cache

如果安全域这样定义:

If security domain is defined like this:

<security-domain name="ldap-test" cache-type="default">

命令将会是这样的:
/host=wf-server-1/server=instance-1/subsystem=security/security-domain=ldap-test:flush-cache

类似的解决方案也适用于独立模式。

在独立模式下,该命令看起来像这样:jboss-cli.sh -c --controller=127.0.0.1:9990 --user={username} --password={password} --command="/subsystem=security/security-domain=ldap-test:flush-cache" - zperee

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接