Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the admin password in jackrabbit

Hi I am using embedded jackrabbit with tomcat. I wanted to change the default password for admin user to something else so it's secure and safe.

I saw in repository.xml place to update adminId to different id but it by defaults takes the same password as user id. so can anybody help in setting a password to different userid.

Thanks Manisha

like image 206
Manisha Mahawar Avatar asked May 11 '11 19:05

Manisha Mahawar


1 Answers

As far as I know, there is no simple method to change admin password in Jackarbbit. When using the DefaultLoginModule, passwords are stored in the "security" workspace in a protected property, so you cannot change them. But you can use Jackrabbit ACL API methods from Java. I was able to change the password with a simple java class, like this:

import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.core.TransientRepository;

import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import java.io.File;

public class Main {

    public static void main(String[] args) {
        Repository repository = new TransientRepository(new File("path_to_jackrabbit_home_dir"));
        try {
            Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

            UserManager userManager = ((JackrabbitSession) session).getUserManager();
            Authorizable authorizable = userManager.getAuthorizable("admin");

            ((User) authorizable).changePassword("newpassword");

            session.save();
            session.logout();
        } catch (RepositoryException e) {
            System.out.println("Auth error.");
            e.printStackTrace();
        }
    }
}

See also: http://jackrabbit.510166.n4.nabble.com/Doubt-with-username-and-password-td3173401.html

like image 96
Emanuele Avatar answered Sep 29 '22 11:09

Emanuele