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?
Solved! Go to Solution.
Views
Replies
Total Likes
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.
see if you can do anything with the disabled user with a null parameter.
-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.
see if you can do anything with the disabled user with a null parameter.
-Sravan
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
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.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies