Removing user from a group

	

	IInfoStore boInfoStore = null;
	IInfoStore boInfoStore2 = null;
	IInfoObject boIInfoObject = null;
	IInfoObject boIInfoObject2 = null;
	IInfoObjects boInfoObjects = null;
	IInfoObjects boInfoObjects2 = null;
	SDKException sdkException = null;
	IEnterpriseSession boEnterpriseSession = null;
	IPluginMgr boPluginMgr;
	IPluginInfo boPluginInfo;
	IUser boCurUser = null;
	IUserGroup boGroup = null;
	IUserAliases allias = null;

boEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(
					USERNAME, PASSWORD, SERVER, AUTHTYPE);
			boInfoStore = (IInfoStore) boEnterpriseSession.getService("",
					"InfoStore");
	boEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(
					USERNAME, PASSWORD, SERVER, AUTHTYPE);
			boInfoStore = (IInfoStore) boEnterpriseSession.getService("",
					"InfoStore");

public void removeUserFromGroup(String userName, String groupName) {
		try {

			logger.debug("remove user from  group " + userName + groupName);

			boInfoStore = (IInfoStore) boEnterpriseSession.getService("",
					"InfoStore");

			// Retrieve the user and group
			boInfoObjects = boInfoStore
					.query("SELECT * FROM CI_SYSTEMOBJECTS Where SI_PROGID='CrystalEnterprise.User' and SI_NAME = '"
							+ userName + "'");
			boCurUser = (IUser) boInfoObjects.get(0);
			boGroup = (IUserGroup) boInfoStore
					.query("SELECT * FROM CI_SYSTEMOBJS WHERE SI_PROGID='CrystalEnterprise.USERGROUP' AND SI_NAME='"
							+ groupName + "'").get(0);

			// This removal assumes that the user is part of the group. It will
			// throw an exception if this is not the case.
			boCurUser.getGroups().remove(new Integer(boGroup.getID()));

			// Commit the changes to the InfoStore.
			boInfoStore.commit(boInfoObjects);
		} catch (SDKException e) {
			logger.error("Exception remove user from  group " + userName + groupName
					+ e);
		}
	}

Leave a Reply

Your email address will not be published. Required fields are marked *