hi how does your repository configuration look like? the default setup in jackrabbit core will provide you with a resource based access control model. in order to user the principal-based implementation you need to have the AccessControlProvider configuration of the workspace-security element set to the right implementation.
kind regards angela On 7/17/13 1:27 PM, "a_totade" <[email protected]> wrote: >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.getP >rincipal()); > 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-ar >e-returned-tp4659071.html >Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
