Cam*_*amW 4 java spring-security
我已经将org.springframework.security.core.userdetails.User子类化,并在我的构造函数中调用:
Super (String username,
String password,
boolean enabled,
boolean accountNonExpired,
boolean credentialsNonExpired,
boolean accountNonLocked,
GrantedAuthority[] authorities)
Run Code Online (Sandbox Code Playgroud)
然后我${SPRING_SECURITY_LAST_EXCEPTION.message}用来在登录失败时显示结果.
我遇到的问题是,如果我将accountNotLocked设置为false,则会显示帐户锁定错误消息,无论密码是否正确,都会发生这种情况.如果首先启用spring验证凭据然后启用,accountNonExpired,credentialsNonExpired和accountNonLocked标志,我会更喜欢它.这样,如果用户获得了正确的凭据,则只会通知用户他们的帐户已被锁定.
有没有办法强迫春天这样做?
我假设你使用最流行DaoAuthenticationProvider,问题出UserDetailsChecker在这个类的默认实现中.也就是说,移动所有检查后DaoAuthenticationProvider.additionalAuthenticationChecks应该足以解决您的问题.尝试以下配置:
<authentication-manager alias="authenticationManager">
<authentication-provider ref="daoAuthenticationProvider" />
</authentication-manager>
<bean id="daoAuthenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="userDetailsService"/>
<property name="passwordEncoder" ref="passwordEncoder"/>
<property name="preAuthenticationChecks"
class="com.example.NullUserDetailsChecker"/>
<property name="postAuthenticationChecks"
class="org.springframework.security.authentication.AccountStatusUserDetailsChecker"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
其中com.example.NullUserDetailsChecker是null对象模式的实现UserDetailsChecker(具有无效的void检查方法).
| 归档时间: |
|
| 查看次数: |
2330 次 |
| 最近记录: |