You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by shivalika <de...@gmail.com> on 2010/07/08 06:40:06 UTC

Setting Privileges

Hello users,

I have developed a login module called as SampleLoginModule & created its
.jar file. This file has been put into the repository & the path in
Repository.xml is changed.

Our this Login module works as:

1.admin logs in after being authenticated.
2.after login, the admin can create users.
The created users are written to a file Users.xml
As well as, i used the createUser method of UserManagerImpl -  it creates
users as JCR nodes.

public User createUser(String userID, String password) throws
RepositoryException

So far, working good!!

Now i want to add privileges for this particular created user at the time of
creation.

I did some R&D as :

public void access_control(Node testRootNode, PrincipalImpl principal)
throws UnsupportedRepositoryOperationException, RepositoryException {
        try {
            AccessControlPolicy acp = null;
            AccessControlManager acm = session.getAccessControlManager();
            System.out.println("1" + acm.toString());

            AccessControlPolicy[] it =
acm.getEffectivePolicies(testRootNode.getPath());
            System.out.println("2:::" + it.length);
            for (int i = 0; i < it.length; i++) {
                acp = it[i];
                System.out.println(acp.toString());
            }
            System.out.println("3" + it.toString());
            Privilege[] privileges = new
Privilege[]{acm.privilegeFromName(Privilege.JCR_WRITE)};
            System.out.println("3:::" + privileges.length);

            ((AccessControlList) acp).addAccessControlEntry(new
PrincipalImpl(session.getUserID()), privileges);
            System.out.println("4");
            acm.setPolicy(testRootNode.getPath(), acp);

            System.out.println("set");

        } catch (Exception re) {
            re.printStackTrace();
            System.out.println("Exception caught:" + re);
        }
    }

I get an exception as:
Exception caught:java.lang.ClassCastException:
org.apache.jackrabbit.core.security.authorization.NamedAccessControlPolicyImpl
cannot be cast to javax.jcr.security.AccessControlList

Moreover, the session is for the admin user, not the created user.

So, what i want is that as soon as the user is created by Admin, the
privileges are being set for this particular created user in question.

Any comments and suggestions would help greatly.

Thanks

shivalika.


-- 
View this message in context: http://jackrabbit.510166.n4.nabble.com/Setting-Privileges-tp2281799p2281799.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Setting Privileges

Posted by shivalika <de...@gmail.com>.
Hi angela ...

Sorry, I forgot to write this--

My repository configuration remains the same except for LoginModule only.

I have my own implementation of LoginModule that allows only created users
to log in & only admin to create users & roles. Also admin can assign roles
to different users.

Thank you so much for replying to me.

Regards...

Shivalika
-- 
View this message in context: http://jackrabbit.510166.n4.nabble.com/Setting-Privileges-tp2281799p2287545.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Setting Privileges

Posted by Angela Schreiber <an...@day.com>.
hi shivalika

> I have developed a login module called as SampleLoginModule & created its
> .jar file. This file has been put into the repository & the path in
> Repository.xml is changed.

and the rest of the repository's security configuration?

> public void access_control(Node testRootNode, PrincipalImpl principal)
> throws UnsupportedRepositoryOperationException, RepositoryException {
>         try {
>             AccessControlPolicy acp = null;
>             AccessControlManager acm = session.getAccessControlManager();
>             System.out.println("1" + acm.toString());
> 
>             AccessControlPolicy[] it =
> acm.getEffectivePolicies(testRootNode.getPath());

AccessControlManager#getEffectivePolicies is for display purpose
only -> see API

you should use
AccessControlManager#getApplicablePolicies or 
AccessControlManager#getPolicies to obtain policies that can
be modified and reapplied.

>             System.out.println("2:::" + it.length);
>             for (int i = 0; i < it.length; i++) {
>                 acp = it[i];
>                 System.out.println(acp.toString());
>             }
>             System.out.println("3" + it.toString());
>             Privilege[] privileges = new
> Privilege[]{acm.privilegeFromName(Privilege.JCR_WRITE)};
>             System.out.println("3:::" + privileges.length);
> 
>             ((AccessControlList) acp).addAccessControlEntry(new
> PrincipalImpl(session.getUserID()), privileges);
>             System.out.println("4");
>             acm.setPolicy(testRootNode.getPath(), acp);
> 
>             System.out.println("set");
> 
>         } catch (Exception re) {
>             re.printStackTrace();
>             System.out.println("Exception caught:" + re);
>         }
>     }
> 
> I get an exception as:
> Exception caught:java.lang.ClassCastException:
> org.apache.jackrabbit.core.security.authorization.NamedAccessControlPolicyImpl
> cannot be cast to javax.jcr.security.AccessControlList

see above. note however: whether or not an applicable policy
is an ACL or not depends on the AccessControlProvider specified
for the particular workspace.

> Moreover, the session is for the admin user, not the created user.

? sorry can't follow you here.

> So, what i want is that as soon as the user is created by Admin, the
> privileges are being set for this particular created user in question.
> 
> Any comments and suggestions would help greatly.

regards
angela