Expand my Community achievements bar.

SOLVED

How to disable the user using cURL?

Avatar

Former Community Member

I have tried below one but its not working:

curl -u admin:admin -Frep:disabled=true http://localhost:4502/home/users/t/testuser.rw.html

getting below error message:

javax.jcr.nodetype.ConstraintViolationException: Unable to perform operation. Node is protected.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Aditi,

Have you tried creating a custom servlet and on post request:

@SuppressWarnings("serial") @Component(immediate = true, metatype = false) @Service(value = javax.servlet.Servlet.class) @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Custom User Manager"), @Property(name = Constants.SERVICE_VENDOR, value = OsgiServiceProperties.SERVICE_VENDOR), @Property(name = "sling.servlet.selectors", value = { "user" }), @Property(name = "sling.servlet.extensions", value = { "api" }) }) public class UserManagementAPI extends SlingAllMethodsServlet { @Reference private ResolverManager rmanager; @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { final ResourceResolver resolver = rmanager.getCurrentOrCreateNew().getResolver(); final UserManager userManager = resolver.adaptTo(UserManager.class); final Authorizable authorizable = userManager.get(request.getParameter("userPath")); // the path in the repo where the user account is stored final User user = authorizable.adaptTo(User.class); // adapt authorisable to actual user in order to access disable user.disable("Does not follow compliance regulations..."); // remember to have a reason } }

Peter

View solution in original post

5 Replies

Avatar

Level 10

Here is a great community article written by an AEM community member - Yogesh  - that talks about how to perform user operations using Curl:

http://www.wemblog.com/2012/03/how-to-do-user-management-using-post.html

Avatar

Former Community Member

Thanks for your reply :)
But there is no command to disable the user .....

Avatar

Level 10

The property rep:disabled is set on an authorizable node (rep:User or rep:Group) that user or group becomes disabled. However this property is protected and you cannot set it directly.Though I am not sure is security API provide that option. You can try with User.setProperty().

Avatar

Former Community Member

Thanks for the reply :)
I want to do it using  curl command, so that i can disable any number of users with less efforts 

Avatar

Correct answer by
Community Advisor

Hi Aditi,

Have you tried creating a custom servlet and on post request:

@SuppressWarnings("serial") @Component(immediate = true, metatype = false) @Service(value = javax.servlet.Servlet.class) @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Custom User Manager"), @Property(name = Constants.SERVICE_VENDOR, value = OsgiServiceProperties.SERVICE_VENDOR), @Property(name = "sling.servlet.selectors", value = { "user" }), @Property(name = "sling.servlet.extensions", value = { "api" }) }) public class UserManagementAPI extends SlingAllMethodsServlet { @Reference private ResolverManager rmanager; @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { final ResourceResolver resolver = rmanager.getCurrentOrCreateNew().getResolver(); final UserManager userManager = resolver.adaptTo(UserManager.class); final Authorizable authorizable = userManager.get(request.getParameter("userPath")); // the path in the repo where the user account is stored final User user = authorizable.adaptTo(User.class); // adapt authorisable to actual user in order to access disable user.disable("Does not follow compliance regulations..."); // remember to have a reason } }

Peter