jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francisco Carriedo Scher <fcarrie...@gmail.com>
Subject Re: Setting up Access Control
Date Wed, 14 Sep 2011 08:28:27 GMT
I tried to start from scratch as you suggested (a simple Java project with
the jackrabbit standalone .jar as library). Then i execute the following
code (from the updated Wiki section) logged in as admin:

    public Node createFolder(String username, String path, String
foldername){

        Node actualNode;
        try {
            // Absolute path REQUIRED
            actualNode = session.getNode(path);
            actualNode = actualNode.addNode(foldername, "nt:folder");
            // Node HAVE TO exist prior to ACL setting
            session.save();
                              // Username value is "admin" or any other
username
            *setAcl(new PrincipalImpl(username), actualNode.getPath());*


        } catch (PathNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (RepositoryException e) {
            e.printStackTrace();
            return null;
        }

        return actualNode;
    }

    private void *setAcl(Principal p, String path)* throws
UnsupportedRepositoryOperationException, RepositoryException {

        AccessControlManager aMgr = session.getAccessControlManager();

        // create a privilege set with jcr:all
        Privilege[] privileges = new Privilege[] {
aMgr.privilegeFromName(Privilege.JCR_ALL) };
        AccessControlList acl;
        try {
            // get first applicable policy (for nodes w/o a policy)
            acl = (AccessControlList)
aMgr.getApplicablePolicies(path).nextAccessControlPolicy();
        } catch (NoSuchElementException e) {
            // else node already has a policy, get that one
            *acl = (AccessControlList) aMgr.getPolicies(path)[0];*
        }
        // remove all existing entries
        for (AccessControlEntry e : acl.getAccessControlEntries()) {
            acl.removeAccessControlEntry(e);
        }
        // add a new one for the special "everyone" principal
        acl.addAccessControlEntry(p, privileges);

        // the policy must be re-set
        aMgr.setPolicy(path, acl);

        // and the session must be saved for the changes to be applied
        session.save();

    }

Executing the code above i get  the following exception (caused by the code
above highlighted in red colour):
*
java.lang.ArrayIndexOutOfBoundsException: 0
    at
com.solaiemes.filerepository.management.FileManager.setAcl(FileManager.java:126)
    at
com.solaiemes.filerepository.management.FileManager.createFolder(FileManager.java:103)
    at com.solaiemes.filerepository.starting.Permisos.main(Permisos.java:70)
*


Hope to be clear enough, if i am not please tell me and i will try to
describe it better.

Thanks for your attention!




2011/9/14 maikhorma <MHerman@nbme.org>

>
> Francisco Carriedo Scher wrote:
> >
> > ...but the problem for me comes when invocating aMgr.setPolicy(path,acl);
> >
>
> What exactly is the problem? I can't tell  if you're getting an exception
> or
> it doesn't appear to apply. If it's an exception, a stack trace with your
> code would help.
>
>
> Francisco Carriedo Scher wrote:
> >
> > So, should i attend any configuration prior to start working on access
> > control?
> >
>
> No, I would start with a fresh download of jackrabbit standalone without
> any
> configurations, as it should work.  If it doesn't your code and error will
> help, if it does work, then there it is something specific to the instance
> you are working in.
>
>
> --
> View this message in context:
> http://jackrabbit.510166.n4.nabble.com/Setting-up-Access-Control-tp3809801p3811342.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>

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