jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yusuf Aaji <yusuf.a...@gmail.com>
Subject Re: AW: New information about my last email...
Date Mon, 24 Jan 2011 20:53:28 GMT
Javier,

Use session.getRootNode() to apply the new policy on the whole repository.

BR,
Yusuf

On Mon, Jan 24, 2011 at 7:40 PM, Javier Arias <jarias@ujaen.es> wrote:

> Hi, I am trying grant privileges to a user but I can not do it. The code
> I am using is the following.
>
> Can anybody help me?
>
>
>
> Repository repository = new TransientRepository(new File(_rep));
> Session session = repository.login(new
>         SimpleCredentials("admin","admin");
>
> UserManager userManager = ((JackrabbitSession)
>        session).getUserManager();
>
> AccessControlManager acm = session.getAccessControlManager();
>
> Node node = sessionAdmin.getRootNodeByIdentifier("admin");
>
>
> Authorizable authorizable = userManager.getAuthorizable(user);
> Principal p = (Principal) ((User) authorizable).getPrincipal();
>
> Privilege[] privileges = null;
> 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();
>
>
> Another problem is, in class AccessControlPolicy I must call
> AccessControlPolicy.getApplicablePolicies() and setPolicy() passing as
> parameter a node. I do not know how I should get this nodo.
> Session.getRootNode()?
> session.getNode("user")?
> session.getNodeByIdentifier("user")?
>
> If I call getNode("user") or getNodeByIdentifier("user") the program
> throws a Repository exception.
>
> Thank you in advance. Regards.
>
> El sáb, 22-01-2011 a las 18:44 +0100, Seidel. Robert escribió:
> > Hi Javier,
> >
> > The jsr specification helped me a lot:
> http://jcp.org/aboutJava/communityprocess/final/jsr283/index.html
> >
> > See page 225 and following.
> >
> > Regards, Robert
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Angela Schreiber [mailto:anchela@adobe.com]
> > Gesendet: Freitag, 21. Januar 2011 15:10
> > An: users@jackrabbit.apache.org
> > Betreff: Re: New information about my last email...
> >
> > hi javier
> >
> > > About grant privileges an user, I am some lost. I understood first step
> > > and second step but I do not know how follow. How can I get
> > > AccessControlList? How grant privileges with User.getPrincipal?
> >
> > did you take a look a the JCR API related to access control?
> > starting from Session.getAccessControlManager() you should find your
> > way through, i guess.
> >
> > angela
>
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message