コード例 #1
0
 public void ChangePassword(Cluster cluster, AdminPolicy policy, byte[] user, string password)
 {
     WriteHeader(CHANGE_PASSWORD, 3);
     WriteField(USER, user);
     WriteField(OLD_PASSWORD, cluster.password);
     WriteField(PASSWORD, password);
     ExecuteCommand(cluster, policy);
 }
コード例 #2
0
 public void CreateUser(Cluster cluster, AdminPolicy policy, string user, string password, IList <string> roles)
 {
     WriteHeader(CREATE_USER, 3);
     WriteField(USER, user);
     WriteField(PASSWORD, password);
     WriteRoles(roles);
     ExecuteCommand(cluster, policy);
 }
コード例 #3
0
        public void SetWhitelist(Cluster cluster, AdminPolicy policy, string roleName, IList <string> whitelist)
        {
            byte fieldCount = (whitelist != null && whitelist.Count > 0) ? (byte)2 : (byte)1;

            WriteHeader(SET_WHITELIST, fieldCount);
            WriteField(ROLE, roleName);

            if (whitelist != null && whitelist.Count > 0)
            {
                WriteWhitelist(whitelist);
            }

            ExecuteCommand(cluster, policy);
        }
コード例 #4
0
 /// <summary>
 /// Retrieve role definition.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <param name="roleName">role name filter</param>
 /// <exception cref="AerospikeException">if command fails</exception>
 public Role QueryRole(AdminPolicy policy, string roleName)
 {
     AdminCommand.RoleCommand command = new AdminCommand.RoleCommand(1);
     return command.QueryRole(cluster, policy, roleName);
 }
コード例 #5
0
 public void DropRole(Cluster cluster, AdminPolicy policy, string roleName)
 {
     WriteHeader(DROP_ROLE, 1);
     WriteField(ROLE, roleName);
     ExecuteCommand(cluster, policy);
 }
コード例 #6
0
 /// <summary>
 /// Retrieve roles for a given user.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <param name="user">user name filter</param>
 public User QueryUser(AdminPolicy policy, string user)
 {
     AdminCommand.UserCommand command = new AdminCommand.UserCommand(1);
     return command.QueryUser(cluster, policy, user);
 }
コード例 #7
0
 public List <User> QueryUsers(Cluster cluster, AdminPolicy policy)
 {
     base.WriteHeader(QUERY_USERS, 0);
     base.ExecuteQuery(cluster, policy);
     return(list);
 }
コード例 #8
0
        private void ExecuteCommand(Cluster cluster, AdminPolicy policy)
        {
            WriteSize();
            Node node = cluster.GetRandomNode();
            int timeout = (policy == null) ? 1000 : policy.timeout;
            Connection conn = node.GetConnection(timeout);

            try
            {
                conn.Write(dataBuffer, dataOffset);
                conn.ReadFully(dataBuffer, HEADER_SIZE);
                node.PutConnection(conn);
            }
            catch (Exception)
            {
                // Garbage may be in socket.  Do not put back into pool.
                node.CloseConnection(conn);
                throw;
            }

            int result = dataBuffer[RESULT_CODE];

            if (result != 0)
            {
                throw new AerospikeException(result);
            }
        }
コード例 #9
0
 public Role QueryRole(Cluster cluster, AdminPolicy policy, string roleName)
 {
     base.WriteHeader(QUERY_ROLES, 1);
     base.WriteField(ROLE, roleName);
     base.ExecuteQuery(cluster, policy);
     return (list.Count > 0) ? list[0] : null;
 }
コード例 #10
0
 //-------------------------------------------------------
 // User administration
 //-------------------------------------------------------
 /// <summary>
 /// Create user with password and roles.  Clear-text password will be hashed using bcrypt 
 /// before sending to server.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <param name="user">user name</param>
 /// <param name="password">user password in clear-text format</param>
 /// <param name="roles">variable arguments array of role names.  Predefined roles are listed in Role.cs</param>		
 public void CreateUser(AdminPolicy policy, string user, string password, IList<string> roles)
 {
     string hash = AdminCommand.HashPassword(password);
     AdminCommand command = new AdminCommand();
     command.CreateUser(cluster, policy, user, hash, roles);
 }
コード例 #11
0
 public void RevokeRoles(Cluster cluster, AdminPolicy policy, string user, IList<string> roles)
 {
     WriteHeader(REVOKE_ROLES, 2);
     WriteField(USER, user);
     WriteRoles(roles);
     ExecuteCommand(cluster, policy);
 }
コード例 #12
0
        /// <summary>
        /// Change user's password.  Clear-text password will be hashed using bcrypt 
        /// before sending to server.
        /// </summary>
        /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
        /// <param name="user">user name</param>
        /// <param name="password">user password in clear-text format</param>
        public void ChangePassword(AdminPolicy policy, string user, string password)
        {
            if (cluster.user == null)
            {
                throw new AerospikeException("Invalid user");
            }

            string hash = AdminCommand.HashPassword(password);
            AdminCommand command = new AdminCommand();
            byte[] userBytes = ByteUtil.StringToUtf8(user);

            if (Util.ByteArrayEquals(userBytes, cluster.user))
            {
                // Change own password.
                command.ChangePassword(cluster, policy, userBytes, hash);
            }
            else
            {
                // Change other user's password by user admin.
                command.SetPassword(cluster, policy, userBytes, hash);
            }
            cluster.ChangePassword(userBytes, hash);
        }
コード例 #13
0
 /// <summary>
 /// Create user defined role.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <param name="roleName">role name</param>
 /// <param name="privileges">privileges assigned to the role.</param>
 /// <exception cref="AerospikeException">if command fails </exception>
 public void CreateRole(AdminPolicy policy, string roleName, IList<Privilege> privileges)
 {
     AdminCommand command = new AdminCommand();
     command.CreateRole(cluster, policy, roleName, privileges);
 }
コード例 #14
0
 /// <summary>
 /// Remove roles from user's list of roles.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <param name="user">user name</param>
 /// <param name="roles">role names.  Predefined roles are listed in Role.cs</param>
 public void RevokeRoles(AdminPolicy policy, string user, IList<string> roles)
 {
     AdminCommand command = new AdminCommand();
     command.RevokeRoles(cluster, policy, user, roles);
 }
コード例 #15
0
 /// <summary>
 /// Revoke privileges from an user defined role.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <param name="roleName">role name</param>
 /// <param name="privileges">privileges assigned to the role.</param>
 /// <exception cref="AerospikeException">if command fails</exception>
 public void RevokePrivileges(AdminPolicy policy, string roleName, IList<Privilege> privileges)
 {
     AdminCommand command = new AdminCommand();
     command.RevokePrivileges(cluster, policy, roleName, privileges);
 }
コード例 #16
0
 /// <summary>
 /// Retrieve all users and their roles.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 public List<User> QueryUsers(AdminPolicy policy)
 {
     AdminCommand.UserCommand command = new AdminCommand.UserCommand(100);
     return command.QueryUsers(cluster, policy);
 }
コード例 #17
0
 public void DropUser(Cluster cluster, AdminPolicy policy, string user)
 {
     WriteHeader(DROP_USER, 1);
     WriteField(USER, user);
     ExecuteCommand(cluster, policy);
 }
コード例 #18
0
 /// <summary>
 /// Drop user defined role.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <param name="roleName">role name</param>
 /// <exception cref="AerospikeException">if command fails</exception>
 public void DropRole(AdminPolicy policy, string roleName)
 {
     AdminCommand command = new AdminCommand();
     command.DropRole(cluster, policy, roleName);
 }
コード例 #19
0
 public void RevokePrivileges(Cluster cluster, AdminPolicy policy, string roleName, IList<Privilege> privileges)
 {
     WriteHeader(REVOKE_PRIVILEGES, 2);
     WriteField(ROLE, roleName);
     WritePrivileges(privileges);
     ExecuteCommand(cluster, policy);
 }
コード例 #20
0
 /// <summary>
 /// Remove user from cluster.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <param name="user">user name</param>
 public void DropUser(AdminPolicy policy, string user)
 {
     AdminCommand command = new AdminCommand();
     command.DropUser(cluster, policy, user);
 }
コード例 #21
0
 public void SetPassword(Cluster cluster, AdminPolicy policy, byte[] user, string password)
 {
     WriteHeader(SET_PASSWORD, 2);
     WriteField(USER, user);
     WriteField(PASSWORD, password);
     ExecuteCommand(cluster, policy);
 }
コード例 #22
0
 public User QueryUser(Cluster cluster, AdminPolicy policy, string user)
 {
     base.WriteHeader(QUERY_USERS, 1);
     base.WriteField(USER, user);
     base.ExecuteQuery(cluster, policy);
     return (list.Count > 0) ? list[0] : null;
 }
コード例 #23
0
        private void ExecuteQuery(Cluster cluster, AdminPolicy policy)
        {
            WriteSize();
            Node node = cluster.GetRandomNode();
            int timeout = (policy == null) ? 1000 : policy.timeout;
            int status = 0;
            Connection conn = node.GetConnection(timeout);

            try
            {
                conn.Write(dataBuffer, dataOffset);
                status = ReadBlocks(conn);
                node.PutConnection(conn);
            }
            catch (Exception e)
            {
                // Garbage may be in socket.  Do not put back into pool.
                node.CloseConnection(conn);
                throw new AerospikeException(e);
            }

            if (status != QUERY_END && status > 0)
            {
                throw new AerospikeException(status, "Query failed.");
            }
        }
コード例 #24
0
 public void DropUser(Cluster cluster, AdminPolicy policy, string user)
 {
     WriteHeader(DROP_USER, 1);
     WriteField(USER, user);
     ExecuteCommand(cluster, policy);
 }
コード例 #25
0
 public List<Role> QueryRoles(Cluster cluster, AdminPolicy policy)
 {
     base.WriteHeader(QUERY_ROLES, 0);
     base.ExecuteQuery(cluster, policy);
     return list;
 }
コード例 #26
0
 /// <summary>
 /// Retrieve all roles.
 /// </summary>
 /// <param name="policy">admin configuration parameters, pass in null for defaults</param>
 /// <exception cref="AerospikeException">if command fails</exception>
 public List<Role> QueryRoles(AdminPolicy policy)
 {
     AdminCommand.RoleCommand command = new AdminCommand.RoleCommand(100);
     return command.QueryRoles(cluster, policy);
 }
コード例 #27
0
 public List<User> QueryUsers(Cluster cluster, AdminPolicy policy)
 {
     base.WriteHeader(QUERY_USERS, 0);
     base.ExecuteQuery(cluster, policy);
     return list;
 }
コード例 #28
0
 public void ChangePassword(Cluster cluster, AdminPolicy policy, byte[] user, string password)
 {
     WriteHeader(CHANGE_PASSWORD, 3);
     WriteField(USER, user);
     WriteField(OLD_PASSWORD, cluster.password);
     WriteField(PASSWORD, password);
     ExecuteCommand(cluster, policy);
 }
コード例 #29
0
 public void DropRole(Cluster cluster, AdminPolicy policy, string roleName)
 {
     WriteHeader(DROP_ROLE, 1);
     WriteField(ROLE, roleName);
     ExecuteCommand(cluster, policy);
 }
コード例 #30
0
 public void CreateRole(Cluster cluster, AdminPolicy policy, string roleName, IList<Privilege> privileges)
 {
     WriteHeader(CREATE_ROLE, 2);
     WriteField(ROLE, roleName);
     WritePrivileges(privileges);
     ExecuteCommand(cluster, policy);
 }
コード例 #31
0
 public List <Role> QueryRoles(Cluster cluster, AdminPolicy policy)
 {
     base.WriteHeader(QUERY_ROLES, 0);
     base.ExecuteQuery(cluster, policy);
     return(list);
 }
コード例 #32
0
 public void CreateUser(Cluster cluster, AdminPolicy policy, string user, string password, IList<string> roles)
 {
     WriteHeader(CREATE_USER, 3);
     WriteField(USER, user);
     WriteField(PASSWORD, password);
     WriteRoles(roles);
     ExecuteCommand(cluster, policy);
 }