Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Check if User belong to particular group

Avatar

Community Advisor

hey,

How can we check programatically if User belongs to a particluar group or not?

Thanks,

Himanshu

1 Accepted Solution

Avatar

Correct answer by
Level 10

Create a simple servlet and use User Manager API

  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

1 Reply

Avatar

Correct answer by
Level 10

Create a simple servlet and use User Manager API

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