Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to change AEM User password in java

Avatar

Level 3

Hello All,

               I need help to how to change the password of existing user AEM. I am implementing it in my java bundle package. So far I have done two ways

***********************************************************************************************

1.

            ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);   

            UserManager userManager = resourceResolver.adaptTo(UserManager.class);

            Session sessionrr = resourceResolver.adaptTo(Session.class);

            User user = (User) userManager.getAuthorizable(UserName);

             user.changePassword(NewPassword);

               if (!userManager.isAutoSave()) {

                    sessionrr.save();

            }

**********************************************************************************************

2.

          JackrabbitSession session1 = (JackrabbitSession) resourceResolver.adaptTo(javax.jcr.Session.class);   

          UserManager userManager = session1.getUserManager();   

          User user = (User) userManager.getAuthorizable(UserName);

          user.changePassword(NewPassword.toString());

          session1.save();

***************************************************************************************************

Issue:

Now with above 2 ways I am able to successfully changing the normal password But I am getting the issue in case if password containing special characters

like a password!@#.

ERROR which I am getting  as

org.apache.sling.auth.core.impl.SlingAuthenticator handleLoginFailure: Unable to authenticate null: UserId/Password mismatch.

403

Can someone help me with this?

Thanks

Qamar

1 Accepted Solution

Avatar

Correct answer by
Level 3

I would like to thank both of you people for the quick reply.

I have successfully resolved the issue with the help of below Adobe help link.

Adobe Experience Manager Help | Posting Special Characters to Adobe Experience Manager

The main cause is to encode/decode special characters in AEM.

Solution:

Encode -> While setting a password

String encodedString = URLEncoder.encode(passwordspecialchars, "UTF-8");

Decode -> Decode existing password while checking from AEM

String pwd = java.net.URLDecoder.decode(request.getParameter("password"), "UTF-8");

Thanks

Qamar

View solution in original post

3 Replies

Avatar

Employee Advisor

The official user API documentation does not specify any limitation related to special characters. Can you try setup debug logging and check which steps is failing?

Also, If there are any issues with the "changePassword" method, it will throw a "RepositoryException" not the one you shared.

For testing purpose, can you try using "admin" session and check if that works?

Avatar

Community Advisor

Could you please check this:

Why am I getting the error SlingAuthenticator handleLoginFailure

There could be a couple of reasons causing this issue. Kindly check for the below details:

1. Check to see if the user is correctly mapped in AEM.
2. See if correct Active Directory attributes are mapped in AEM.
3. See if it is happening for one user or all the users.
4. See the crx/quickstart logs for any entries.

Avatar

Correct answer by
Level 3

I would like to thank both of you people for the quick reply.

I have successfully resolved the issue with the help of below Adobe help link.

Adobe Experience Manager Help | Posting Special Characters to Adobe Experience Manager

The main cause is to encode/decode special characters in AEM.

Solution:

Encode -> While setting a password

String encodedString = URLEncoder.encode(passwordspecialchars, "UTF-8");

Decode -> Decode existing password while checking from AEM

String pwd = java.net.URLDecoder.decode(request.getParameter("password"), "UTF-8");

Thanks

Qamar