Esempio n. 1
0
        /// <summary>
        /// Asserts that the calling thread has the required identity.
        /// </summary>
        /// <param name="target">The required identity.</param>
        /// <param name="condition">
        /// If true, an exception is thrown when the thread does not meet target identity.
        /// If false, an exception is thrown when the thread does the target identity.
        /// </param>
        internal static void AssertIdentity(ScriptIdentity target, bool condition = true)
        {
            var thread   = LuaThread.running();
            var identity = GetIdentity(thread);

            if (identity == null || (target.HasFlag(identity) == condition))
            {
                return;                                                              // threads with no identity are unrestricted
            }
#if DEBUG
            var frame  = new StackFrame(1);
            var method = frame.GetMethod();
            var type   = method.DeclaringType;
            var name   = method.Name;
            throw new SecurityException($"Method {type}.{name} requires identity level {target}. (Current: {identity})");
#else
            throw new SecurityException();
#endif
        }
Esempio n. 2
0
 /// <summary/>
 internal ScriptSecurityAttribute(ScriptIdentity identity)
 {
     Identity = identity;
 }