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);
 }
 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);
 }
        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);
        }
 /// <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);
 }
 public void DropRole(Cluster cluster, AdminPolicy policy, string roleName)
 {
     WriteHeader(DROP_ROLE, 1);
     WriteField(ROLE, roleName);
     ExecuteCommand(cluster, policy);
 }
 /// <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);
 }
Esempio n. 7
0
 public List <User> QueryUsers(Cluster cluster, AdminPolicy policy)
 {
     base.WriteHeader(QUERY_USERS, 0);
     base.ExecuteQuery(cluster, policy);
     return(list);
 }
        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);
            }
        }
 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;
 }
 //-------------------------------------------------------
 // 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);
 }
 public void RevokeRoles(Cluster cluster, AdminPolicy policy, string user, IList<string> roles)
 {
     WriteHeader(REVOKE_ROLES, 2);
     WriteField(USER, user);
     WriteRoles(roles);
     ExecuteCommand(cluster, policy);
 }
        /// <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);
        }
 /// <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);
 }
 /// <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);
 }
 /// <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);
 }
 /// <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);
 }
 public void DropUser(Cluster cluster, AdminPolicy policy, string user)
 {
     WriteHeader(DROP_USER, 1);
     WriteField(USER, user);
     ExecuteCommand(cluster, policy);
 }
 /// <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);
 }
 public void RevokePrivileges(Cluster cluster, AdminPolicy policy, string roleName, IList<Privilege> privileges)
 {
     WriteHeader(REVOKE_PRIVILEGES, 2);
     WriteField(ROLE, roleName);
     WritePrivileges(privileges);
     ExecuteCommand(cluster, policy);
 }
 /// <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);
 }
 public void SetPassword(Cluster cluster, AdminPolicy policy, byte[] user, string password)
 {
     WriteHeader(SET_PASSWORD, 2);
     WriteField(USER, user);
     WriteField(PASSWORD, password);
     ExecuteCommand(cluster, policy);
 }
 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;
 }
        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.");
            }
        }
Esempio n. 24
0
 public void DropUser(Cluster cluster, AdminPolicy policy, string user)
 {
     WriteHeader(DROP_USER, 1);
     WriteField(USER, user);
     ExecuteCommand(cluster, policy);
 }
 public List<Role> QueryRoles(Cluster cluster, AdminPolicy policy)
 {
     base.WriteHeader(QUERY_ROLES, 0);
     base.ExecuteQuery(cluster, policy);
     return list;
 }
 /// <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);
 }
 public List<User> QueryUsers(Cluster cluster, AdminPolicy policy)
 {
     base.WriteHeader(QUERY_USERS, 0);
     base.ExecuteQuery(cluster, policy);
     return list;
 }
 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);
 }
Esempio n. 29
0
 public void DropRole(Cluster cluster, AdminPolicy policy, string roleName)
 {
     WriteHeader(DROP_ROLE, 1);
     WriteField(ROLE, roleName);
     ExecuteCommand(cluster, policy);
 }
 public void CreateRole(Cluster cluster, AdminPolicy policy, string roleName, IList<Privilege> privileges)
 {
     WriteHeader(CREATE_ROLE, 2);
     WriteField(ROLE, roleName);
     WritePrivileges(privileges);
     ExecuteCommand(cluster, policy);
 }
Esempio n. 31
0
 public List <Role> QueryRoles(Cluster cluster, AdminPolicy policy)
 {
     base.WriteHeader(QUERY_ROLES, 0);
     base.ExecuteQuery(cluster, policy);
     return(list);
 }
 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);
 }