Is there a way to enable a disabled user? | Community
Skip to main content
Level 2
February 18, 2023
Solved

Is there a way to enable a disabled user?

  • February 18, 2023
  • 2 replies
  • 1514 views

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?

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 B_Sravan

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/api/security/user/User.html#disable-java.lang.String-

 

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

-Sravan

2 replies

B_Sravan
Community Advisor
B_SravanCommunity AdvisorAccepted solution
Community Advisor
February 18, 2023

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/api/security/user/User.html#disable-java.lang.String-

 

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

-Sravan

rampai
Community Advisor
Community Advisor
February 18, 2023

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

Level 4
February 19, 2023

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.