public void test_UserPermissions() { MQConnection con = null; try { con = connectToServer(address, null, null); createNewUser(con, TEST_USERS[0], TEST_DESC[0], TEST_PASSWD[0]); ErrorCode ec; for (int x = 7; x >= 0; x--) { ec = con.UserSetPermissions(TEST_USERS[0], (x & 0x04) != 0, (x & 0x2) != 0, (x & 0x1) != 0); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Failed to set permissions for: " + TEST_USERS[0]); ActorPermissions actorPerms = new ActorPermissions(); ec = con.UserGetPermissions(TEST_USERS[0], actorPerms); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Failed to retrive permissions for: " + TEST_USERS[0]); Assert.IsTrue(actorPerms.ModifyQueues == ((x & 0x04) != 0), "Modify queues incorrectly set: " + x); Assert.IsTrue(actorPerms.ModifyUsers == ((x & 0x02) != 0), "Modify users incorrectly set: " + x); Assert.IsTrue(actorPerms.ModifyGroups == ((x & 0x01) != 0), "Modify groups incorrectly set: " + x); } } finally { if (con != null) con.Close(); } }
/** * <summary> * Retrieve the permissions for a specific user. * </summary> * * <param name="username"> The name of the user</param> * <param name="actorPerms"> Receives the permissions for the user, must not be null.</param> * * <returns><c>ErrorCode.EC_NOERROR</c> upon success, otherwise errors returned * could be but are not limited to:<br/> * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_DOESNOTEXIST</c></td> * <td>The specified user does not exist on the SAFMQ server, or the * user has no permissions set. * </td></tr> * </table> * </returns> */ public ErrorCode UserGetPermissions(string username, ActorPermissions actorPerms) { USER_DELETE_USER_GET_PERMS_USER_GET_GROUPS_PARAMS parms = new USER_DELETE_USER_GET_PERMS_USER_GET_GROUPS_PARAMS(); ErrorCode ret = ErrorCode.EC_NETWORKERROR; parms.username = username; try { output.Write(Safmq.CMD_USER_GET_PERMS); parms.Write(output); output.Flush(); ret = getResponseCode(); if (ret == ErrorCode.EC_NOERROR) { USER_GET_PERMS_GROUP_GET_PERMS_RESPONSE_data perms = new USER_GET_PERMS_GROUP_GET_PERMS_RESPONSE_data(); perms.Read(input); actorPerms.ModifyQueues = (perms.modify_queues != 0); actorPerms.ModifyUsers = (perms.modify_users != 0); actorPerms.ModifyGroups = (perms.modify_groups != 0); } } catch (Exception) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }