Is there a way to enable a disabled user? | Community
Skip to main content
Level 2
Feb 18, 2023 1:05 AM UTC
Solved

Is there a way to enable a disabled user?

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.
B_Sravan
B_SravanAccepted solution
New Participant
Feb 18, 2023 7:48 AM UTC

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

3 replies

Level 4
Feb 19, 2023 1:52 PM UTC

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.

Translate
B_Sravan
B_SravanAccepted solution
New Participant
Feb 18, 2023 7:48 AM UTC

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

Translate
rampai
Level 1
Feb 18, 2023 8:38 AM UTC

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

Translate