jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Seidel. Robert" <Robert.Sei...@aeb.de>
Subject AW: Setting twice policies on a node ?
Date Wed, 13 Jul 2011 06:17:48 GMT
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:jean.rebillat@free.fr] 
Gesendet: Dienstag, 12. Juli 2011 18:51
An: users@jackrabbit.apache.org
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.

Mime
View raw message