Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Is there a way to enable a disabled user?

Avatar

Level 2

Hello there, I'm actually creating users via UserManager's API and when I create them i set user.disable() (from User's interface). Why isn't there a method that does the opposite? I want to enable the disabled user, what should I do? Is it possible that no one ever thought to make a enable method?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @lezzowski1 ,

 

as per the documentation, when you use the disable method, if you leave the reason parameter as null, the user can still be accessible through UserManager.getAuthorizable(String). If the reason parameter is a non-null string, the user can no longer be able to log in further. 

 

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/org/apache/jackrabbit...

 

see if you can do anything with the disabled user with a null parameter.

-Sravan

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @lezzowski1 ,

 

as per the documentation, when you use the disable method, if you leave the reason parameter as null, the user can still be accessible through UserManager.getAuthorizable(String). If the reason parameter is a non-null string, the user can no longer be able to log in further. 

 

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/org/apache/jackrabbit...

 

see if you can do anything with the disabled user with a null parameter.

-Sravan

Avatar

Level 6

Hi @lezzowski1 ,

 

@B_Sravan is right.

 

reason - String describing the reason for disable this user or null if the user account should be enabled again.

 

If you pass reason as null you should be able to enable the user again.

 

Thanks,

Ram

Avatar

Level 5

Here is the sample logic to enable the user again.

ResourceResolver resourceResolver = // obtain a ResourceResolver object
UserManager userManager = resourceResolver.adaptTo(UserManager.class);
String userId = "user123"; // ID of the user to enable
User user = (User) userManager.getAuthorizable(userId);
if (user != null && !user.isEnabled()) {
    user.disable(null); // Enable the user
    Session session = user.getSession();
    session.save();
}

Hope this is helpful.