GetGatewayRules() публичный статический Метод

public static GetGatewayRules ( ) : List
Результат List
Пример #1
0
        public Shared.Types.BooleanResult AuthenticatedUserGateway(Shared.Types.SessionProperties properties)
        {
            UserInformation userInfo = properties.GetTrackedSingle<UserInformation>();

            try
            {
                using (MySqlUserDataSource dataSource = new MySqlUserDataSource())
                {
                    List<GroupGatewayRule> rules = GroupRuleLoader.GetGatewayRules();

                    foreach (GroupGatewayRule rule in rules)
                    {
                        m_logger.DebugFormat("Checking rule: {0}", rule.ToString());
                        if (rule.RuleMatch(dataSource.IsMemberOfGroup(userInfo.Username, rule.Group)))
                        {
                            m_logger.DebugFormat("Rule is a match, adding to {0}", rule.LocalGroup);
                            userInfo.Groups.Add(new GroupInformation { Name = rule.LocalGroup });
                        }
                        else
                        {
                            m_logger.DebugFormat("Rule is not a match");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_logger.ErrorFormat("Unexpected error: {0}", e);
                throw;
            }
            
            // Always return success
            return new Shared.Types.BooleanResult { Success = true };
        }
Пример #2
0
        public Shared.Types.BooleanResult AuthenticatedUserGateway(Shared.Types.SessionProperties properties)
        {
            UserInformation userInfo = properties.GetTrackedSingle <UserInformation>();

            try
            {
                using (MySqlUserDataSource dataSource = new MySqlUserDataSource())
                {
                    List <GroupGatewayRule> rules = GroupRuleLoader.GetGatewayRules();

                    foreach (GroupGatewayRule rule in rules)
                    {
                        m_logger.DebugFormat("Checking rule: {0}", rule.ToString());
                        if (rule.RuleMatch(dataSource.IsMemberOfGroup(userInfo.Username, rule.Group)))
                        {
                            m_logger.DebugFormat("Rule is a match, adding to {0}", rule.LocalGroup);
                            userInfo.Groups.Add(new GroupInformation {
                                Name = rule.LocalGroup
                            });
                        }
                        else
                        {
                            m_logger.DebugFormat("Rule is not a match");
                        }
                    }
                }
            }
            catch (MySqlException e)
            {
                bool preventLogon = Settings.Store.PreventLogonOnServerError;
                if (preventLogon)
                {
                    m_logger.DebugFormat("Encountered MySQL server error, and preventing logon: {0}", e.Message);
                    return(new BooleanResult {
                        Success = false,
                        Message = string.Format("Preventing logon due to server error: {0}", e.Message)
                    });
                }
                else
                {
                    m_logger.DebugFormat("Encoutered MySQL server error, but returning success anyway.  Error: {0}", e.Message);
                    return(new BooleanResult {
                        Success = true,
                        Message = string.Format("Encountered server error: {0}", e.Message)
                    });
                }
            }
            catch (Exception e)
            {
                m_logger.ErrorFormat("Unexpected error: {0}", e);
                throw;
            }

            // Always return success
            return(new Shared.Types.BooleanResult {
                Success = true
            });
        }
Пример #3
0
        private void InitUI()
        {
            this.hostTB.Text = Settings.Store.Host;
            int port = Settings.Store.Port;

            this.portTB.Text     = Convert.ToString(port);
            this.userTB.Text     = Settings.Store.User;
            this.passwordTB.Text = Settings.Store.GetEncryptedSetting("Password");
            this.dbTB.Text       = Settings.Store.Database;
            bool useSsl = Settings.Store.UseSsl;

            this.useSslCB.Checked = useSsl;

            // User table schema settings
            this.userTableTB.Text         = Settings.Store.Table;
            this.unameColTB.Text          = Settings.Store.UsernameColumn;
            this.hashMethodColTB.Text     = Settings.Store.HashMethodColumn;
            this.passwdColTB.Text         = Settings.Store.PasswordColumn;
            this.userPrimaryKeyColTB.Text = Settings.Store.UserTablePrimaryKeyColumn;

            int encodingInt = Settings.Store.HashEncoding;

            Settings.HashEncoding encoding = (Settings.HashEncoding)encodingInt;

            if (encoding == Settings.HashEncoding.HEX)
            {
                this.encHexRB.Checked = true;
            }
            else
            {
                this.encBase64RB.Checked = true;
            }

            // Group table schema settings
            this.groupTableNameTB.Text          = Settings.Store.GroupTableName;
            this.groupNameColTB.Text            = Settings.Store.GroupNameColumn;
            this.groupTablePrimaryKeyColTB.Text = Settings.Store.GroupTablePrimaryKeyColumn;

            // User-Group table settings
            this.userGroupTableNameTB.Text  = Settings.Store.UserGroupTableName;
            this.userGroupUserFKColTB.Text  = Settings.Store.UserForeignKeyColumn;
            this.userGroupGroupFKColTB.Text = Settings.Store.GroupForeignKeyColumn;

            // Gateway rules
            List <GroupGatewayRule> gwLst = GroupRuleLoader.GetGatewayRules();

            foreach (GroupGatewayRule rule in gwLst)
            {
                this.gtwRulesListBox.Items.Add(rule);
            }
            this.gtwRuleConditionCB.SelectedIndex = 0;
        }
Пример #4
0
        private void InitUI()
        {
            this.hostTB.Text = Settings.Store.Host;
            int port = Settings.Store.Port;
            this.portTB.Text = Convert.ToString(port);
            this.userTB.Text = Settings.Store.User;
            this.passwordTB.Text = Settings.Store.GetEncryptedSetting("Password");
            this.dbTB.Text = Settings.Store.Database;
            bool useSsl = Settings.Store.UseSsl;
            this.useSslCB.Checked = useSsl;

            // User table schema settings
            this.userTableTB.Text = Settings.Store.Table;
            this.unameColTB.Text = Settings.Store.UsernameColumn;
            this.hashMethodColTB.Text = Settings.Store.HashMethodColumn;
            this.passwdColTB.Text = Settings.Store.PasswordColumn;
            this.userPrimaryKeyColTB.Text = Settings.Store.UserTablePrimaryKeyColumn;

            int encodingInt = Settings.Store.HashEncoding;
            Settings.HashEncoding encoding = (Settings.HashEncoding)encodingInt;

            if (encoding == Settings.HashEncoding.HEX)
                this.encHexRB.Checked = true;
            else
                this.encBase64RB.Checked = true;

            // Group table schema settings
            this.groupTableNameTB.Text = Settings.Store.GroupTableName;
            this.groupNameColTB.Text = Settings.Store.GroupNameColumn;
            this.groupTablePrimaryKeyColTB.Text = Settings.Store.GroupTablePrimaryKeyColumn;

            // User-Group table settings
            this.userGroupTableNameTB.Text = Settings.Store.UserGroupTableName;
            this.userGroupUserFKColTB.Text = Settings.Store.UserForeignKeyColumn;
            this.userGroupGroupFKColTB.Text = Settings.Store.GroupForeignKeyColumn;

            /////////////// Authorization tab /////////////////
            this.cbAuthzMySqlGroupMemberOrNot.SelectedIndex = 0;
            this.cbAuthzGroupRuleAllowOrDeny.SelectedIndex = 0;

            this.ckDenyWhenMySqlAuthFails.Checked = Settings.Store.AuthzRequireMySqlAuth;

            List<GroupAuthzRule> lst = GroupRuleLoader.GetAuthzRules();
            // The last one should be the default rule
            if (lst.Count > 0 &&
                lst[lst.Count - 1].RuleCondition == GroupRule.Condition.ALWAYS)
            {
                GroupAuthzRule rule = lst[lst.Count - 1];
                if (rule.AllowOnMatch)
                    this.rbDefaultAllow.Checked = true;
                else
                    this.rbDefaultDeny.Checked = true;
                lst.RemoveAt(lst.Count - 1);
            }
            else
            {
                // The list is empty or the last rule is not a default rule.
                throw new Exception("Default rule not found in rule list.");
            }
            // The rest of the rules
            foreach (GroupAuthzRule rule in lst)
                this.listBoxAuthzRules.Items.Add(rule);

            ///////////////// Gateway tab ///////////////
            List<GroupGatewayRule> gwLst = GroupRuleLoader.GetGatewayRules();
            foreach (GroupGatewayRule rule in gwLst)
                this.gtwRulesListBox.Items.Add(rule);
            this.gtwRuleConditionCB.SelectedIndex = 0;

            this.m_preventLogonWhenServerUnreachableCb.Checked = Settings.Store.PreventLogonOnServerError;
        }