Is it possible to have one page. check user group and show different content depending of CUG | Community
Skip to main content
Xena_bcn
Level 5
November 23, 2015
Solved

Is it possible to have one page. check user group and show different content depending of CUG

  • November 23, 2015
  • 5 replies
  • 910 views

hi there

I read the Adobe CQ documentation about CUG, it is saying to create links within an non-protected page. but I would like to have inside JSP code of the page a condition to check user group and show different content. is it possible?

 

Linking To The Realm

Since the target of any links to the CUG Realm are not visible to the anonymous user, the linkchecker will remove such links.

To avoid this, it is advisable to create non-protected redirect pages that point to pages within the CUG Realm. The navigation entries are then rendered without causing the linkchecker any problems. Only when actually accessing the redirect page will the user be redirected inside the CUG Realm - after successfully providing their login credentials.

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Lokesh_Shivalingaiah

get the session user and use the memberOf() method in the Authorizable API to find the groups of the logged in user and build logic.

ex code

  Session session = resourceResolver.adaptTo(Session.class); UserManager userManager = resourceResolver.adaptTo(UserManager.class); /* to get the current user */ Authorizable auth = userManager.getAuthorizable(session.getUserID()); /* to get the groups it is member of */ Iterator<Group> groups = auth.memberOf(); 

5 replies

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
November 23, 2015

get the session user and use the memberOf() method in the Authorizable API to find the groups of the logged in user and build logic.

ex code

  Session session = resourceResolver.adaptTo(Session.class); UserManager userManager = resourceResolver.adaptTo(UserManager.class); /* to get the current user */ Authorizable auth = userManager.getAuthorizable(session.getUserID()); /* to get the groups it is member of */ Iterator<Group> groups = auth.memberOf(); 
joerghoh
Adobe Employee
Adobe Employee
November 24, 2015

I would not use the code to decide if you should show certain content or not. Rather use permissions and handle the exception if the user is not allowed to read the content. This gives you more flexibility, as you just need to adjust ACLs/CUGs, but never any config of groups, which is then evaluated by your code.

kind regards,
Jörg

Adobe Employee
November 24, 2015

What is your use case? What kind of content is it you wish to switch for users?

Regards,

Opkar

Xena_bcn
Xena_bcnAuthor
Level 5
November 25, 2015

hi Opkar

thanks for getting back

So the client web site has a CUG page which redirects to login,

then the main page of that section has an image and a link to the another page, but depending of the group of the logged user, it should be shown 1 or another.  Same for another menu.

Currently this main page has 4 versions.

So client asked to have just one page.

 

How do you understand this now?

Let me know.

Thanks

Xena_bcn
Xena_bcnAuthor
Level 5
November 25, 2015

hi

i created 1 container component and in it's bean put this code to check logged user groups and return a boolean.

then in JSP checked it and depending on this value div was there or not. So it is solved now.

 

thank you for your help.

 

Xena