Пример #1
0
        public Configuration()
        {
            InitializeComponent();
            
            //Setup the drop down box
            actionBox.Items.AddRange(ListOfRules.Rules);
            this.actionBox.SelectedIndex = 0;
            
            //Get list of rules
            try
            {
                rules = new ListOfRules();
                rules.Load();
                
            }
            catch (UsernameModPluginException)
            {
                MessageBox.Show("Unable to load all rules from registry.");
            }
            updateListView();

            resetForm();
        }
Пример #2
0
 public void Starting()
 {
     rules = new ListOfRules();
     rules.Load();
 }
Пример #3
0
        /// <summary>
        /// Runs the rules against the username, modifying it for future plugins.
        /// If an IMatchRule is present, AuthorizeUser will only return true if
        /// the username matches the rule.
        /// </summary>
        /// <param name="properties"></param>
        /// <returns></returns>
        BooleanResult IPluginAuthorization.AuthorizeUser(SessionProperties properties)
        {
            try
            {
                m_logger.DebugFormat("AuthorizeUser({0})", properties.Id.ToString());

                ListOfRules rules = new ListOfRules();
                rules.Load();

                // Get user info
                UserInformation userInfo = properties.GetTrackedSingle<UserInformation>();

                bool authorized = true; //By default, we don't authenticate
                string username = userInfo.Username;

                m_logger.DebugFormat("Start of Authorization, username: {0}", username);

                foreach (IUsernameRule rule in rules.list)
                {
                    if (rule.stage == Stage.Authorization)
                    {
                        m_logger.DebugFormat("[Authorization] Checking rule: {0}", rule.ToString());
                        if (rule is IModifyRule)
                        {
                            IModifyRule mRule = (IModifyRule)rule;
                            username = mRule.modify(username);
                            m_logger.DebugFormat("Username modified: {0}", username);
                        }
                        else if (rule is IMatchRule)
                        {
                            //If the match rule fails, do not authorize
                            authorized = ((IMatchRule)rule).match(username) ? authorized : false;
                            m_logger.DebugFormat("Authorized? {0}", authorized);
                        }
                    }
                }

                //Set the changes to the username
                userInfo.Username = username;

                return new BooleanResult() { Success = authorized };
            }

            catch (Exception e)
            {
                m_logger.ErrorFormat("Error running rules. {0}", e.Message);
                return new BooleanResult() { Success = false, Message = "Unable to modify username during authorization stage." };
            }
        }