Reading groups of a user
From OpenCms Wiki
This Code is for OpenCMS 7.0.3, beacuse some methods were deprecated in OpenCMS 7.0.4
[edit] Code Example
// Getting the cmsObject to find the groups of user
CmsObject cmsObject = cms.getCmsObject();
// Getting the groups of the users
List groups = cmsObject.getGroupsOfUser("Admin");
[edit] JSP Example
<%@ page import="java.util.List,
java.util.Iterator,
org.opencms.file.CmsObject,
org.opencms.jsp.CmsJspNavElement,
org.opencms.db.CmsDefaultUsers,
org.opencms.main.OpenCms,
org.opencms.file.CmsUser,
org.opencms.file.CmsGroup,
org.opencms.jsp.CmsJspLoginBean" %>
<jsp:useBean id="cms" class="org.opencms.jsp.CmsJspActionElement">
<% cms.init(pageContext, request, response); %>
</jsp:useBean>
<%
// This bean is used to check the loged user
CmsJspLoginBean loginBean= new CmsJspLoginBean(pageContext, request, response);
out.println("<b>Grupos para el usuario: " + loginBean.getUserName() + "</b><br>");
// Getting the cmsObject to find the groups of user
CmsObject cmsObject = cms.getCmsObject();
// Getting the groups of the users
List groups = cmsObject.getGroupsOfUser(loginBean.getUserName());
while (it.hasNext()) {
CmsGroup cmsGroup = (CmsGroup) it.next();
out.println( cmsGroup.getName() + "<br>");
}
%>
<pre>

