code: public List<CmsRole> getRolesForResource(CmsDbContext dbc, CmsUser user, CmsResource resource) throws CmsException {
  
          // guest user has no role
          if (user.isGuestUser()) {
              return Collections.emptyList();
          }
  
          // try to read from cache
          String key = user.getId().toString() + resource.getRootPath();
          List<CmsRole> result = m_monitor.getCachedRoleList(key);
          if (result != null) {
              return result;
          }
          result = new ArrayList<CmsRole>();
  
          Iterator<CmsOrganizationalUnit> itOus = getResourceOrgUnits(dbc, resource).iterator();
          while (itOus.hasNext()) {
              CmsOrganizationalUnit ou = itOus.next();
  
              // read all roles of the current user
              List<CmsGroup> groups = new ArrayList<CmsGroup>(
                  getGroupsOfUser(
                      dbc,
                      user.getName(),
                      ou.getName(),
                      false,
                      true,
                      false,
                      dbc.getRequestContext().getRemoteAddress()));
              // check the roles applying to the given resource
              Iterator<CmsGroup> it = groups.iterator();
              while (it.hasNext()) {
                  CmsGroup group = it.next();
                  CmsRole givenRole = CmsRole.valueOf(group).forOrgUnit(null);
                  if (givenRole.isOrganizationalUnitIndependent() || result.contains(givenRole)) {
                      // skip already added roles
                      continue;
                  }
                  result.add(givenRole);
              }
          }
  
          result = Collections.unmodifiableList(result);
          m_monitor.cacheRoleList(key, result);
          return result;
      }
docs: Returns all roles the given user has for the given resource.<p>
  
  @param dbc the current database context
  @param user the user to check
  @param resource the resource to check the roles for
  
  @return a list of {@link CmsRole} objects
  
  @throws CmsException if something goes wrong