Authentication 根据Spring Security中的my user.status字段进行身份验证的优雅方式
我可以验证用户的身份Authentication 根据Spring Security中的my user.status字段进行身份验证的优雅方式,authentication,spring-security,Authentication,Spring Security,我可以验证用户的身份 Authentication request = new UsernamePasswordAuthenticationToken(this.username, this.password); Authentication result = authenticationManager.authenticate(request); SecurityContextHolder.getContext().setAuthenticati
Authentication request = new UsernamePasswordAuthenticationToken(this.username, this.password);
Authentication result = authenticationManager.authenticate(request);
SecurityContextHolder.getContext().setAuthentication(result);
现在我必须选择user.status字段为“活动”的用户
我想我可以在上面的代码前放几行,检查状态字段
但我也认为,如果我能让Spring Security为我做这件事,它会更优雅、更整洁
但我不知道如何让SS通过重写某些类或方法来为我做到这一点
感谢您的建议。如果您只有两种状态(“活动”、“非活动”),则可以使用本机用户.enabled字段,而不是自定义user.status field。AuthenticationManager.authenticate()方法将自动检查此字段(如果您使用某些本机AuthenticationProvider,如DAOAAuthenticationProvider)。请参见中的启用属性,您可以在spring安全配置中将以下SpEL添加到截取url中
<intercept-url pattern="/**" access="isFullyAuthenticated() and principal.status == 'active'/>