I'm trying to programmatically create, disable and enable CQ5 user account. I'm able to create and disable the account but I don't know how to enable it again. Here's my code
org.apache.jackrabbit.api.security.user.UserManager um = request.getResourceResolver().adaptTo(org.apache.jackrabbit.api.security.user.UserManager.class); org.apache.jackrabbit.api.security.user.User user = um.createUser(login, password); user.disable("Waiting for moderation!"); Node node = request.getResourceResolver().getResource(user.getPath()).adaptTo(Node.class); node.setProperty("rep:disabled", (String)null); // This is how I'm trying to enable the account
but this doesn't work - I get exception that tells me that the property rep:disabled is not modifiable. How can I enable the disabled account?
BTW the code here is just for demonstration. In fact I have the disable and enable sections separated.
Thanks for any help.
EDIT the Exception
Exception javax.jcr.nodetype.ConstraintViolationException: Attempt to modify protected property rep:disabled of User 'testUser'
Solved! Go to Solution.
To enable a disabled user -- call disable again -- and pass null:
String myId = tmpUser.getID();
if (myId.equals("scottm") == true) // this is a disabled user
{
%><p>Enab;e - ID is <%= myId %>
<%
tmpUser.disable(null) ;
%></p><%
}
To enable a disabled user -- call disable again -- and pass null:
String myId = tmpUser.getID();
if (myId.equals("scottm") == true) // this is a disabled user
{
%><p>Enab;e - ID is <%= myId %>
<%
tmpUser.disable(null) ;
%></p><%
}
I am looking into this with code. The API reference says:
disable(String reason)
Disable this user thus preventing future login if the reason
is a non-null String.
Have you tried calling this method again and pass a null for the reason? This will set a null again.
I am not sure why the author of this API did not create an enable method.
Is this stil the case, do we have an "enable" method to enable a disabled user?
I cannot see it in the API: https://jackrabbit.apache.org/api/2.8/index.html?org/apache/jackrabbit/api/security/user/User.html
Views
Replies
Total Likes
Hi ksuren
You still have to call disable(null) to enable a disabled user. It is mentioned in the api documentation with the following sentence:
Regards.
Views
Replies
Total Likes