Jetty JDBCLoginService 不获取密码更改?

Jetty JDBCLoginService doesn't pick up password changes?

我已成功使用 Jetty JDBCLoginService 进行 FORM 身份验证(正如 Jetty configuring security authentication page 中所述)。

用户第一次登录时 JDBCLoginService 会缓存用户密码详细信息(如果您遵循 JDBCLoginService.loadUser(String) you pretty quickly get to the user identity being cached in the MappedLoginService._users map 中的逻辑)。

然而,没有任何东西会使此缓存失效 - 即使用户注销,旧的详细信息也会永远保留在那里。

在我的网络应用程序中,我提供了我自己的用户设置 servlet,允许用户更改他们的密码。这与数据库完全独立于 JDBCLoginService 进行交互,因此显然它所做的更改不会被 JDBCLoginService.

获取

我看不到任何明显的方式让 webapp 向登录服务发出此类更改的信号。我将尝试子类化 JDBCLoginService 并覆盖 MappedLoginService.logout(UserIdentity) 以始终在注销时从缓存中删除用户,以便在他们下次登录时获取任何密码更改。

但是更改密码是很正常的,所以我很惊讶我需要更改标准行为 - 我应该以不同的方式处理事情吗?或者使用例如基于 JDBCLoginService?

的更高级的库

这是什么版本的 Jetty? JDBCLoginService9.2.6 Javadocs 是这样说的:

HashMapped User Realm with JDBC as data source. JDBCLoginService extends HashULoginService and adds a method to fetch user information from database. The login() method checks the inherited Map for the user. If the user is not found, it will fetch details from the database and populate the inherited Map. It then calls the superclass login() method to perform the actual authentication. Periodically (controlled by configuration parameter), internal hashes are cleared. Caching can be disabled by setting cache refresh interval to zero. Uses one database connection that is initialized at startup. Reconnect on failures. authenticate() is 'synchronized'. An example properties file for configuration is in $JETTY_HOME/etc/jdbcRealm.properties

这意味着您可以控制缓存失效的频率,或者完全禁用缓存。

但请参阅我上面的评论,您可能更愿意使用更强大的 authentication/authorization 设置与 Shiro 或 Spring 安全性(不一定需要 Spring)