【发布时间】:2013-02-11 19:51:22
【问题描述】:
我构建了一个简单的 web 应用程序,这是我学习 Spring 技术的一部分。
我正在考虑创建某种自定义用户会话,其中包含对许多用户属性的引用,例如语言、货币可能是。
我怎样才能在春天实现这一目标?还是已经存在一些东西?
【问题讨论】:
我构建了一个简单的 web 应用程序,这是我学习 Spring 技术的一部分。
我正在考虑创建某种自定义用户会话,其中包含对许多用户属性的引用,例如语言、货币可能是。
我怎样才能在春天实现这一目标?还是已经存在一些东西?
【问题讨论】:
您可以编写自定义authentication provider 并传递自定义UserDetailsService
<authentication-manager>
<authentication-provider user-service-ref="customUserService" />
</authentication-manager>
<beans:bean id="customUserService" class="custom.UserServiceImpl">
</beans:bean>
public class UserServiceImpl implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException {
//Your logic
return new AuthenticatedUser("", "", true, true, true, new HashSet<GrantedAuthority>());
}
}
public class AuthenticatedUser extends
org.springframework.security.core.userdetails.User {
private static final long serialVersionUID = 1L;
// Your additional properties
public AuthenticatedUser(String username, String password,
boolean enabled, boolean accountNonExpired,
boolean credentialsNonExpired,
Collection<? extends GrantedAuthority> authorities)
throws IllegalArgumentException {
super(username, password, enabled, accountNonExpired,
credentialsNonExpired, true, authorities);
}
}
【讨论】: