Programatic user creation in AEM | Community
Skip to main content
Murali89
Level 2
October 16, 2015
Solved

Programatic user creation in AEM

  • October 16, 2015
  • 2 replies
  • 1106 views

I am using the below code to create users under /home/users/myproject

Session session = request.getResourceResolver().adaptTo(Session.class);
        //Session session2  = request.get 
        JackrabbitSession jsession= (JackrabbitSession) session;
        UserManager usermanager;
        final String  userName = "testincdscdcg2ss2dcd3";
        try {
            usermanager = (UserManager) js.getUserManager();
            User user = usermanager.createUser("Mytestissng2dcddcdxsx", "dcdMyTestingsvdfcdv2", new Principal() {

                        public String getName() {
                            return userName;
                        }
                    }, "/home/users/myproject");
            jsession.save();

 

But it is creating users with strange node names, Attached is the screen shot. Even if i create a user from AEM useradmin UI it creates users with similar strange node names. 

Just wondering how does geometrixx has user nodes with proper names under /home/users/geometrixx.

Also once the new user node is created under my project path i.e  /home/users/myproject/ppXn-NUF084WwcxjAD9 i need to add a profile node and add some properties using below code

String NodePath = userManager.getAuthorizable("Mytestissng2dcddcdxsx ").getPath()

Node node = session.getNode(NodePath );

/* Add profile node and add properies to profile node like profileNode.setProperty("timeNow", System.currentTimeMillis()); */

 

but userManager.getAuthorizable("Mytestissng2dcddcdxsx ").getPath(); is saying The method getPath() is undefined for the type Authorizable. Is there a way i can get the node name from usermanager api by passing the username of the user as a parameter ?

As i don't have control over the node name that is getting created i am not able frame a path like " /home/users/myproject/+nodenameoftheuser " and then test if one such node exists and get that node using the path Session.getNode( " /home/users/myproject/+nodenameoftheuser ") 

Any help is appreciated.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Lokesh_Shivalingaiah

It is the actual behavior of AEM in its latest versions. So you will have to use queries to get the path

2 replies

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
October 16, 2015

It is the actual behavior of AEM in its latest versions. So you will have to use queries to get the path

Adobe Employee
October 16, 2015