When dealing with Spring Security do you usually store the current user into a session variable or do you hit the DB every single time you want to access some user information?
At the moment I do the following but it seems a bit wasteful:
public class CurrentUserService {
private UserDAO userDAO;
public CurrentUserService(UserDAO userDAO) {
super();
this.userDAO = userDAO;
}
public User getUser(){
String username=SecurityContextHolder.getContext().getAuthentication().getName();
return userDAO.findUser(username);
}
}