Пример #1
0
        /// <summary>
        /// Is the gate applicable for the current context
        /// </summary>
        /// <param name="gate">gate to check</param>
        /// <returns>true if applicable, false otherwise</returns>
        public bool IsGateApplicable(IGate gate)
        {
            if (!Code.ValidateArgument(gate, nameof(gate), TaggingUtilities.ReserveTag(0x2382104a /* tag_967bk */)) ||
                !Code.ValidateNotNullOrWhiteSpaceArgument(gate.Name, nameof(gate.Name), TaggingUtilities.ReserveTag(0x2382104b /* tag_967bl */)))
            {
                return(false);
            }

            if (IsKnownApplicableGate(gate.Name))
            {
                return(true);
            }

            if (IsKnownBlockedGate(gate.Name))
            {
                return(false);
            }

            bool grantAccess = IsGateApplicableInternal(gate);

            if (grantAccess)
            {
                KnownApplicableGates.AddOrUpdate(gate.Name, _ => 0, (_, __) => 0);
            }
            else
            {
                KnownBlockedGates.AddOrUpdate(gate.Name, _ => 0, (_, __) => 0);
            }

            return(grantAccess);
        }
Пример #2
0
        /// <summary>
        /// Is this a known blocked gate
        /// </summary>
        /// <param name="gateName">name of the gate</param>
        /// <returns>true if known blocked gate, false otherwise</returns>
        private bool IsKnownBlockedGate(string gateName)
        {
            if (KnownBlockedGates == null)
            {
                KnownBlockedGates = new ConcurrentDictionary <string, byte>(StringComparer.OrdinalIgnoreCase);

                ISet <string> blockedGates = Request?.BlockedGateIds;
                if (blockedGates != null)
                {
                    UpdateGatesDictionary(KnownBlockedGates, blockedGates);
                }

                UpdateGatesDictionary(KnownBlockedGates, m_settings?.GatesOverrideDisabled);
            }

            if (KnownBlockedGates.ContainsKey(gateName))
            {
                ULSLogging.LogTraceTag(0x2382104d /* tag_967bn */, Categories.GateSelection, Levels.Verbose,
                                       "Blocking access to gate '{0}' as it has been previously blocked.", gateName);
                return(true);
            }

            return(false);
        }