jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Malzer Ferdinand OSP sIT <Ferdinand.Mal...@s-itsolutions.at>
Subject AW: problem after registering a custom privilege
Date Thu, 03 May 2012 06:54:01 GMT
Hello,
Thx for the fast reply.

It seems that the problem was the statement session.save() which leads to that inconsistency
in the repository.
Now registering seem to work with the following code:

            session = repository.login(new SimpleCredentials(user, pwd.toCharArray()), workspace);
            JackrabbitWorkspace jrws = (JackrabbitWorkspace) session.getWorkspace();
            PrivilegeManager privMgr = jrws.getPrivilegeManager();
            try {
                Privilege priv = privMgr.getPrivilege("gcms_role_chief");
                System.out.println("Privilege already exists: " + priv.getName());
            } catch (AccessControlException e) {
                privMgr.registerPrivilege("gcms_role_chief", false, new String[] {});
            }
            //dont save the session!!

:-) ferry malzer

-----Urspr√ľngliche Nachricht-----
Von: justinedelson@gmail.com [mailto:justinedelson@gmail.com] Im Auftrag von Justin Edelson
Gesendet: Mittwoch, 02. Mai 2012 16:26
An: users@jackrabbit.apache.org
Betreff: Re: problem after registering a custom privilege

You need to check if the privilege already exists before registering it.

Justin

On Wed, May 2, 2012 at 10:13 AM, Malzer Ferdinand OSP sIT <
Ferdinand.Malzer@s-itsolutions.at> wrote:

> Hello,
> I try to register a custom privileg with the following code.
>
>
>            session = repository.login(new SimpleCredentials(user,
> pwd.toCharArray()), workspace);
>            JackrabbitWorkspace jrws = (JackrabbitWorkspace)
> session.getWorkspace();
>            PrivilegeManager privMgr = jrws.getPrivilegeManager();
>            privMgr.registerPrivilege("gcms_role_chief", false, new
> String[] {});
>            session.save();
>
> The code seems to work fine (it runs with no exception).
> The next time when I try to access the repository I get the following
> exception:
>
> Exception in thread "main" javax.jcr.RepositoryException: Duplicate entry
> for custom privilege with name {}gcms_role_chief
>        at
> org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry$CustomPrivilegeStore.load(PrivilegeRegistry.java:1078)
>        at
> org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry$CustomPrivilegeStore.access$100(PrivilegeRegistry.java:1046)
>        at
> org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry.<init>(PrivilegeRegistry.java:165)
>        at
> org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:273)
>        at
> org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:589)
>        at
> at.spardat.jackrabbit.test.DumpRepository.main(DumpRepository.java:46)
>
> Does somebody know how I could register a custom privilege the right way?
>
> Thx in advance!
> ferry malzer
>

Mime
View raw message