Example #1
0
            private bool mergePrivilege(GrantedSysPrivilege newGrant)
            {
                bool privilegeStrengthRaised;

                IEnumerable <GrantedSysPrivilege> existingGrants =
                    from grant in privileges
                    where grant.Privilege == newGrant.Privilege
                    select grant;

                if (existingGrants.Count() > 0)
                {
                    GrantedSysPrivilege existingGrant = existingGrants.First();

                    if (newGrant.IsStrongerThan(existingGrant))
                    {
                        privileges.Remove(existingGrant);
                        privilegeStrengthRaised = true;
                    }
                    else
                    {
                        privilegeStrengthRaised = false;
                    }
                }
                else
                {
                    privilegeStrengthRaised = true;
                }

                if (privilegeStrengthRaised)
                {
                    privileges.Add(newGrant);
                }

                return(privilegeStrengthRaised);
            }
Example #2
0
        public bool RefreshRoleData(RoleManager.Role role)
        {
            if (refreshUserRoleData(role))
            {
                return(true);
            }
            else
            {
                OracleCommand cmd = new OracleCommand(ROLE_SYS_PRIVS_ROLE_SELECT, conn);
                // set up parameters
                OracleParameter roleParam = cmd.CreateParameter();
                roleParam.ParameterName = "role";
                roleParam.OracleDbType  = OracleDbType.Char;
                roleParam.Direction     = System.Data.ParameterDirection.Input;
                roleParam.Value         = role.Name;
                // execute
                OracleDataReader odr = cmd.ExecuteReader();

                if (!odr.HasRows)
                {
                    return(false);
                }

                // purge old data
                purgeOldUserRoleSysPrivs(role.Name);

                while (odr.Read())
                {
                    GrantedSysPrivilege grant = LoadPrivilege(odr);
                    grants.Add(grant);
                }

                return(true);
            }
        }
Example #3
0
        public void RefreshRolesData()
        {
            OracleCommand    cmd     = new OracleCommand(DBA_SYS_PRIVS_ROLES_SELECT, conn);
            OracleDataReader odr     = cmd.ExecuteReader();
            bool             hasRows = true;

            if (!odr.HasRows)
            {
                cmd.CommandText = ROLE_SYS_PRIVS_SELECT;
                odr             = cmd.ExecuteReader();
                hasRows         = odr.HasRows;
            }

            if (hasRows)
            {
                grants.Clear();

                while (odr.Read())
                {
                    GrantedSysPrivilege grant = LoadPrivilege(odr);
                    grants.Add(grant);
                }

                // notify roles
                OnAllRolesSysPrivilegesRefreshed();
            }
        }
Example #4
0
            public override void DownloadPrivileges()
            {
                IEnumerable <GrantedSysPrivilege> newPrivs =
                    manager.downloadUserRolePrivileges(userRole);

                if (newPrivs.Count() > 0)
                {
                    privileges.Clear();
                    privileges.AddRange(newPrivs);
                }
                else
                {
                    OracleCommand    cmd = new OracleCommand(CURRENT_USER_PRIVS_SELECT, conn);
                    OracleDataReader odr = cmd.ExecuteReader();

                    if (odr.HasRows)
                    {
                        privileges.Clear();
                    }

                    while (odr.Read())
                    {
                        GrantedSysPrivilege grant = SysPrivManager.LoadPrivilege(odr);
                        // add it
                        privileges.Add(grant);
                    }
                }
            }
Example #5
0
        private bool refreshUsersRolesData(StringCollection userRoleNames)
        {
            OracleCommand cmd = new OracleCommand(
                string.Format("{0}\r\n{1}",
                              DBA_SYS_PRIVS_SELECT,
                              createSysPrivsWhereClause(userRoleNames, "grantee")),
                conn);

            OracleDataReader odr = cmd.ExecuteReader();

            if (!odr.HasRows)
            {
                return(false);
            }

            // purge old data
            purgeOldUserRoleSysPrivs(userRoleNames);

            while (odr.Read())
            {
                GrantedSysPrivilege grant = LoadPrivilege(odr);
                grants.Add(grant);
            }

            return(true);
        }
Example #6
0
        private bool refreshUserRoleData(UserRole userRole)
        {
            OracleCommand cmd = new OracleCommand(DBA_SYS_PRIVS_USERROLE_SELECT, conn);
            // set up parameters
            OracleParameter granteeParam = cmd.CreateParameter();

            granteeParam.ParameterName = "grantee";
            granteeParam.OracleDbType  = OracleDbType.Char;
            granteeParam.Direction     = System.Data.ParameterDirection.Input;
            granteeParam.Value         = userRole.Name;
            // execute
            OracleDataReader odr = cmd.ExecuteReader();

            if (!odr.HasRows)
            {
                return(false);
            }

            // purge user's data
            purgeOldUserRoleSysPrivs(userRole.Name);

            while (odr.Read())
            {
                GrantedSysPrivilege grant = LoadPrivilege(odr);
                grants.Add(grant);
            }

            return(false);
        }
Example #7
0
        public bool IsStrongerThan(GrantedSysPrivilege grant)
        {
            if (this.Privilege != grant.Privilege)
                throw new Exception("Incomparable privileges");

            return
                this.AdminOption &&
                !grant.AdminOption;
        }
Example #8
0
        public bool IsStrongerThan(GrantedSysPrivilege grant)
        {
            if (this.Privilege != grant.Privilege)
            {
                throw new Exception("Incomparable privileges");
            }

            return
                (this.AdminOption &&
                 !grant.AdminOption);
        }
Example #9
0
        public static string prepareGrantStatement(GrantedSysPrivilege grant)
        {
            ESysPrivilegeEnumConverter converter = new ESysPrivilegeEnumConverter();
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("GRANT {0} TO {1}",
                            converter.Convert(grant.Privilege, typeof(string), null, null),
                            grant.Grantee);

            if (grant.AdminOption)
            {
                sb.Append(" WITH ADMIN OPTION");
            }

            return(sb.ToString());
        }
Example #10
0
            public bool GetPrivilegeGrantInfo(ESysPrivilege privilege, out GrantedSysPrivilege grant)
            {
                IEnumerable <GrantedSysPrivilege> search =
                    from privGrant in privileges
                    where privGrant.Privilege == privilege
                    select privGrant;

                if (search.Count() > 0)
                {
                    grant = search.First();
                    return(true);
                }
                else
                {
                    grant = null;
                    return(false);
                }
            }
Example #11
0
        /// <summary>
        /// Refreshes information about all privilege grants
        /// </summary>
        public void RefreshUsersData()
        {
            OracleCommand    cmd = new OracleCommand(DBA_SYS_PRIVS_USERS_SELECT, conn);
            OracleDataReader odr = cmd.ExecuteReader();

            if (!odr.HasRows)
            {
                return;
            }

            grants.Clear();

            while (odr.Read())
            {
                GrantedSysPrivilege grant = LoadPrivilege(odr);
                grants.Add(grant);
            }

            // notify them about changes
            OnAllUsersSysPrivilegesRefreshed();
        }
Example #12
0
        /// <summary>
        /// ---TODO: return error code and string message (e.g. OracleException message?)
        /// </summary>
        /// <param name="grant"></param>
        /// <returns></returns>
        protected bool GrantSysPrivilege(GrantedSysPrivilege grant, out string errorMsg)
        {
            // check whether the grant can be performed etc.

            // perform a grant
            OracleCommand cmd = new OracleCommand(
                prepareGrantStatement(grant),
                conn);

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (OracleException e)
            {
                errorMsg = string.Format("Error occured:\r\n{0}", e.Message);
                return(false);
            }

            errorMsg = string.Empty;
            return(true);
        }
Example #13
0
        public void RefreshRolesData(ReadOnlyCollection <RoleManager.Role> roles)
        {
            StringCollection roleNames = (from userRole in roles select userRole.Name) as StringCollection;

            if (refreshUsersRolesData(roleNames))
            {
                OnRolesSysPrivilegesRefreshed(roles);
            }
            else
            {
                // try to load it from ROLE_SYS_PRIVS
                OracleCommand cmd = new OracleCommand(
                    string.Format("{0}\r\n{1}",
                                  ROLE_SYS_PRIVS_SELECT,
                                  createSysPrivsWhereClause(roleNames, "role")),
                    conn);

                OracleDataReader odr = cmd.ExecuteReader();

                if (!odr.HasRows)
                {
                    return;
                }

                // purge old data
                purgeOldUserRoleSysPrivs(roleNames);

                while (odr.Read())
                {
                    GrantedSysPrivilege grant = LoadPrivilege(odr);
                    grants.Add(grant);
                }

                // notify
                OnRolesSysPrivilegesRefreshed(roles);
            }
        }
Example #14
0
            public virtual bool GrantSysPrivilege(GrantedSysPrivilege grant, bool adminOption,
                                                  out string errorMsg)
            {
                //---TODO: kontrola, zda j*z neni prideleno???---

                // create a grant for user or role
                GrantedSysPrivilege newGrant = grant.CreateGrant(userRole, adminOption);

                // try to perform it via session-level priv manager
                if (!manager.GrantSysPrivilege(newGrant, out errorMsg))
                {
                    return(false);
                }

                // grant succeeded, add it to the collection and notify RoleManager
                // about a change to perform change distribution
                if (mergePrivilege(newGrant))
                {
                    OnPrivilegeGranted(grant.Privilege);
                }

                errorMsg = string.Empty;
                return(true);
            }
Example #15
0
 public virtual bool GrantSysPrivilege(GrantedSysPrivilege proposedGrant, bool adminOption)
 {
 }
Example #16
0
 private GrantedSysPrivilege createInheritedGrant(GrantedSysPrivilege grant)
 {
     return(new GrantedSysPrivilege(userRole.Name, grant.Privilege, false, false));
 }
Example #17
0
 public virtual bool GrantSysPrivilege(GrantedSysPrivilege proposedGrant, bool adminOption)
 {
 }