You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by simer anand <si...@gmail.com> on 2009/09/14 08:02:21 UTC

how can i add new users and store them in repository

Hello Users,

                   I have gone through the threads in Nabble's Jackrabbit
forum but didn't got my answer.
                  
                   What i' m doing is i recently made jackrabbit repository
authenticate using Jaas Authentication and which now prevent anonymous
access and then after searching and googling through the Nabble's Jackrabbit
forum i need to ask you how i can add a facility to my repository that would
enable adding new users and thus storing them and further some one who
created those users can authenticate themselves for viewing/reading/writing 
the repository as per the privileges. 


Thank you in advance for any following mesage.
simer
-- 
View this message in context: http://www.nabble.com/how-can-i-add-new-users-and-store-them-in-repository-tp25430694p25430694.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: how can i add new users and store them in repository

Posted by simer anand <si...@gmail.com>.
Hello Amjed,

                            Thanks for replying.

                             I have being trying what ever you guided to me
about UserManager class and adding users.

I have done a bit on this and this time facing some problem that is i
created a java class which implements the UserManager but i' m not bale to
make class file of it/compile it.  I  h've attached the java file with the
mail  please have a look. I'm new to this & i' m sure i must have missed
something out of this.

Following are the bugs.

[sda_tr1@cad44 ~/Desktop]$ javac SuserManager.java
SuserManager.java:12: cannot find symbol
symbol  : variable userId
location: class SuserManager
       if(this.userService.exists(userId)){
                                  ^
SuserManager.java:12: cannot find symbol
symbol  : variable userService
location: class SuserManager
       if(this.userService.exists(userId)){
              ^
SuserManager.java:13: cannot find symbol
symbol  : constructor AuthorizableExistsException()
location: class
org.apache.jackrabbit.api.security.user.AuthorizableExistsException
           throw new AuthorizableExistsException();
                 ^
SuserManager.java:16: cannot find symbol
symbol  : variable userId
location: class SuserManager
           user = this.userService.create(userId,password);
                                          ^
SuserManager.java:16: cannot find symbol
symbol  : variable userService
location: class SuserManager
           user = this.userService.create(userId,password);
                      ^
5 errors


These were the bugs and i have one more question in my mind that is  if we
are able to imply this custom UserManager class then  what would be the
changes in the behaviour of the reopsitory.
Means we have to put some user and password string in the repository.xml and
after that we can use only those usernames and passwords for accessing the
repository.

Thanks
simer

Re: how can i add new users and store them in repository

Posted by amjedonline <am...@gmail.com>.

Hi Simer Anand,
Below is the possible code that makes things a little clear for you:

    //UserService is any userservice/dao, that creates user object in your
database ?  
    @Override
    public User createUser(String userID, String password) throws
AuthorizableExistsException, RepositoryException {
        User user = null;
        if(this.userService.exists(userId)){
            throw new AuthorizableExistsException();
        }
        try{
            user = this.userService.create(userId,password)
        }catch(Exception e){
            throw new RepositoryException(e.getMessage());
        }

        return user;
    }

    // You can ignore intermediate path if it doesnt make any sense in your
case
    @Override
    public User createUser(String userID, String password, Principal
principal, String intermediatePath)
            throws AuthorizableExistsException, RepositoryException {

        return createUser(userID, password);
    }


 Ignore principal, unless you are using the userId as principal.

-Amjed




simer anand wrote:
> 
> Hello amjedonline and users,
> 
>                                           I went through the source code
> of the UserManger class that is
> org.apache.jackrabbit.api.security.user.UserManager and found some methods
> as create user(String UserId , String Password) but being doing it first
> time don't know how i can configure it . So  any one who can provide me
> with some sample programs.
> 
> 
>  User createUser(String userID, String password) throws
> AuthorizableExistsException, RepositoryException;
>   /**
>      * Creates an User for the given userID that authenitcates with the
> given
>      * {@link javax.jcr.Credentials Credentials} and returns the specified
>      * Principal upon {@link User#getPrincipal()}. If the implementation
> is not
>      * able to deal with the <code>itermediatePath</code> that parameter
> should
>      * be ignored.
>      * Except for the <code>itermediatePath</code>, neither of the
> specified
>      * parameters can be <code>null</code>.
>      *
>      * @param userID
>      * @param password
>      * @param principal
>      * @param intermediatePath
>      * @return The new <code>User</code>.
>      * @throws AuthorizableExistsException in case the given userID is
> already
>      * in use or another Authorizable with the same principal name exists.
>      * @throws RepositoryException If the current Session is
>      * not allowed to create users or some another error occurs.
>      */
> 
> 
> I' m stuck in this issue please help 
> Thanks 
> simer 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-can-i-add-new-users-and-store-them-in-repository-tp25430694p25469191.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: how can i add new users and store them in repository

Posted by simer anand <si...@gmail.com>.
Hello amjedonline and users,

                                          I went through the source code of
the UserManger class that is
org.apache.jackrabbit.api.security.user.UserManager and found some methods
as create user(String UserId , String Password) but being doing it first
time don't know how i can configure it . So  any one who can provide me with
some sample programs.


 User createUser(String userID, String password) throws
AuthorizableExistsException, RepositoryException;
  /**
     * Creates an User for the given userID that authenitcates with the
given
     * {@link javax.jcr.Credentials Credentials} and returns the specified
     * Principal upon {@link User#getPrincipal()}. If the implementation is
not
     * able to deal with the <code>itermediatePath</code> that parameter
should
     * be ignored.
     * Except for the <code>itermediatePath</code>, neither of the specified
     * parameters can be <code>null</code>.
     *
     * @param userID
     * @param password
     * @param principal
     * @param intermediatePath
     * @return The new <code>User</code>.
     * @throws AuthorizableExistsException in case the given userID is
already
     * in use or another Authorizable with the same principal name exists.
     * @throws RepositoryException If the current Session is
     * not allowed to create users or some another error occurs.
     */


I' m stuck in this issue please help 
Thanks 
simer 

-- 
View this message in context: http://www.nabble.com/how-can-i-add-new-users-and-store-them-in-repository-tp25430694p25468254.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: how can i add new users and store them in repository

Posted by amjedonline <am...@gmail.com>.
Hi Simer,

Jakckrabbit has o.a.j.api.security.user.UserManager interface to implement
your custom usermanager.

But the irony is that one cannot configure jackrabbit to use custom
usermanager ( hypothetical <UserManager class=".."> :-) ).

however you can achieve this by writing your own SecurityManager ( which can
be configured with  <SecurityManager/>), and use the custom usermanager in
the securitymanager.

please look into the code to get an idea as to how you need to implement
UserManager and SecurityManager.


Note - consequently you have to write PrincipalProvider, as the
DefaultPrincipalProvider is implemented with UserManagerImpl composition and
not by interfacin through UserManager ( which I  assume has  some scope of
re-factoring ) 

This approach seems very dirty, but I cannot think of any cleaner way to
achieve this.


Jukka/Melissa - please correct me If am wrong.

-Amjed



simer anand wrote:
> 
> Hello Users and amjedonline,
> 
>  how i can add a facility to my repository that would enable adding new
>> users and thus storing them
>> -You have to implement your own UserManager, which probably creates user
>> in
>> your database.
>>
> 
> Any reference how i can do that.
> 
>>
>> and further some one who created those users can authenticate themselves
>> for
>> viewing/reading/writing  the repository as per the privileges.
>>
>> -Not sure, looks like you have to implement SecurityManager. Look into
>> the
>> DefaultSecurityManager, you ll get the answer.
>>
>>
>>
> 
> Thanks for your reply,
> Simer
> 
> 

-- 
View this message in context: http://www.nabble.com/how-can-i-add-new-users-and-store-them-in-repository-tp25430694p25432833.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: how can i add new users and store them in repository

Posted by simer anand <si...@gmail.com>.
Hello Users and amjedonline,

 how i can add a facility to my repository that would enable adding new
> users and thus storing them
> -You have to implement your own UserManager, which probably creates user in
> your database.
>

Any reference how i can do that.

>
> and further some one who created those users can authenticate themselves
> for
> viewing/reading/writing  the repository as per the privileges.
>
> -Not sure, looks like you have to implement SecurityManager. Look into the
> DefaultSecurityManager, you ll get the answer.
>
>
>

Thanks for your reply,
Simer

Re: how can i add new users and store them in repository

Posted by amjedonline <am...@gmail.com>.

 how i can add a facility to my repository that would enable adding new
users and thus storing them 
-You have to implement your own UserManager, which probably creates user in
your database.

and further some one who created those users can authenticate themselves for
viewing/reading/writing  the repository as per the privileges. 

-Not sure, looks like you have to implement SecurityManager. Look into the
DefaultSecurityManager, you ll get the answer.



simer anand wrote:
> 
> Hello Users,
> 
>                    I have gone through the threads in Nabble's Jackrabbit
> forum but didn't got my answer.
>                   
>                    What i' m doing is i recently made jackrabbit
> repository authenticate using Jaas Authentication and which now prevent
> anonymous access and then after searching and googling through the
> Nabble's Jackrabbit forum i need to ask you how i can add a facility to my
> repository that would enable adding new users and thus storing them and
> further some one who created those users can authenticate themselves for
> viewing/reading/writing  the repository as per the privileges. 
> 
> 
> Thank you in advance for any following mesage.
> simer
> 

-- 
View this message in context: http://www.nabble.com/how-can-i-add-new-users-and-store-them-in-repository-tp25430694p25432174.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.