public List<CmsGroup> getGroupsOfUser(
        CmsDbContext dbc,
        String username,
        String ouFqn,
        boolean includeChildOus,
        boolean readRoles,
        boolean directGroupsOnly,
        String remoteAddress)
    throws CmsException {

        CmsUser user = readUser(dbc, username);
        String prefix = ouFqn + "_" + includeChildOus + "_" + directGroupsOnly + "_" + readRoles + "_" + remoteAddress;
        String cacheKey = m_keyGenerator.getCacheKeyForUserGroups(prefix, dbc, user);
        List<CmsGroup> groups = m_monitor.getCachedUserGroups(cacheKey);
        if (groups == null) {
            // get all groups of the user
            List<CmsGroup> directGroups = getUserDriver(dbc).readGroupsOfUser(
                dbc,
                user.getId(),
                readRoles ? "" : ouFqn,
                readRoles ? true : includeChildOus,
                remoteAddress,
                readRoles);
            Set<CmsGroup> allGroups = new HashSet<CmsGroup>();
            if (!readRoles) {
                allGroups.addAll(directGroups);
            }
            if (!directGroupsOnly) {
                if (!readRoles) {
                    // now get all parents of the groups
                    for (int i = 0; i < directGroups.size(); i++) {
                        CmsGroup parent = getParent(dbc, directGroups.get(i).getName());
                        while ((parent != null) && (!allGroups.contains(parent))) {
                            if (parent.getOuFqn().startsWith(ouFqn)) {
                                allGroups.add(parent);
                            }
                            // read next parent group
                            parent = getParent(dbc, parent.getName());
                        }
                    }
                }
            }
            if (readRoles) {
                // for each for role
                for (int i = 0; i < directGroups.size(); i++) {
                    CmsGroup group = directGroups.get(i);
                    CmsRole role = CmsRole.valueOf(group);
                    if (!includeChildOus && role.getOuFqn().equals(ouFqn)) {
                        allGroups.add(group);
                    }
                    if (includeChildOus && role.getOuFqn().startsWith(ouFqn)) {
                        allGroups.add(group);
                    }
                    if (directGroupsOnly || (!includeChildOus && !role.getOuFqn().equals(ouFqn))) {
                        // if roles of child OUs are not requested and the role does not belong to the requested OU don't include the role children
                        continue;
                    }
                    CmsOrganizationalUnit currentOu = readOrganizationalUnit(dbc, group.getOuFqn());
                    boolean readChildRoleGroups = true;
                    if (currentOu.hasFlagWebuser() && role.forOrgUnit(null).equals(CmsRole.ACCOUNT_MANAGER)) {
                        readChildRoleGroups = false;
                    }
                    if (readChildRoleGroups) {
                        // get the child roles
                        Iterator<CmsRole> itChildRoles = role.getChildren(true).iterator();
                        while (itChildRoles.hasNext()) {
                            CmsRole childRole = itChildRoles.next();
                            if (childRole.isSystemRole()) {
                                if (canReadRoleInOu(currentOu, childRole)) {
                                    // include system roles only
                                    try {
                                        allGroups.add(readGroup(dbc, childRole.getGroupName()));
                                    } catch (CmsDataAccessException e) {
                                        // should not happen, log error if it does
                                        LOG.error(e.getLocalizedMessage(), e);
                                    }
                                }
                            }
                        }
                    } else {
                        LOG.info("Skipping child role group check for web user OU " + currentOu.getName());
                    }
                    if (includeChildOus) {
                        // if needed include the roles of child ous
                        Iterator<CmsOrganizationalUnit> itSubOus = getOrganizationalUnits(
                            dbc,
                            readOrganizationalUnit(dbc, group.getOuFqn()),
                            true).iterator();
                        while (itSubOus.hasNext()) {
                            CmsOrganizationalUnit subOu = itSubOus.next();
                            // add role in child ou
                            try {
                                if (canReadRoleInOu(subOu, role)) {
                                    allGroups.add(readGroup(dbc, role.forOrgUnit(subOu.getName()).getGroupName()));
                                }
                            } catch (CmsDbEntryNotFoundException e) {
                                // ignore, this may happen while deleting an orgunit
                                if (LOG.isDebugEnabled()) {
                                    LOG.debug(e.getLocalizedMessage(), e);
                                }
                            }
                            // add child roles in child ous
                            Iterator<CmsRole> itChildRoles = role.getChildren(true).iterator();
                            while (itChildRoles.hasNext()) {
                                CmsRole childRole = itChildRoles.next();
                                try {
                                    if (canReadRoleInOu(subOu, childRole)) {
                                        allGroups.add(
                                            readGroup(dbc, childRole.forOrgUnit(subOu.getName()).getGroupName()));
                                    }
                                } catch (CmsDbEntryNotFoundException e) {
                                    // ignore, this may happen while deleting an orgunit
                                    if (LOG.isDebugEnabled()) {
                                        LOG.debug(e.getLocalizedMessage(), e);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // make group list unmodifiable for caching
            groups = Collections.unmodifiableList(new ArrayList<CmsGroup>(allGroups));
            if (dbc.getProjectId().isNullUUID()) {
                m_monitor.cacheUserGroups(cacheKey, groups);
            }
        }

        return groups;
    }
public List < CmsGroup > getGroupsOfUser ( CmsDbContext dbc , String username , String ouFqn , boolean includeChildOus , boolean readRoles , boolean directGroupsOnly , String remoteAddress ) throws CmsException { CmsUser user = readUser ( dbc , username ) ; String prefix = ouFqn + "_" + includeChildOus + "_" + directGroupsOnly + "_" + readRoles + "_" + remoteAddress ; String cacheKey = m_keyGenerator . getCacheKeyForUserGroups ( prefix , dbc , user ) ; List < CmsGroup > groups = m_monitor . getCachedUserGroups ( cacheKey ) ; if ( groups == null ) { List < CmsGroup > directGroups = getUserDriver ( dbc ) . readGroupsOfUser ( dbc , user . getId ( ) , readRoles ? "" : ouFqn , readRoles ? true : includeChildOus , remoteAddress , readRoles ) ; Set < CmsGroup > allGroups = new HashSet < CmsGroup > ( ) ; if ( ! readRoles ) { allGroups . addAll ( directGroups ) ; } if ( ! directGroupsOnly ) { if ( ! readRoles ) { for ( int i = 0 ; i < directGroups . size ( ) ; i ++ ) { CmsGroup parent = getParent ( dbc , directGroups . get ( i ) . getName ( ) ) ; while ( ( parent != null ) && ( ! allGroups . contains ( parent ) ) ) { if ( parent . getOuFqn ( ) . startsWith ( ouFqn ) ) { allGroups . add ( parent ) ; } parent = getParent ( dbc , parent . getName ( ) ) ; } } } } if ( readRoles ) { for ( int i = 0 ; i < directGroups . size ( ) ; i ++ ) { CmsGroup group = directGroups . get ( i ) ; CmsRole role = CmsRole . valueOf ( group ) ; if ( ! includeChildOus && role . getOuFqn ( ) . equals ( ouFqn ) ) { allGroups . add ( group ) ; } if ( includeChildOus && role . getOuFqn ( ) . startsWith ( ouFqn ) ) { allGroups . add ( group ) ; } if ( directGroupsOnly || ( ! includeChildOus && ! role . getOuFqn ( ) . equals ( ouFqn ) ) ) { continue ; } CmsOrganizationalUnit currentOu = readOrganizationalUnit ( dbc , group . getOuFqn ( ) ) ; boolean readChildRoleGroups = true ; if ( currentOu . hasFlagWebuser ( ) && role . forOrgUnit ( null ) . equals ( CmsRole . ACCOUNT_MANAGER ) ) { readChildRoleGroups = false ; } if ( readChildRoleGroups ) { Iterator < CmsRole > itChildRoles = role . getChildren ( true ) . iterator ( ) ; while ( itChildRoles . hasNext ( ) ) { CmsRole childRole = itChildRoles . next ( ) ; if ( childRole . isSystemRole ( ) ) { if ( canReadRoleInOu ( currentOu , childRole ) ) { try { allGroups . add ( readGroup ( dbc , childRole . getGroupName ( ) ) ) ; } catch ( CmsDataAccessException e ) { LOG . error ( e . getLocalizedMessage ( ) , e ) ; } } } } } else { LOG . info ( "Skipping child role group check for web user OU " + currentOu . getName ( ) ) ; } if ( includeChildOus ) { Iterator < CmsOrganizationalUnit > itSubOus = getOrganizationalUnits ( dbc , readOrganizationalUnit ( dbc , group . getOuFqn ( ) ) , true ) . iterator ( ) ; while ( itSubOus . hasNext ( ) ) { CmsOrganizationalUnit subOu = itSubOus . next ( ) ; try { if ( canReadRoleInOu ( subOu , role ) ) { allGroups . add ( readGroup ( dbc , role . forOrgUnit ( subOu . getName ( ) ) . getGroupName ( ) ) ) ; } } catch ( CmsDbEntryNotFoundException e ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( e . getLocalizedMessage ( ) , e ) ; } } Iterator < CmsRole > itChildRoles = role . getChildren ( true ) . iterator ( ) ; while ( itChildRoles . hasNext ( ) ) { CmsRole childRole = itChildRoles . next ( ) ; try { if ( canReadRoleInOu ( subOu , childRole ) ) { allGroups . add ( readGroup ( dbc , childRole . forOrgUnit ( subOu . getName ( ) ) . getGroupName ( ) ) ) ; } } catch ( CmsDbEntryNotFoundException e ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( e . getLocalizedMessage ( ) , e ) ; } } } } } } } groups = Collections . unmodifiableList ( new ArrayList < CmsGroup > ( allGroups ) ) ; if ( dbc . getProjectId ( ) . isNullUUID ( ) ) { m_monitor . cacheUserGroups ( cacheKey , groups ) ; } } return groups ; }
Returns the groups of an user filtered by the specified IP address.<p>

@param dbc the current database context
@param username the name of the user
@param ouFqn the fully qualified name of the organizational unit to restrict the result set for
@param includeChildOus include groups of child organizational units
@param readRoles if to read roles or groups
@param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect groups
@param remoteAddress the IP address to filter the groups in the result list

@return a list of <code>{@link CmsGroup}</code> objects

@throws CmsException if operation was not successful