protected void setAuthorizations(User user, Set<String> newAuthorizations, User authUser) {
String[] newAuthorizationsArray = newAuthorizations.toArray(new String[newAuthorizations.size()]);
authorizationRepository.addAuthorizationToGraph(newAuthorizationsArray);
String newAuthorizationsString = Joiner.on(SEPARATOR).join(newAuthorizations);
LOGGER.info(
"Setting authorizations '%s' to user '%s' by '%s'",
newAuthorizationsString,
user.getUsername(),
authUser.getUsername()
);
Set<String> currentAuthorizations = getAuthorizations(user);
getUserRepository().setPropertyOnUser(user, AUTHORIZATIONS_PROPERTY_IRI, newAuthorizationsString);
Set<String> addedAuthorizations = new HashSet<>(newAuthorizations);
addedAuthorizations.removeAll(currentAuthorizations);
for (String auth : addedAuthorizations) {
sendNotificationToUserAboutAddAuthorization(user, auth, authUser);
fireUserAddAuthorizationEvent(user, auth);
}
Set<String> removedAuthorizations = new HashSet<>(currentAuthorizations);
removedAuthorizations.removeAll(newAuthorizations);
for (String auth : removedAuthorizations) {
sendNotificationToUserAboutRemoveAuthorization(user, auth, authUser);
fireUserRemoveAuthorizationEvent(user, auth);
}
workQueueRepository.pushUserAccessChange(user);
}