DirectoryService systemDirectory = (DirectoryService) bundleCtx.getService(userDirectoryRef);
logger.debug("Checking new site '{}' user '{}' for shadowing of site or system account");
User shadowedUser = systemDirectory.loadUser(user, site);
if (shadowedUser != null) {
if (SecurityUtils.userHasRole(shadowedUser, SYSTEMADMIN))
throw new UserShadowedException("Site '" + site.getIdentifier() + "' account '" + user + "' is shadowing the system account");
else if (SecurityUtils.userHasRole(shadowedUser, SITEADMIN))
throw new UserShadowedException("Site '" + site.getIdentifier() + "' account '" + user + "' is shadowing the site account");
else
throw new UserExistsException("Site '" + site.getIdentifier() + "' account '" + user + "' already exists");
}
} else {
logger.warn("Directory service not found, site '{}' user '{}' cannot be checked for user shadowing", site.getIdentifier(), user);