}
if (users.size() == 0) {
throw new UsernameNotFoundException("User not found for '" + loginName + "'");
}
logger.debug("loadUserByUserName success for '" + loginName + "'");
User user = users.get(0);
// if some spaces have guest access enabled, allocate these spaces as well
Set<Space> userSpaces = user.getSpaces();
logger.debug("user spaces: " + userSpaces);
for(Space s : findSpacesWhereGuestAllowed()) {
if(!userSpaces.contains(s)) {
user.addSpaceWithRole(s, Role.ROLE_GUEST);
}
}
for(UserSpaceRole usr : user.getSpaceRoles()) {
logger.debug("UserSpaceRole: " + usr);
// this is a hack, the effect of the next line would be to
// override hibernate lazy loading and get the space and associated metadata.
// since this only happens only once on authentication and simplifies a lot of
// code later because the security principal is "fully prepared",