【发布时间】:2011-06-22 05:49:44
【问题描述】:
我有以下 UserDetailsService 实现。
到目前为止,身份验证过程运行良好。
如何将我的“MyUser bean”(成功登录)存储在“会话”中,以便我可以在应用程序的其他区域访问它
谢谢。
@Transactional(readOnly = true)
public class CustomUserDetailsService implements UserDetailsService {
private EmployeesApi employeesApi = new EmployeesApi();
/**
* Retrieves a user record containing the user's credentials and access.
*/
public UserDetails loadUserByUsername(String userName)
throws UsernameNotFoundException, DataAccessException {
// Declare a null Spring User
UserDetails user = null;
try {
MyUser employee = employeesApi.getByUserName(userName);
user = new User(
employee.getUserName(),
employee.getPassword().toLowerCase(),
true,
true,
true,
true,
getAuthorities(1) );
} catch (Exception e) {
logger.error("Error in retrieving user");
throw new UsernameNotFoundException("Error in retrieving user");
}
}
....
【问题讨论】:
标签: java spring-mvc spring-security