Example #1
0
        public static IPolicyServerBuilder AddRequiredPlatformServices(this IPolicyServerBuilder builder)
        {
            builder.Services.AddOptions();
            builder.Services.AddSingleton(p => p.GetRequiredService <IOptions <PolicyServerOptions> >().Value);

            return(builder);
        }
Example #2
0
        public static IPolicyServerBuilder AddEndpoint <T>(this IPolicyServerBuilder builder, String name, PathString path) where T : class, IEndpointHandler
        {
            builder.Services.AddTransient <T>();
            builder.Services.AddSingleton(new Endpoint(name, path, typeof(T)));

            return(builder);
        }
Example #3
0
        public static IPolicyServerBuilder AddRequestParsers(this IPolicyServerBuilder builder)
        {
            builder.Services.AddTransient <IPolicyRequestParser, DefaultPolicyRequestParser>();
            builder.Services.AddTransient <IPermissionRequestParser, DefaultPermissionRequestParser>();

            return(builder);
        }
 public static IPolicyServerBuilder AddConfigurationStore(
     this IPolicyServerBuilder builder,
     Action <clientStoreOptions> storeOptionsAction = null
     )
 {
     return(builder.AddConfigurationStore <PolicyDbContext>(storeOptionsAction));
 }
Example #5
0
        public static IPolicyServerBuilder AddInMemoryCaching(this IPolicyServerBuilder builder)
        {
            builder.Services.TryAddSingleton <IMemoryCache, MemoryCache>();
            builder.Services.TryAddTransient(typeof(ICache <>), typeof(DefaultCache <>));

            return(builder);
        }
        public static IPolicyServerBuilder AddRoleStore <T>(this IPolicyServerBuilder builder) where T : class, IRoleStore
        {
            builder.Services.TryAddTransient(typeof(T));
            builder.Services.AddTransient <IRoleStore, ValidatingRoleStore <T> >();

            return(builder);
        }
Example #7
0
        public static IPolicyServerBuilder AddResponseGenerators(this IPolicyServerBuilder builder)
        {
            builder.Services.AddTransient <IPolicyResponseGenerator, DefaultPolicyResponseGenerator>();
            builder.Services.AddTransient <IPermissionResponseGenerator, DefaultPermissionResponseGenerator>();
            builder.Services.AddTransient <IDiscoveryResponseGenerator, DefaultDiscoveryResponseGenerator>();

            return(builder);
        }
Example #8
0
        /// <summary>
        /// Adds the in memory clients.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="section">The configuration section containing the configuration data.</param>
        /// <returns></returns>
        public static IPolicyServerBuilder AddInMemoryPolicies(this IPolicyServerBuilder builder, IConfigurationSection section)
        {
            List <Client> clients = new List <Client>();

            section.Bind(clients);

            return(builder.AddInMemoryPolicies(clients));
        }
        public static IPolicyServerBuilder AddPermissionStoreCache <T>(this IPolicyServerBuilder builder) where T : IPermissionStore
        {
            builder.Services.TryAddTransient(typeof(T));
            builder.Services.AddTransient <ValidatingPermissionStore <T> >();
            builder.Services.AddTransient <IPermissionStore, CachingPermissionStore <ValidatingPermissionStore <T> > >();

            return(builder);
        }
Example #10
0
        public static IPolicyServerBuilder AddValidators(this IPolicyServerBuilder builder)
        {
            builder.Services.TryAddTransient <IPolicyConfigurationValidator, DefaultPolicyConfigurationValidator>();
            builder.Services.TryAddTransient <IClientConfigurationValidator, DefaultClientConfigurationValidator>();
            builder.Services.TryAddTransient <IPermissionConfigurationValidator, DefaultPermissionConfigurationValidator>();
            builder.Services.TryAddTransient <IRoleConfigurationValidator, DefaultRoleConfigurationValidator>();

            return(builder);
        }
Example #11
0
        public static IPolicyServerBuilder AddDefaultEndpoints(this IPolicyServerBuilder builder)
        {
            builder.Services.AddTransient <IEndpointRouter, EndpointRouter>();

            builder.AddEndpoint <PolicyEndpoint>(EndpointNames.Policy, ProtocolRoutePaths.Policy.EnsureLeadingSlash());
            builder.AddEndpoint <PermissionEndpoint>(EndpointNames.Permission, ProtocolRoutePaths.Permission.EnsureLeadingSlash());
            builder.AddEndpoint <DiscoveryEndpoint>(EndpointNames.Discovery, ProtocolRoutePaths.DiscoveryConfiguration.EnsureLeadingSlash());

            return(builder);
        }
        public static IPolicyServerBuilder AddConfigurationStoreCache(
            this IPolicyServerBuilder builder
            )
        {
            builder.AddInMemoryCaching();
            builder.AddClientStoreCache <ClientStore>();
            builder.AddPolicyStoreCache <PolicyStore>();
            builder.AddPermissionStoreCache <PermissionStore>();
            builder.AddRoleStoreCache <RoleStore>();

            return(builder);
        }
        public static IPolicyServerBuilder AddPolicyServer(this IServiceCollection services)
        {
            IPolicyServerBuilder builder = services.AddPolicyServerBuilder();

            builder
            .AddRequiredPlatformServices()
            .AddDefaultEndpoints()
            .AddValidators()
            .AddRequestParsers()
            .AddResponseGenerators()
            .AddServices();

            return(builder);
        }
        public static IPolicyServerBuilder AddConfigurationStore <TContext>(
            this IPolicyServerBuilder builder,
            Action <clientStoreOptions> storeOptionsAction = null
            ) where TContext : DbContext, IPolicyDbContext
        {
            builder.Services.AddPolicyDbContext <TContext>(storeOptionsAction);

            builder.AddClientStore <ClientStore>();
            builder.AddPolicyStore <PolicyStore>();
            builder.AddPermissionStore <PermissionStore>();
            builder.AddRoleStore <RoleStore>();


            return(builder);
        }
Example #15
0
        public static IPolicyServerBuilder AddInMemoryPolicies(this IPolicyServerBuilder builder, IEnumerable <Client> clients)
        {
            builder.Services.AddSingleton(clients);

            builder.AddClientStore <InMemoryClientStore>();

            //var existingCors = builder.Services.Where(x => x.ServiceType == typeof(ICorsPolicyService)).LastOrDefault();
            //if (existingCors != null &&
            //    existingCors.ImplementationType == typeof(DefaultCorsPolicyService) &&
            //    existingCors.Lifetime == ServiceLifetime.Transient) {
            //    // if our default is registered, then overwrite with the InMemoryCorsPolicyService
            //    // otherwise don't overwrite with the InMemoryCorsPolicyService, which uses the custom one registered by the host
            //    builder.Services.AddTransient<ICorsPolicyService, InMemoryCorsPolicyService>();
            //}

            return(builder);
        }
Example #16
0
        public static IPolicyServerBuilder AddServices(this IPolicyServerBuilder builder)
        {
            builder.Services.AddTransient <IPolicyService, DefaultPolicyService>();

            return(builder);
        }