jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Javier Arias <jar...@ujaen.es>
Subject Re: AW: New information about my last email...
Date Wed, 26 Jan 2011 10:01:20 GMT
Hi Angela, 

My goal is create a new user and grant him some privileges. As you
suggested me the privileges will be: 

jcr:modifyProperties
jcr:addChildNodes
jcr:removeNodes
jcr:removeChildNode
jcr:nodetypeManagement

The code that I am executing is the following:

************************
Repository repository = new TransientRepository(new File(_repository));
Session session = repository.login(new SimpleCredentials("user","pass");

UserManager userManager = ((JackrabbitSession)session).getUserManager();

Authorizable authorizable =  
     userManager.getAuthorizable(user);            

Principal p = (Principal) authorizable.getPrincipal();

AccessControlManager acm = session.getAccessControlManager();

Node node = session.getRootNode();
            
AccessControlPolicyIterator it = (AccessControlPolicyIterator)   
      acm.getApplicablePolicies(node.getPath());
      
if (it.hasNext())
{
 AccessControlPolicy policy = it.nextAccessControlPolicy();
 if (policy instanceof AccessControlList)
 {
 privileges[0] = acm.privilegeFromName(Privilege.JCR_MODIFY_PROPERTIES);
 privileges[1] = acm.privilegeFromName(Privilege.JCR_ADD_CHILD_NODES);
 privileges[2] = acm.privilegeFromName(Privilege.JCR_REMOVE_NODE);
 privileges[3] =     
       acm.privilegeFromName(Privilege.JCR_REMOVE_CHILD_NODES);
 privileges[4] =  
       acm.privilegeFromName(Privilege.JCR_NODE_TYPE_MANAGEMENT);
                   
 ((AccessControlList)policy).addAccessControlEntry(p,privileges);
                    acm.setPolicy(node.getPath(), policy);
}

session.save();
session.logout();

************************

the problem is when I call:

AccessControlPolicyIterator it = (AccessControlPolicyIterator)
acm.getApplicablePolicies(node.getPath());

if (it.hasNext())
....

the function it.hasNext() returns always false. I do not understand
why. 
Do you know what is happening?
I am spending a lot of time in create an user and grant privileges.

Thank you. Regards.


Mime
View raw message