⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mqconnection.java

📁 一个简单实用的开源C++消息中间件SAFMQ - [软件开发] - [开源 消息中间件 SAFMQ ] 2006-11-23 在很多网络应用中
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * @param username	The name of the user
	 * @param actorPerms	Receives the permissions for the user, must not be null.
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
	 *				<td>The specified user does not exist on the SAFMQ server, or the
	 *					user has no permissions set.
	 *				</td></tr>
	 *</table>
	 */
	public int UserGetPermissions(String username, ActorPermissions actorPerms) {
		USER_DELETE_USER_GET_PERMS_USER_GET_GROUPS_PARAMS	params =  new USER_DELETE_USER_GET_PERMS_USER_GET_GROUPS_PARAMS();
		int													ret = Safmq.EC_NETWORKERROR;

		paramutil.arrayCopy(params.username,username);
		try {
			out.write(Safmq.CMD_USER_GET_PERMS);
			params.write(out);
			out.flush();
			ret = getResponseCode();
			if (ret == Safmq.EC_NOERROR) {
				USER_GET_PERMS_GROUP_GET_PERMS_RESPONSE_data	perms = new USER_GET_PERMS_GROUP_GET_PERMS_RESPONSE_data();
				perms.read(in);
				actorPerms.setModifyqueues(perms.modify_queues != 0);
				actorPerms.setModifyusers(perms.modify_users != 0);
				actorPerms.setModifygroups(perms.modify_groups != 0);
			}
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Changes the password for the specified user.
	 * 
	 * @param username	Name of the user
	 * @param password	New password for the user.
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The current logged in user is not authorized to create users.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
	 *				<td>The specified user does not exist on the SAFMQ server.
	 *				</td></tr>
	 *</table>
	 */
	public int SetPassword(String username, String password) {
		int							ret = Safmq.EC_NETWORKERROR;
		USER_SET_PASSWORD_PARAMS	params = new USER_SET_PASSWORD_PARAMS();

		paramutil.arrayCopy(params.username, username);
		paramutil.arrayCopy(params.password, password);
		try {
			out.write(Safmq.CMD_USER_SET_PASSWORD);
			params.write(out);
			out.flush();
			ret = getResponseCode();
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}

	/**
	 * Creates a new security group on the SAFMQ server.
	 * 
	 * @param groupname Name of the group to create.
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_ALREADYDEFINED</code></td>
	 *				<td>A group with this name already exists
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The current logged in user is not authorized to create groups.
	 *				</td></tr>
	 *</table>
	 */
	public int CreateGroup(String groupname) {
		GROUP_CREATE_GROUP_DELETE_GROUP_GET_USERS_GROUP_GET_PERMS_PARAMS	params = new GROUP_CREATE_GROUP_DELETE_GROUP_GET_USERS_GROUP_GET_PERMS_PARAMS();
		int																	ret = Safmq.EC_NETWORKERROR;

		paramutil.arrayCopy(params.groupname,groupname);
		try {
			out.write(Safmq.CMD_GROUP_CREATE);
			params.write(out);
			out.flush();
			ret = getResponseCode();
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Removes the security group from the SAFMQ server.
	 * @param groupname The name of the group
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The current logged in user is not authorized to create groups.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
	 *				<td>The group specified does not exist.
	 *				</td></tr>
	 *</table>
	 */
	public int DeleteGroup(String groupname) {
		GROUP_CREATE_GROUP_DELETE_GROUP_GET_USERS_GROUP_GET_PERMS_PARAMS	params = new GROUP_CREATE_GROUP_DELETE_GROUP_GET_USERS_GROUP_GET_PERMS_PARAMS();
		int																	ret = Safmq.EC_NETWORKERROR;

		paramutil.arrayCopy(params.groupname,groupname);
		try {
			out.write(Safmq.CMD_GROUP_DELETE);
			params.write(out);
			out.flush();
			ret = getResponseCode();
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Changes the permissions for the specified group.
	 * 
	 * @param groupname		The name of the group
	 * @param modifyqueues	Whether the group may create queues
	 * @param modifyusers	Whether the group may create and delete users and set permissions
	 * @param modifygroups	Whether the gorup may create, delete and change group membership and permissions
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The current logged in user is not authorized to modify group permissions.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
	 *				<td>The specified group does not exist on the SAFMQ server.
	 *				</td></tr>
	 *</table>
	 */
	public int GroupSetPermissions(String groupname, boolean modifyqueues, boolean modifyusers, boolean modifygroups) {
		GROUP_SET_PERMS_PARAMS	params = new GROUP_SET_PERMS_PARAMS();
		int						ret = Safmq.EC_NETWORKERROR;

		paramutil.arrayCopy(params.groupname,groupname);
		params.modify_queues = (byte)(modifyqueues?1:0);
		params.modify_users = (byte)(modifyusers?1:0);
		params.modify_groups = (byte)(modifygroups?1:0);
		try {
			out.write(Safmq.CMD_GROUP_SET_PERMS);
			params.write(out);
			out.flush();
			ret = getResponseCode();
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Retrieves the permissions of a specific group.
	 * 
	 * @param groupname The name of the group
	 * @param actorPerms	Receives the permissions, must not be null
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
	 *				<td>The specified group does not exist on the SAFMQ server, or no
	 *					permissions have been set for that group.
	 *				</td></tr>
	 *</table>
	 */
	public int GroupGetPermissions(String groupname, ActorPermissions actorPerms) {
		GROUP_CREATE_GROUP_DELETE_GROUP_GET_USERS_GROUP_GET_PERMS_PARAMS	params = new GROUP_CREATE_GROUP_DELETE_GROUP_GET_USERS_GROUP_GET_PERMS_PARAMS();
		int																	ret = Safmq.EC_NETWORKERROR;

		paramutil.arrayCopy(params.groupname,groupname);
		try {
			out.write(Safmq.CMD_GROUP_GET_PERMS);
			params.write(out);
			out.flush();
			ret = getResponseCode();
			if (ret == Safmq.EC_NOERROR) {
				USER_GET_PERMS_GROUP_GET_PERMS_RESPONSE_data	perms = new USER_GET_PERMS_GROUP_GET_PERMS_RESPONSE_data();
				perms.read(in);
				actorPerms.setModifyqueues(perms.modify_queues != 0);
				actorPerms.setModifyusers(perms.modify_users != 0);
				actorPerms.setModifygroups(perms.modify_groups != 0);
			}
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Adds a user to a group.
	 * 
	 * @param groupname	The name of the group
	 * @param username	The name of the user
	 * 
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The current logged in user is not authorized to modify group permissions.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
	 *				<td>The specified group does not exist on the SAFMQ server.
	 *				</td></tr>
	 *</table>
	 */
	public int GroupAddUser(String groupname, String username) {
		GROUP_ADD_USER_GROUP_DELETE_USER_PARAMS	params = new GROUP_ADD_USER_GROUP_DELETE_USER_PARAMS();
		int										ret = Safmq.EC_NETWORKERROR;

		paramutil.arrayCopy(params.groupname,groupname);
		paramutil.arrayCopy(params.username,username);
		
		try {
			out.write(Safmq.CMD_GROUP_ADD_USER);
			params.write(out);
			out.flush();
			ret = getResponseCode();
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Deletes a user from a group.
	 * 
	 * @param groupname	The name of the group
	 * @param username	The name of the user
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The current logged in user is not authorized to modify group permissions.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
	 *				<td>The specified group does not exist on the SAFMQ server.
	 *				</td></tr>
	 *</table>
	 */
	public int GroupDeleteUser(String groupname, String username) {
		GROUP_ADD_USER_GROUP_DELETE_USER_PARAMS	params = new GROUP_ADD_USER_GROUP_DELETE_USER_PARAMS();
		int										ret = Safmq.EC_NETWORKERROR;

		paramutil.arrayCopy(params.groupname,groupname);
		paramutil.arrayCopy(params.username,username);

		try {
			out.write(Safmq.CMD_GROUP_DELETE_USER);
			params.write(out);
			out.flush();
			ret = getResponseCode();
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Retrieves a the list of users in a group.  The names of the users are
	 * deposited into the <code>Vector users</code> in the form of <code>String</code>
	 * objects.
	 * 
	 * @param groupname	The name of the users.
	 * @param users		A vector receiving <code>String</code> objects containing
	 * 					the user's name.
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
	 *				<td>The specified group does not exist on the SAFMQ server.
	 *				</td></tr>
	 *</table>
	 */
	public int GroupGetUsers(String groupname, Vector users) {
		GROUP_CREATE_GROUP_DELETE_GROUP_GET_USERS_GROUP_GET_PERMS_PARAMS	params = new GROUP_CREATE_GROUP_DELETE_GROUP_GET_USERS_GROUP_GET_PERMS_PARAMS();
		int																	ret = Safmq.EC_NETWORKERROR;

		paramutil.arrayCopy(params.groupname,groupname);
		users.clear();

		try {
			out.write(Safmq.CMD_GROUP_GET_USERS);
			params.write(out);
			out.flush();
			ret = getResponseCode();
			if (ret == Safmq.EC_NOERROR) {
				int	nUsers;
				int	x;
				byte	username[] = new byte[Safmq.USER_NAME_LENGTH];

				nUsers = in.readInt();
				for(x=0;x<nUsers;x++) {
					in.readFully(username);
					users.add(new String(username,0,zlength(username)));
				}
			}
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}

	/**
	 * Retrieves a the list of groups the in which the user resides.  The names of the groups are
	 * deposited into the <code>Vector users</code> in the form of <code>String</code>
	 * objects.
	 * 
	 * @param username	The name of the users.
	 * @param groups	A vector receiving <code>String</code> objects containing
	 * 					the group's name.
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -