예제 #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 applicable gate
        /// </summary>
        /// <param name="gateName">name of the gate</param>
        /// <returns>true if known applicable gate, false otherwise</returns>
        private bool IsKnownApplicableGate(string gateName)
        {
            if (KnownApplicableGates == null)
            {
                KnownApplicableGates = new ConcurrentDictionary <string, byte>(StringComparer.OrdinalIgnoreCase);

                ISet <string> requestedGates = Request?.RequestedGateIds;
                if (requestedGates != null)
                {
                    UpdateGatesDictionary(KnownApplicableGates, requestedGates);
                }

                UpdateGatesDictionary(KnownApplicableGates, m_settings?.GatesOverrideEnabled);
            }

            if (KnownApplicableGates.ContainsKey(gateName))
            {
                ULSLogging.LogTraceTag(0x2382104c /* tag_967bm */, Categories.GateSelection, Levels.Verbose,
                                       "Allowing access to gate '{0}' as it has been previously allowed.", gateName);
                return(true);
            }

            return(false);
        }