定义一个自定义用户详细信息服务,实现UserDetailsService。使用用户凭证填充类User的实例,可以将禁止用户的字段使用enabled
或accountNonLocked
。
@Service("userDetailsService")
public class MyUserDetailsService implements UserDetailsService {
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// load user data from repository
String password = ...
boolean enabled = ...
// ...
UserDetails user = new User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
return user;
}
}
再用线为您服务到认证管理器中spring-security.xml
:
<security:authentication-manager>
<security:authentication-provider user-service-ref="userDetailsService">
...
<security:authentication-manager>