code: protected boolean hasRole(CmsRole role, List<CmsGroup> roles) {
  
          // iterates the role groups the user is in
          for (CmsGroup group : roles) {
              String groupName = group.getName();
              // iterate the role hierarchy
              for (String distictGroupName : role.getDistinctGroupNames()) {
                  if (distictGroupName.startsWith(CmsOrganizationalUnit.SEPARATOR)) {
                      // this is a ou independent role
                      // we need an exact match, and we ignore the ou parameter
                      if (groupName.equals(distictGroupName.substring(1))) {
                          return true;
                      }
                  } else {
                      // first check if the user has the role at all
                      if (groupName.endsWith(CmsOrganizationalUnit.SEPARATOR + distictGroupName)
                          || groupName.equals(distictGroupName)) {
                          // this is a ou dependent role
                          if (role.getOuFqn() == null) {
                              // ou parameter is null, so the user needs to have the role in at least one ou does not matter which
                              return true;
                          } else {
                              // the user needs to have the role in the given ou or in a parent ou
                              // now check that the ou matches
                              String groupFqn = CmsOrganizationalUnit.getParentFqn(groupName);
                              if (role.getOuFqn().startsWith(groupFqn)) {
                                  return true;
                              }
                          }
                      }
                  }
              }
          }
          return false;
      }
docs: Returns <code>true</code> if at least one of the given group names is equal to a group name
  of the given role in the given organizational unit.<p>
  
  This checks the given list against the group of the given role as well as against the role group
  of all parent roles.<p>
  
  If the organizational unit is <code>null</code>, this method will check if the
  given user has the given role for at least one organizational unit.<p>
  
  @param role the role to check
  @param roles the groups to match the role groups against
  
  @return <code>true</code> if at last one of the given group names is equal to a group name
  of this role