/** * Checks if the current user can still read and write access rights. If he can't, then the security data are * rebuilt. */ private boolean checkPermissions() { if (currentUser.isAdministrator()) { return true; } else { List<String> principals = new ArrayList<String>(); principals.add(currentUser.getName()); principals.addAll(currentUser.getAllGroups()); ACP acp = currentDocument.getACP(); new SecurityDataConverter(); List<UserEntry> modifiableEntries = SecurityDataConverter.convertToUserEntries(securityData); if (null == acp) { acp = new ACPImpl(); } acp.setRules(modifiableEntries.toArray(new UserEntry[0])); final boolean access = acp.getAccess(principals.toArray(new String[0]), getPermissionsToCheck()) .toBoolean(); if (!access) { rebuildSecurityData(); } return access; } }
@Override public void applyDefaultPermissions(String userOrGroupName) { if (userOrGroupName == null) { throw new NullPointerException("null userOrGroupName"); } if (!isAdministrator()) { throw new DocumentSecurityException("You need to be an Administrator to do this."); } DocumentModel rootDocument = getRootDocument(); ACP acp = new ACPImpl(); UserEntry userEntry = new UserEntryImpl(userOrGroupName); userEntry.addPrivilege(READ); acp.setRules(new UserEntry[] { userEntry }); setACP(rootDocument.getRef(), acp, false); }
@Override public String updateSecurityOnDocument() { List<UserEntry> modifiableEntries = SecurityDataConverter.convertToUserEntries(securityData); ACP acp = currentDocument.getACP(); if (acp == null) { acp = new ACPImpl(); } acp.setRules(modifiableEntries.toArray(new UserEntry[0])); currentDocument.setACP(acp, true); documentManager.save(); Events.instance().raiseEvent(EventNames.DOCUMENT_SECURITY_CHANGED); // Reread data from the backend to be sure the current bean // state is uptodate w.r.t. the real backend state rebuildSecurityData(); // Type currentType = typeManager.getType(currentDocument.getType()); // return applicationController.getPageOnEditedDocumentType(currentType); // Forward to default view, that's not what we want // return navigationContext.getActionResult(currentDocument, UserAction.AFTER_EDIT); // Temporary fix, to avoid forward to default_view. // The same page is reloaded after submit. // May use UserAction, with new kind of action (AFTER_EDIT_RIGHTS)? return null; }
copyTo(aces, i + 1, entries, i, entries.length - i - 1); acp.setRules(entries, true); session.setACP(docRef, acp, true);