Search This Blog

About Me

Highly experienced in implementation and customization of Alfresco. More than 11 years of experience working on Alfresco, versions ranging from 2.x to 5.x. Successfully processed innovative and tailored CMS solutions to meet ever-changing business requirements for multiple clients. Role Includes : Experience in Alfresco Upgrades, SOLR migration, Proposals, Team Handling, Delivery, Content Migration, POC's etc.. Extensive experience in client co ordination, working on offshore-onshore model and project take over. Technical Expertise Includes : Java, JSP, Servlet, JSF, JavaScript, AJAX, Spring, SQL, Hibernate, Web Services(REST). Specialities Includes : Content Migration, Product Customization, Business CMS Solutions, Workflow, Project Transition.

Wednesday, December 23, 2009

Getting the list of groups the user is a member of..in Alfresco


Hello Guys,

Here is the code or just a function to find out the groups of which user is a member of.
Please find the below code, you can use it from any class just by passing ApplicationContext and the Group Name as a parameters.

public static boolean isCurrentUserInGroup(ApplicationContext context, String groupName)
{
// The authority service returns authorities with their AuthorityDAO type
// prefix prepended to the name, so we'll do that as well
groupName = AuthorityType.GROUP.getPrefixString() + groupName;
final ServiceRegistry serviceRegistry = (ServiceRegistry)
context.getBean(ServiceRegistry.SERVICE_REGISTRY);
// get the current user
String currentUserName =
serviceRegistry.getAuthenticationService().getCurrentUserName();
// get the list of groups this user is a member of
Set authorityList = serviceRegistry.getAuthorityService().getContainingAuthorities
(AuthorityType.GROUP, currentUserName, false);
System.out.println("authorityList--"+authorityList);
// look in the list to see if groupName is in there. If so, return true;
return authorityList.contains(groupName);
}



No comments: