Exemple #1
0
        /// <summary>
        /// Gets Windows Identity associated with this group
        /// </summary>
        /// <param name="incomingIdentity">Incoming identity</param>
        /// <returns>Windows Identity associated with this group</returns>
        public WindowsIdentity GetWindowsIdentity(WindowsIdentity incomingIdentity)
        {
            WindowsIdentity identity = null;

            if (this.MapIncomingUser == true)
            {
                if (incomingIdentity == null)
                {
                    throw new ArgumentException("Current user is mapped to group " + this.Name + " which is expected to return context of the incoming user. But context of the incoming user passed is null.");
                }

                return(incomingIdentity);
            }

            if (this.UserName == null || this.Password == null)
            {
                if (this.UserName == null && this.Password == null)
                {
                    identity = WindowsIdentityHelper.GetCurrentWindowsIdentity();
                }
                else
                {
                    if (this.UserName == null)
                    {
                        throw new ArgumentException("User name is null for group " + this.Name);
                    }

                    if (this.Password == null)
                    {
                        throw new ArgumentException("Password is null for group " + this.Name);
                    }
                }
            }
            else
            {
                identity = WindowsIdentityHelper.GetWindowsIdentity(this.UserName, this.Password, this.DomainName);
            }

            return(identity);
        }
        /// <summary>
        /// Populates the RbacSystem from an RBAC configuration file
        /// </summary>
        /// <param name="configPath">full path to the config file</param>
        private void Populate(string configPath)
        {
            this.Reset();

            XmlConfiguration rbacConfiguration = XmlConfiguration.Create(configPath);

            foreach (XmlGroup group in rbacConfiguration.Groups)
            {
                WindowsIdentity identity = null;

                try
                {
                    if (group.UserName == null || group.Password == null)
                    {
                        if (group.UserName != null || group.Password != null)
                        {
                            if (group.UserName == null)
                            {
                                throw new ArgumentException("User name is null for group " + group.Name);
                            }

                            if (group.Password == null)
                            {
                                throw new ArgumentException("Password is null for group " + group.Name);
                            }
                        }
                    }
                    else
                    {
                        if (group.DomainName == null)
                        {
                            group.DomainName = Environment.MachineName;
                        }

                        identity = WindowsIdentityHelper.GetWindowsIdentity(group.UserName, group.Password, group.DomainName);
                    }
                }
                catch (Exception)
                {
                    // Not able to get the impersonated WindowsIdentity
                    // use the current WindowsIdentity
                    identity = WindowsIdentity.GetCurrent();
                }

                this.Groups.Add(new RbacGroup(group));
            }

            foreach (XmlUser userConfig in rbacConfiguration.Users)
            {
                RbacUser  user  = new RbacUser(new RbacUser.RbacUserInfo(userConfig.Name, userConfig.AuthenticationType, userConfig.DomainName), userConfig.Quota);
                RbacGroup group = this.Groups.Find(item => item.Name == userConfig.GroupName);
                if (group == null)
                {
                    throw new ArgumentException("Group not found = " + userConfig.GroupName);
                }

                user.Group = group;

                this.Users.Add(user);
            }
        }