Hi,
The first code did not change a policy, it is adding it to the node.
When it was added, it is not "applicable" anymore, that's why
getApplicablePolicies() is empty. You have to use getPolicies() instead...
The JSR was designed to use multiple policies, but in Jackrabbit there is
normally only one, that's why you have to write something (ugly) like this:
AccessControlManager acMngr =
connection.getSession().getAccessControlManager();
AccessControlPolicyIterator it =
acMngr.getApplicablePolicies(path);
while(it.hasNext()) {
AccessControlPolicy acp = it.nextAccessControlPolicy();
if (acp instanceof AccessControlList) {
return (AccessControlList) acp;
}
}
AccessControlPolicy[] acps = acMngr.getPolicies(path);
for (AccessControlPolicy accessControlPolicy : acps) {
if (accessControlPolicy instanceof AccessControlList) {
return (AccessControlList) accessControlPolicy;
}
}
Kindly regards,
Robert
-----Ursprüngliche Nachricht-----
Von: jrebillat [mailto:[email protected]]
Gesendet: Dienstag, 12. Juli 2011 18:51
An: [email protected]
Betreff: Setting twice policies on a node ?
In a program I am working on that uses JCR a storage, I need to have security
set on some nodes.
I used to use another implementation of JCR than Jackrabbit, for historical
reasons.
Now, I want to switch to Jackrabbit 2.1 but I'm hanging on something strange
to me.
On a node, I catch the policy :
AccessControlManager manager = session.getAccessControlManager();
Principal principal = group.getPrincipal();
AccessControlPolicyIterator ps =
manager.getApplicablePolicies(path);
AccessControlList ps0 = (AccessControlList)ps.next();
then I change it with new "privs" and save :
ps0.addAccessControlEntry(principal, privs);
manager.setPolicy(path, ps0);
session.save();
What is strange to me is that, from now on - even if I close the application
and restart it - I can not get another time the control list for that
particular node. In fact, calling a second time for the same path :
AccessControlManager manager = session.getAccessControlManager();
Principal principal = group.getPrincipal();
AccessControlPolicyIterator ps =
manager.getApplicablePolicies(path);
AccessControlList ps0 = (AccessControlList)ps.next();
will generate an error (nothing to iterate on), as if there was no
applicable policies for the given path.
What did I miss ?
--
View this message in context:
http://jackrabbit.510166.n4.nabble.com/Setting-twice-policies-on-a-node-tp3662853p3662853.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.