Here is the process for getting the members of a group.
As per my requirement i did this, U may change lot in this :)
<%--
GroupUsersGettingBasedOnGroupId component.
GroupUsersGettingBasedOnGroupId comp
--%><%
%><%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" %>
<%@page contentType="text/html"
pageEncoding="utf-8"
import="com.day.text.Text,
org.slf4j.Logger,org.slf4j.LoggerFactory,
org.apache.jackrabbit.api.security.user.*,
org.apache.sling.api.resource.ResourceResolver,
javax.jcr.Session" %>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%
%><cq:defineObjects/>
<%!
private final Logger log = LoggerFactory.getLogger(getClass());
%>
<%
java.util.Iterator<Authorizable> users, groups ;
Object obj = null; User user = null;String id = null;int i=0;
String groupName="everyone";
UserManager userManager = resourceResolver.adaptTo(UserManager.class);
try{
final Group groupd = (Group) userManager.getAuthorizable(groupName);
%><font color="orange"><%=groupd%><br/><%
users = groupd.getMembers();
while(users.hasNext()){
obj = users.next();
if(!(obj instanceof User)){
continue;
}
user = (User)obj;
id = user.getID();
if(id.contains("@")){
i++;
%><br/>User <%=i%>:<%=id%><%
}
}
}catch(Exception e){
%><br/>Group "<%=groupName%>" Not Found<br/><%
}
%></font>
As per my requirement i did this, U may change lot in this :)
<%--
GroupUsersGettingBasedOnGroupId component.
GroupUsersGettingBasedOnGroupId comp
--%><%
%><%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" %>
<%@page contentType="text/html"
pageEncoding="utf-8"
import="com.day.text.Text,
org.slf4j.Logger,org.slf4j.LoggerFactory,
org.apache.jackrabbit.api.security.user.*,
org.apache.sling.api.resource.ResourceResolver,
javax.jcr.Session" %>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%
%><cq:defineObjects/>
<%!
private final Logger log = LoggerFactory.getLogger(getClass());
%>
<%
java.util.Iterator<Authorizable> users, groups ;
Object obj = null; User user = null;String id = null;int i=0;
String groupName="everyone";
UserManager userManager = resourceResolver.adaptTo(UserManager.class);
try{
final Group groupd = (Group) userManager.getAuthorizable(groupName);
%><font color="orange"><%=groupd%><br/><%
users = groupd.getMembers();
while(users.hasNext()){
obj = users.next();
if(!(obj instanceof User)){
continue;
}
user = (User)obj;
id = user.getID();
if(id.contains("@")){
i++;
%><br/>User <%=i%>:<%=id%><%
}
}
}catch(Exception e){
%><br/>Group "<%=groupName%>" Not Found<br/><%
}
%></font>
1 comment:
Thanks buddy
Post a Comment