roles.add(getLocalRole(site, SystemRole.GUEST));
} else {
Object principal = auth.getPrincipal();
if (principal == null) {
logger.warn("No principal found in spring security context, setting current user to anonymous");
user = new Guest(site.getIdentifier());
roles.add(getLocalRole(site, SystemRole.GUEST));
} else if (principal instanceof SpringSecurityUser) {
user = ((SpringSecurityUser) principal).getUser();
logger.debug("Principal was identified as '{}'", user.getLogin());
} else if (principal instanceof UserDetails) {
UserDetails userDetails = (UserDetails) principal;
user = new UserImpl(userDetails.getUsername());
logger.debug("Principal was identified as '{}'", user.getLogin());
Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
if (authorities != null && authorities.size() > 0) {
for (GrantedAuthority ga : authorities) {
logger.debug("Principal '{}' gained role '{}'", user.getLogin(), ga.getAuthority());
roles.add(new RoleImpl(ga.getAuthority()));
}
}
} else if (Security.ANONYMOUS_USER.equals(principal)) {
user = new Guest(site.getIdentifier());
roles.add(getLocalRole(site, SystemRole.GUEST));
} else {
logger.warn("Principal was not compatible with spring security, setting current user to anonymous");
user = new Guest(site.getIdentifier());
roles.add(getLocalRole(site, SystemRole.GUEST));
}
}
for (Role role : roles) {