Expand my Community achievements bar.

SOLVED

Programatic user creation in AEM

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

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