Hi,
I'm using the UnrestrictedSessionRunner class to try to WRITE_SECURITY permission before saving a Document(Task) to a user who is not in the Admin group , the runUnrestricted () method returns a new session without the information we need to grant permission.
Here's an example
protected class WritePermission extends UnrestrictedSessionRunner {
protected WritePermission(CoreSession session) {
super(session);
// this.session = documentManager;
}
@Override
public void run() throws ClientException {
DocumentModel doc = getCurrentDocument();
ACP acp = null;
DocumentModel doc2 = session.getDocument(new PathRef(
doc.getPath().toString()));
try {
acp = doc2.getACP();
} catch (Exception e) {
}
if (acp == null) {
acp = new ACPImpl();
}
ACL acl = acp.getOrCreateACL();
int WorkspaceAdminACEIndex = acl.indexOf(new ACE(
session.getPrincipal().toString(),
SecurityConstants.WRITE_SECURITY, true));
if (WorkspaceAdminACEIndex == -1) {
ACE ace = new ACE(session.getPrincipal().toString(),
SecurityConstants.WRITE_SECURITY, true);
acl.add(0, ace);
acp.addACL(acl);
doc2.setACP(acp, true);
}
session.saveDocument(doc2);
session.save();
}
}
new WritePermission(documentManager).runUnrestricted(); // calling the runUnrestricted method.
How could grant permission to the user in this new session returned by runUnrestricted () method?