protected void removeAuthorization(User user, String auth, User authUser) { Set<String> auths = getAuthorizations(user); if (auths.contains(auth)) { LOGGER.info( "Removing authorization '%s' to user '%s' by '%s'", auth, user.getUsername(), authUser.getUsername() ); auths.remove(auth); getUserRepository().setPropertyOnUser(user, AUTHORIZATIONS_PROPERTY_IRI, Joiner.on(SEPARATOR).join(auths)); sendNotificationToUserAboutRemoveAuthorization(user, auth, authUser); workQueueRepository.pushUserAccessChange(user); fireUserRemoveAuthorizationEvent(user, auth); } }
protected void addAuthorization(User user, String auth, User authUser) { auth = auth.trim(); Set<String> auths = getAuthorizations(user); if (!auths.contains(auth)) { LOGGER.info( "Adding authorization '%s' to user '%s' by '%s'", auth, user.getUsername(), authUser.getUsername() ); auths.add(auth); authorizationRepository.addAuthorizationToGraph(auth); getUserRepository().setPropertyOnUser(user, AUTHORIZATIONS_PROPERTY_IRI, Joiner.on(SEPARATOR).join(auths)); sendNotificationToUserAboutAddAuthorization(user, auth, authUser); workQueueRepository.pushUserAccessChange(user); fireUserAddAuthorizationEvent(user, auth); } }
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); }