public void setUserService(UserService userService) {
this.userService = userService;
}
public User attachToUser(Authentication auth) {
User user = userService.get((String) auth.getPrincipal());
if (null == user) {
throw new AuthenticationException(Authentication.ERROR_NOTEXIST);
}
if (!user.isEnabled()) {
throw new AuthenticationException(Authentication.ERROR_UNACTIVE);
}
if (null == auth.getDetails()) {
auth.setDetails(new UserDetails());
}
UserDetails details = (UserDetails) auth.getDetails();
details.setUserid(user.getId());
details.setFullname(user.getFullname());
details.setCategory(entityDao.get(UserCategory.class, user.getDefaultCategory().getId()));
return user;
}