Beispiel #1
0
        public override void AddUsersToRoles(string [] usernames, string [] rolenames)
        {
            Hashtable h = new Hashtable();

            foreach (string u in usernames)
            {
                if (u == null)
                {
                    throw new ArgumentNullException("null element in usernames array");
                }
                if (h.ContainsKey(u))
                {
                    throw new ArgumentException("duplicate element in usernames array");
                }
                if (u.Length == 0 || u.Length > 256 || u.IndexOf(",") != -1)
                {
                    throw new ArgumentException("element in usernames array in illegal format");
                }
                h.Add(u, u);
            }

            h = new Hashtable();
            foreach (string r in rolenames)
            {
                if (r == null)
                {
                    throw new ArgumentNullException("null element in rolenames array");
                }
                if (h.ContainsKey(r))
                {
                    throw new ArgumentException("duplicate element in rolenames array");
                }
                if (r.Length == 0 || r.Length > 256 || r.IndexOf(",") != -1)
                {
                    throw new ArgumentException("element in rolenames array in illegal format");
                }
                h.Add(r, r);
            }

            using (DbConnection connection = CreateConnection()) {
                int returnValue = DerbyRolesHelper.UsersInRoles_AddUsersToRoles(connection, ApplicationName, usernames, rolenames, DateTime.UtcNow);

                if (returnValue == 0)
                {
                    return;
                }
                else if (returnValue == 2)
                {
                    throw new ProviderException("One or more of the specified role names was not found.");
                }
                else if (returnValue == 3)
                {
                    throw new ProviderException("One or more of the specified user names is already associated with one or more of the specified role names.");
                }
                else
                {
                    throw new ProviderException("Failed to create new user/role association.");
                }
            }
        }
Beispiel #2
0
        public override bool DeleteRole(string rolename, bool throwOnPopulatedRole)
        {
            if (rolename == null)
            {
                throw new ArgumentNullException("rolename");
            }

            if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf(",") != -1)
            {
                throw new ArgumentException("rolename is in invalid format");
            }

            using (DbConnection connection = CreateConnection()) {
                int returnValue = DerbyRolesHelper.Roles_DeleteRole(connection, ApplicationName, rolename, throwOnPopulatedRole);

                if (returnValue == 0)
                {
                    return(true);
                }
                if (returnValue == 2)
                {
                    return(false);                    //role does not exists
                }
                else if (returnValue == 3 && throwOnPopulatedRole)
                {
                    throw new ProviderException(rolename + " is not empty");
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #3
0
        public override bool IsUserInRole(string username, string rolename)
        {
            if (username == null)
            {
                throw new ArgumentNullException("rolename");
            }
            if (username.Length == 0 || username.Length > 256 || username.IndexOf(",") != -1)
            {
                throw new ArgumentException("username is in invalid format");
            }
            if (rolename == null)
            {
                throw new ArgumentNullException("rolename");
            }
            if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf(",") != -1)
            {
                throw new ArgumentException("rolename is in invalid format");
            }

            using (DbConnection connection = CreateConnection()) {
                int returnValue = DerbyRolesHelper.UsersInRoles_IsUserInRole(connection, ApplicationName, username, rolename);

                if (returnValue == 4)
                {
                    return(true);
                }

                return(false);
            }
        }
Beispiel #4
0
        public override void CreateRole(string rolename)
        {
            if (rolename == null)
            {
                throw new ArgumentNullException("rolename");
            }

            if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf(",") != -1)
            {
                throw new ArgumentException("rolename is in invalid format");
            }

            using (DbConnection connection = CreateConnection()) {
                int returnValue = DerbyRolesHelper.Roles_CreateRole(connection, ApplicationName, rolename);

                if (returnValue == 2)
                {
                    throw new ProviderException(rolename + " already exists in the database");
                }
                else
                {
                    return;
                }
            }
        }
Beispiel #5
0
        public override string [] GetUsersInRole(string rolename)
        {
            if (rolename == null)
            {
                throw new ArgumentNullException("rolename");
            }

            if (rolename.Length == 0 || rolename.Length > 256 || rolename.IndexOf(",") != -1)
            {
                throw new ArgumentException("rolename is in invalid format");
            }

            using (DbConnection connection = CreateConnection()) {
                DbDataReader reader;
                ArrayList    roleList    = new ArrayList();
                int          returnValue = DerbyRolesHelper.UsersInRoles_GetUsersInRoles(connection, applicationName, rolename, out reader);

                if (returnValue == 2)
                {
                    throw new ProviderException("The role '" + rolename + "' was not found.");
                }

                using (reader) {
                    if (reader == null)
                    {
                        return new string [] { }
                    }
                    ;

                    while (reader.Read())
                    {
                        roleList.Add(reader.GetString(0));
                    }
                }
                return((string [])roleList.ToArray(typeof(string)));
            }
        }

        string GetStringConfigValue(NameValueCollection config, string name, string def)
        {
            string rv  = def;
            string val = config [name];

            if (val != null)
            {
                rv = val;
            }
            return(rv);
        }
Beispiel #6
0
        public override string [] FindUsersInRole(string roleName, string usernameToMatch)
        {
            if (roleName == null)
            {
                throw new ArgumentNullException("roleName");
            }
            if (usernameToMatch == null)
            {
                throw new ArgumentNullException("usernameToMatch");
            }
            if (roleName.Length == 0 || roleName.Length > 256 || roleName.IndexOf(",") != -1)
            {
                throw new ArgumentException("roleName is in invalid format");
            }
            if (usernameToMatch.Length == 0 || usernameToMatch.Length > 256)
            {
                throw new ArgumentException("usernameToMatch is in invalid format");
            }

            using (DbConnection connection = CreateConnection()) {
                DbDataReader reader;
                ArrayList    userList    = new ArrayList();
                int          returnValue = DerbyRolesHelper.UsersInRoles_FindUsersInRole(connection, applicationName, roleName, usernameToMatch, out reader);

                if (returnValue == 2)
                {
                    throw new ProviderException("The role '" + roleName + "' was not found.");
                }

                using (reader) {
                    if (reader == null)
                    {
                        return new string [] { }
                    }
                    ;

                    while (reader.Read())
                    {
                        userList.Add(reader.GetString(0));
                    }
                }
                return((string [])userList.ToArray(typeof(string)));
            }
        }
Beispiel #7
0
        public override string [] GetAllRoles()
        {
            using (DbConnection connection = CreateConnection()) {
                DbDataReader reader;
                ArrayList    roleList = new ArrayList();
                DerbyRolesHelper.Roles_GetAllRoles(connection, applicationName, out reader);
                using (reader) {
                    if (reader == null)
                    {
                        return new string [] { }
                    }
                    ;

                    while (reader.Read())
                    {
                        roleList.Add(reader.GetString(0));
                    }
                }
                return((string [])roleList.ToArray(typeof(string)));
            }
        }
Beispiel #8
0
        public override string [] GetRolesForUser(string username)
        {
            if (username == null)
            {
                throw new ArgumentNullException("rolename");
            }

            if (username.Length == 0 || username.Length > 256 || username.IndexOf(",") != -1)
            {
                throw new ArgumentException("username is in invalid format");
            }

            using (DbConnection connection = CreateConnection()) {
                DbDataReader reader;
                ArrayList    roleList    = new ArrayList();
                int          returnValue = DerbyRolesHelper.UsersInRoles_GetRolesForUser(connection, applicationName, username, out reader);

                if (returnValue == 2)
                {
                    throw new ProviderException("username was not found in the database");
                }

                using (reader) {
                    if (reader == null)
                    {
                        return new string [] { }
                    }
                    ;

                    while (reader.Read())
                    {
                        roleList.Add(reader.GetString(0));
                    }
                }
                return((string [])roleList.ToArray(typeof(string)));
            }
        }