Expand my Community achievements bar.

SOLVED

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

Avatar

Level 6

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.

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 10

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(); 

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

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(); 

Avatar

Employee Advisor

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

Avatar

Employee

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

Regards,

Opkar

Avatar

Level 6

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

Avatar

Level 6

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