public void removeUserFromGroup(CmsDbContext dbc, String username, String groupname, boolean readRoles)
    throws CmsException, CmsIllegalArgumentException, CmsDbEntryNotFoundException, CmsSecurityException {

        CmsGroup group = readGroup(dbc, groupname);
        //check if group exists
        if (group == null) {
            // the group does not exists
            throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_GROUP_1, groupname));
        }
        if (group.isVirtual() && !readRoles) {
            // if removing a user from a virtual role treat it as removing the user from the role
            removeUserFromGroup(dbc, username, CmsRole.valueOf(group).getGroupName(), true);
            return;
        }
        if (group.isVirtual()) {
            // this is an hack so to prevent a unlimited recursive calls
            readRoles = false;
        }
        if ((readRoles && !group.isRole()) || (!readRoles && group.isRole())) {
            // we want a role but we got a group, or the other way
            throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_GROUP_1, groupname));
        }

        // test if this user is existing in the group
        if (!userInGroup(dbc, username, groupname, readRoles)) {
            // user is not in the group, throw exception
            throw new CmsIllegalArgumentException(
                Messages.get().container(Messages.ERR_USER_NOT_IN_GROUP_2, username, groupname));
        }

        CmsUser user = readUser(dbc, username);
        //check if the user exists
        if (user == null) {
            // the user does not exists
            throw new CmsIllegalArgumentException(
                Messages.get().container(Messages.ERR_USER_NOT_IN_GROUP_2, username, groupname));
        }

        if (readRoles) {
            CmsRole role = CmsRole.valueOf(group);
            // update virtual groups
            Iterator<CmsGroup> it = getVirtualGroupsForRole(dbc, role).iterator();
            while (it.hasNext()) {
                CmsGroup virtualGroup = it.next();
                if (userInGroup(dbc, username, virtualGroup.getName(), false)) {
                    // here we say readroles = true, to prevent an unlimited recursive calls
                    removeUserFromGroup(dbc, username, virtualGroup.getName(), true);
                }
            }
        }
        getUserDriver(dbc).deleteUserInGroup(dbc, user.getId(), group.getId());

        // flush relevant caches
        if (readRoles) {
            m_monitor.flushCache(CmsMemoryMonitor.CacheType.HAS_ROLE, CmsMemoryMonitor.CacheType.ROLE_LIST);
        }
        m_monitor.flushCache(CmsMemoryMonitor.CacheType.USERGROUPS, CmsMemoryMonitor.CacheType.USER_LIST);

        if (!dbc.getProjectId().isNullUUID()) {
            // user modified event is not needed
            return;
        }
        // fire user modified event
        Map<String, Object> eventData = new HashMap<String, Object>();
        eventData.put(I_CmsEventListener.KEY_USER_ID, user.getId().toString());
        eventData.put(I_CmsEventListener.KEY_USER_NAME, user.getName());
        eventData.put(I_CmsEventListener.KEY_GROUP_ID, group.getId().toString());
        eventData.put(I_CmsEventListener.KEY_GROUP_NAME, group.getName());
        eventData.put(
            I_CmsEventListener.KEY_USER_ACTION,
            I_CmsEventListener.VALUE_USER_MODIFIED_ACTION_REMOVE_USER_FROM_GROUP);
        OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_USER_MODIFIED, eventData));

    }
public void removeUserFromGroup ( CmsDbContext dbc , String username , String groupname , boolean readRoles ) throws CmsException , CmsIllegalArgumentException , CmsDbEntryNotFoundException , CmsSecurityException { CmsGroup group = readGroup ( dbc , groupname ) ; if ( group == null ) { throw new CmsDbEntryNotFoundException ( Messages . get ( ) . container ( Messages . ERR_UNKNOWN_GROUP_1 , groupname ) ) ; } if ( group . isVirtual ( ) && ! readRoles ) { removeUserFromGroup ( dbc , username , CmsRole . valueOf ( group ) . getGroupName ( ) , true ) ; return ; } if ( group . isVirtual ( ) ) { readRoles = false ; } if ( ( readRoles && ! group . isRole ( ) ) || ( ! readRoles && group . isRole ( ) ) ) { throw new CmsDbEntryNotFoundException ( Messages . get ( ) . container ( Messages . ERR_UNKNOWN_GROUP_1 , groupname ) ) ; } if ( ! userInGroup ( dbc , username , groupname , readRoles ) ) { throw new CmsIllegalArgumentException ( Messages . get ( ) . container ( Messages . ERR_USER_NOT_IN_GROUP_2 , username , groupname ) ) ; } CmsUser user = readUser ( dbc , username ) ; if ( user == null ) { throw new CmsIllegalArgumentException ( Messages . get ( ) . container ( Messages . ERR_USER_NOT_IN_GROUP_2 , username , groupname ) ) ; } if ( readRoles ) { CmsRole role = CmsRole . valueOf ( group ) ; Iterator < CmsGroup > it = getVirtualGroupsForRole ( dbc , role ) . iterator ( ) ; while ( it . hasNext ( ) ) { CmsGroup virtualGroup = it . next ( ) ; if ( userInGroup ( dbc , username , virtualGroup . getName ( ) , false ) ) { removeUserFromGroup ( dbc , username , virtualGroup . getName ( ) , true ) ; } } } getUserDriver ( dbc ) . deleteUserInGroup ( dbc , user . getId ( ) , group . getId ( ) ) ; if ( readRoles ) { m_monitor . flushCache ( CmsMemoryMonitor . CacheType . HAS_ROLE , CmsMemoryMonitor . CacheType . ROLE_LIST ) ; } m_monitor . flushCache ( CmsMemoryMonitor . CacheType . USERGROUPS , CmsMemoryMonitor . CacheType . USER_LIST ) ; if ( ! dbc . getProjectId ( ) . isNullUUID ( ) ) { return ; } Map < String , Object > eventData = new HashMap < String , Object > ( ) ; eventData . put ( I_CmsEventListener . KEY_USER_ID , user . getId ( ) . toString ( ) ) ; eventData . put ( I_CmsEventListener . KEY_USER_NAME , user . getName ( ) ) ; eventData . put ( I_CmsEventListener . KEY_GROUP_ID , group . getId ( ) . toString ( ) ) ; eventData . put ( I_CmsEventListener . KEY_GROUP_NAME , group . getName ( ) ) ; eventData . put ( I_CmsEventListener . KEY_USER_ACTION , I_CmsEventListener . VALUE_USER_MODIFIED_ACTION_REMOVE_USER_FROM_GROUP ) ; OpenCms . fireCmsEvent ( new CmsEvent ( I_CmsEventListener . EVENT_USER_MODIFIED , eventData ) ) ; }
Removes a user from a group.<p>

@param dbc the current database context
@param username the name of the user that is to be removed from the group
@param groupname the name of the group
@param readRoles if to read roles or groups

@throws CmsException if operation was not successful
@throws CmsIllegalArgumentException if the given user was not member in the given group
@throws CmsDbEntryNotFoundException if the given group was not found
@throws CmsSecurityException if the given user was <b>read as 'null' from the database</b>

@see #addUserToGroup(CmsDbContext, String, String, boolean)