jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a_totade <a_tot...@rediffmail.com>
Subject Principal-based ACLs - zero policy are returned
Date Wed, 17 Jul 2013 11:27:46 GMT
I am trying to use principle based ACL.

I have written the code as below and I am getting zero policies. I would
appreciate if somebody helps me in resolving the error.
------------------------------------------------
  Session session=null;
        try{
                Repository repository =     repository = new
TransientRepository("D:\\work\\Jackrabbit-Repository\\repository.xml",
"D:\\work\\Jackrabbit-Repository");
              session = repository.login(new
SimpleCredentials("admin","admin".toCharArray()));
                String nodepath = "user1Node";

                JackrabbitSession js = (JackrabbitSession) session;
                User user = ((User)
js.getUserManager().getAuthorizable("user1"));
                Principal principal = user.getPrincipal();
                System.out.println(user.getPrincipal());

                Node n2 = session.getNode("/"+nodepath);
                JackrabbitAccessControlManager acm =
(JackrabbitAccessControlManager)session.getAccessControlManager();
                JackrabbitAccessControlPolicy[] ps  =
acm.getPolicies(user.getPrincipal());//acm.getApplicablePolicies(user.getPrincipal());
                System.out.println("  policy list it=== "+ps.length);
                 //Getting 0 policies and so error afterwards
                JackrabbitAccessControlList list =
(JackrabbitAccessControlList) ps[0];

                // list entries
                AccessControlEntry[] entries =
list.getAccessControlEntries();

                if(entries.length>0){
                        System.out.println(" removing previous
entries......");
                        AccessControlEntry entry = entries[0];
                        // remove entry
                        list.removeAccessControlEntry(entry);
                }
                // add new entry
                                        Privilege[] privileges = new
Privilege[] { acm.privilegeFromName(Privilege.JCR_ALL)};
                                        Map<String, Value> restrictions =
new HashMap<String, Value>();
                                        ValueFactory vf =
session.getValueFactory();
                                        restrictions.put("rep:nodePath",
vf.createValue(nodepath, PropertyType.PATH));
                                        restrictions.put("rep:glob",
vf.createValue("*"));
                                        list.addEntry(principal, privileges,
true /* allow or deny */, restrictions);

                                        // reorder entries
                                        //list.orderBefore(entry, entry2);

                                        // finally set policy again & save
                                        acm.setPolicy(list.getPath(), list);


                System.out.println("access provided at ===== "+nodepath);
                session.save();
                }catch(Exception ex){
                        ex.printStackTrace();
                }finally{
                        session.logout();
                }




--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Principal-based-ACLs-zero-policy-are-returned-tp4659071.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Mime
View raw message