예제 #1
0
 public static void AddScopePolicies <TController>(
     this AuthorizationOptions options,
     string issuer,
     Assembly assembly   = null,
     bool fromReferenced = false)
 {
     foreach (var attr in ScopeAuthorizeHelper
              .GetAllScopeAuthorizeAttributes <TController>(
                  assembly, fromReferenced))
     {
         options.AddScopePolicy(attr.Scope, issuer);
     }
 }
예제 #2
0
        GetAllScopeAuthorizeAttributes <TController>(
            Assembly assembly = null, bool fromReferenced = false)
        {
            var ass   = assembly ?? Assembly.GetEntryAssembly();
            var ttype = typeof(TController);

            foreach (var typeInfo in ass.DefinedTypes)
            {
                if (!(typeInfo.IsSubclassOf(ttype) ||
                      typeInfo.IsInstanceOfType(ttype)))
                {
                    continue;
                }

                foreach (var methodInfo in typeInfo.GetMethods())
                {
                    foreach (var attribute in methodInfo
                             .GetCustomAttributes <ScopeAuthorizeAttribute>(true))
                    {
                        yield return(attribute);
                    }
                }
            }

            if (fromReferenced)
            {
                foreach (var items in ass.GetReferencedAssemblies()
                         .Select(s => ScopeAuthorizeHelper
                                 .GetAllScopeAuthorizeAttributes <TController>(
                                     Assembly.Load(s))))
                {
                    foreach (var item in items)
                    {
                        yield return(item);
                    }
                }
            }
        }