Creating User Profile in AEM

04 / May / 2015 by Shivani Garg 6 comments

Hello everyone,

In this blog, we will be focusing on how to create a user and user profiles in AEM.  It is generally needed when we create login and signup forms.

Depending on the use case, users can be created using:

i) In the UserManager API ,we can create a user, password under a specific group and provide permissions to them.

Sample code for UserManager API

ResourceResolver resolver=request.getResourceResolver();
Session session=request.getResourceResolver().adaptTo(Session.class);
UserManager userManager = resolver.adaptTo(UserManager.class);
Group group=userManager.createGroup(" Group Name");
User user=userManager.createUser("username",”pwd”);
if (! userManager.isAutoSave()) {;

ii) The other case is when you have to create a profile for user like username, password, group, email, address, contact etc. For this purpose AccountManager API can be used.

Sample Code for AccountManager API:

AccountManagerFactory accountManagerFactory;
private ResourceResolverFactory resolverFactory;
Map<String, Object> serviceParams = new HashMap<String, Object>();
serviceParams.put(SUBSERVICE, "signUpService");
Session session = resolver.adaptTo(Session.class);
AccountManager accountManager = accountManagerFactory.createAccountManager(session);
Map<String,RequestParameter[]> profilemap = new HashMap<>();
accountManager.getOrCreateAccount(“userName”, “password”, "admin", profilemap);


The Map can be populated in two ways:

a) If the value of the profile property is coming from form

[java] profilemap.put("email", request.getRequestParameters("email")); [/java]

//like email we can add additional attributes in profile

b) If the property is not in RequestParameters then—–

[java] String email=””;
profilemap.put(“email”,new RequestParameter[]{new Parameters(email) }); [/java]

//Create a POJO class to set values of additional attribute—-

[java]final class Parameters implements RequestParameter {
private final String parameter;
private Parameters(String parameter)
this.parameter = parameter;


If you want to see your created Users,Go to Crxde , /home/Users ……..You can see your users and profiles also.

So here you see how you can create users in AEM and create profiles for them.

Regards: Shivani Garg


comments (6)

  1. Jay Gandhi

    b) If the property is not in RequestParameters then—– – is not working for me. property is not get added in profilemap.

  2. Dhiraj Agarwal

    getting the following exception in aem 6.1 while using accountmanager API Cannot derive user name for bundle [505] and sub service signUpService

    I think you need to make changes in Apache Sling Service User Mapper Service to map a user to the subservice. I just dont know how to add the subservice here to a system user.

  3. Aniket

    Nice its helpfull can you tell how to set user and group folder and user node name…because it taking random value..can you help


Leave a Reply

Your email address will not be published. Required fields are marked *