Пример #1
0
        /// <summary>
        /// Runs the rules against the username, modifying it for future plugins.
        /// If an IMatchRule is present, AuthenticatedUserGateway will only return true if
        /// the username matches the rule.
        /// </summary>
        /// <param name="properties"></param>
        /// <returns></returns>
        BooleanResult IPluginAuthenticationGateway.AuthenticatedUserGateway(SessionProperties properties)
        {
            try
            {
                m_logger.DebugFormat("GatewayUser({0})", properties.Id.ToString());

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

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

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

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

                foreach (IUsernameRule rule in rules.list)
                {
                    if (rule.stage == Stage.Gateway)
                    {
                        m_logger.DebugFormat("[Gateway] 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
                            authGateway = ((IMatchRule)rule).match(username) ? authGateway : false;
                            m_logger.DebugFormat("Auth'd Gateway? {0}", authGateway);
                        }
                    }
                }

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

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

            catch (Exception e)
            {
                m_logger.ErrorFormat("Error running rules. {0}", e.Message);
                return(new BooleanResult()
                {
                    Success = false, Message = "Unable to modify username during gateway stage."
                });
            }
        }
Пример #2
0
        /// <summary>
        /// Runs the rules against the username, modifying it for future plugins.
        /// If a IMatchRule is present and matches, it will allow a login for that
        /// user regardless of an entered password.
        /// </summary>
        /// <param name="properties"></param>
        /// <returns></returns>
        BooleanResult IPluginAuthentication.AuthenticateUser(SessionProperties properties)
        {
            try
            {
                m_logger.DebugFormat("AuthenticateUser({0})", properties.Id.ToString());

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

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

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

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

                foreach (IUsernameRule rule in rules.list)
                {
                    if (rule.stage == Stage.Authentication)
                    {
                        m_logger.DebugFormat("[Authentication] Running 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)
                        {
                            authenticated = ((IMatchRule)rule).match(username) ? true : authenticated;
                            m_logger.DebugFormat("Authenticated? {0}", authenticated);
                        }
                    }
                }

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

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

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