- if (!session.getUserID().equals(
- authentication.getPrincipal().toString())) {
- log.warn("Current session has user ID " + session.getUserID()
- + " while authentication is " + authentication
- + ". Re-login.");
- return login();
+ String userID = session.getUserID();
+ UserDetails userDetails = (UserDetails) authentication.getDetails();
+ if (userDetails != null) {
+ String currentUserName = userDetails.getUsername();
+ if (!userID.equals(currentUserName)) {
+ log.warn("Current session has user ID " + userID
+ + " while logged is user is " + currentUserName
+ + "(authentication=" + authentication + ")"
+ + ". Re-login.");
+ return login();
+ }