Source:
public Response putNotePermissions(@PathParam("noteId") String noteId, String req) throws IOException { String principal = SecurityUtils.getPrincipal(); HashSet<String> roles = SecurityUtils.getRoles(); HashSet<String> userAndRoles = new HashSet<>(); userAndRoles.add(principal); userAndRoles.addAll(roles); checkIfUserCanWrite(noteId, ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId))); HashMap<String, HashSet<String>> permMap = gson.fromJson(req, new TypeToken<HashMap<String, HashSet<String>>>() {}.getType()); Note note = notebook.getNote(noteId); LOG.info("Set permissions {}", noteId, principal, permMap.get("owners"), permMap.get("readers"), permMap.get("writers")); HashSet<String> readers = permMap.get("readers"); HashSet<String> owners = permMap.get("owners"); HashSet<String> writers = permMap.get("writers"); if (readers != null && !readers.isEmpty()) { if (writers.isEmpty()) { writers = Sets.newHashSet(SecurityUtils.getPrincipal()); } if (owners.isEmpty()) { owners = Sets.newHashSet(SecurityUtils.getPrincipal()); } } if (writers != null && !writers.isEmpty()) { if (owners.isEmpty()) { owners = Sets.newHashSet(SecurityUtils.getPrincipal()); } } notebookAuthorization.setReaders(noteId, readers); notebookAuthorization.setWriters(noteId, writers); notebookAuthorization.setOwners(noteId, owners); LOG.debug("After set permissions {}", notebookAuthorization.getOwners(noteId), notebookAuthorization.getReaders(noteId), notebookAuthorization.getWriters(noteId)); AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); note.persist(subject); notebookServer.broadcastNote(note); notebookServer.broadcastNoteList(subject, userAndRoles); return new JsonResponse<>(Status.OK).build(); }

Target:
public Response putNotePermissions(@PathParam("noteId") String noteId, String req) throws IOException { String principal = SecurityUtils.getPrincipal(); HashSet<String> roles = SecurityUtils.getRoles(); HashSet<String> userAndRoles = new HashSet<>(); userAndRoles.add(principal); userAndRoles.addAll(roles); checkIfUserIsOwner(noteId, ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId))); HashMap<String, HashSet<String>> permMap = gson.fromJson(req, new TypeToken<HashMap<String, HashSet<String>>>() {}.getType()); Note note = notebook.getNote(noteId); LOG.info("Set permissions {}", noteId, principal, permMap.get("owners"), permMap.get("readers"), permMap.get("writers")); HashSet<String> readers = permMap.get("readers"); HashSet<String> owners = permMap.get("owners"); HashSet<String> writers = permMap.get("writers"); if (readers != null && !readers.isEmpty()) { if (writers.isEmpty()) { writers = Sets.newHashSet(SecurityUtils.getPrincipal()); } if (owners.isEmpty()) { owners = Sets.newHashSet(SecurityUtils.getPrincipal()); } } if (writers != null && !writers.isEmpty()) { if (owners.isEmpty()) { owners = Sets.newHashSet(SecurityUtils.getPrincipal()); } } notebookAuthorization.setReaders(noteId, readers); notebookAuthorization.setWriters(noteId, writers); notebookAuthorization.setOwners(noteId, owners); LOG.debug("After set permissions {}", notebookAuthorization.getOwners(noteId), notebookAuthorization.getReaders(noteId), notebookAuthorization.getWriters(noteId)); AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); note.persist(subject); notebookServer.broadcastNote(note); notebookServer.broadcastNoteList(subject, userAndRoles); return new JsonResponse<>(Status.OK).build(); }