PITS Blog
  • Home
  • Services
    • Dedicated team Have your own development team at our location in Kerala, India. We tailor our employees individually to your project.
    • Website & web shop Get into the online business and sell your products around the clock. Or convince yourself with a modern website on desktop and mobile devices.
    • Application development We develop very individual web or software applications for you for a wide variety of needs.
    • Hybrid or native iOS & Android Apps Online business is often done on the go today, and the trend is rising. Invest now and make your software mobile-compatible.
  • Credentials
  • Technology
  • Process
  • About us
  • Contact
  • White papers
  • Jobs
  • Blog
  • Startups
�
Avatar

How to create a new user in CQ5 using API’s.

By kiran on October, 31 2014
demo post

By Visakh R N

WordPress and .NET

By Priyanka K

Roadmap to become a DevOps Engineer

By Francis Varghese

Gutenberg - More Than Just An Editor

By Priyanka K

Create a new user in CQ5 using API’s.

 

Assume that our CQ system is developed for a Manufacturer and they has to deal with different Dealers, all of whom need to get access to the site. For this purpose all dealers required a login credentials and permission to access their CRX system. This can be achieved by following the steps below.

Step 1 : Create Username and password using your own logic.

Step 2 : Create UserManager Object.

org.apache.jackrabbit.api.security.user.UserManager;
UserManager userManager = resolver.adaptTo(UserManager.class);

Step 3: Create User with username and password. Before creating a User we can create a group (for example: Dealer Group), where we can add all the dealers (Users) .By providing permissions to the group ,all the users in the group will get the same permissions.

3.1 Create a Group and User

Group group=userManager.createGroup("Dealer Group");
User user = userManager.createUser(name, password);

3.2 Add Users to Group.
Authorizable authUser = userManager.getAuthorizable(user.getID());
group.addMember(authUser);

Step 4 : Provide permissions to Group.

AccessControlManager accCtrlMgr = session.getAccessControlManager();
JackrabbitSession jcrSession = (JackrabbitSession) session;
PrincipalManager principalMgr = jcrSession.getPrincipalManager();
Principal groupPrincipal = principalMgr.getPrincipal(group);
Privilege[] privileges = new Privilege[] { accCtrlMgr.privilegeFromName(Privilege.JCR_ALL) };

Step 5 : Set privileges to particular path

AccessControlList acl = accCtrlMgr.getApplicablePolicies(path).nextAccessControlPolicy();
acl.addAccessControlEntry(groupPrincipal, rootNodePrivilege);
accCtrlMgr.setPolicy(path, acl);
session.save();

We'd love to hear from you.

Contact us

Switzerland
thomas(at)pitsolutions(dot)com
+41 (0) 43 558 4360

India
enquiries(at)pitsolutions(dot)com
+91 (0) 471 270 0615 / 715

UAE
mohammed(at)pitsolutions(dot)com
+971 (0) 4 359 8610

USA
arnab(at)pitsolutions(dot)com
+1 (0) 703 945 8076

Copyright © 2019PIT Solutions AG.An ISO 9001:2015 certified company. All Rights Reserved

SCROLL TO TOP