0

我可以验证用户

Authentication request = new UsernamePasswordAuthenticationToken(this.username, this.password);
            Authentication result = authenticationManager.authenticate(request);
            SecurityContextHolder.getContext().setAuthentication(result);

现在我必须选择 user.status 字段为“活动”的用户。

我想我可以在上面检查状态字段的代码之前放几行,

但我也认为如果我可以让 Spring Security 为我做这件事,它会更加优雅和整洁。

但是我不知道如何通过覆盖某些类或某些方法来让 SS 为我做这件事?

感谢您的建议。

4

2 回答 2

0

如果您只有两个状态(“活动”、“不活动”),那么您可以使用本机user.enabled字段而不是自定义 user.status字段。该字段将由 AuthenticationManager.authenticate() 方法自动检查(如果您使用像 DaoAuthenticationProvider 这样的本机 AuthenticationProvider)。查看标准用户架构中的启用属性

于 2013-01-03T15:05:13.353 回答
0

您可以在 spring 安全配置中将以下 SpEL 添加到拦截 url。

<intercept-url pattern="/**" access="isFullyAuthenticated() and principal.status == 'active'/>
于 2013-01-03T15:16:34.467 回答