我构建了一个简单的webapp,这是我学习弹簧技术的一部分。
我正在考虑创建某种自定义用户会话,该会话保存对许多用户属性的引用,例如语言,货币可能是。
我怎样才能在春天实现这一目标?或者已经存在某些东西?
答案 0 :(得分:0)
您可以撰写自定义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);
}
}