예제 #1
0
파일: AppKeeper.cs 프로젝트: Agnael/Sero
        public AppKeeper(ILoxy loxy)
        {
            if (loxy == null)
            {
                throw new ArgumentNullException(nameof(loxy));
            }

            _loxy = loxy;
        }
예제 #2
0
        public LoggerProxy(ILoxy loxy, Action <LoggerProxyOptions> config)
        {
            LoggerProxyOptions defaultOptions = new LoggerProxyOptions();

            config(defaultOptions);

            _loxy   = loxy;
            Options = defaultOptions;
        }
예제 #3
0
        public LoggerFactoryProxy(ILoxy eventLogger, Action <LoggerProxyOptions> config)
        {
            Id      = new Guid();
            _events = eventLogger;

            LoggerProxyOptions defaultOptions = new LoggerProxyOptions();

            config(defaultOptions);
            Options = defaultOptions;
        }
예제 #4
0
        protected override async Task OnBefore(HttpContext context)
        {
            _loxy = (ILoxy)context.RequestServices.GetService(typeof(ILoxy));

            if (_loxy == null)
            {
                throw new LoxyNotFoundException();
            }

            if (_loxy.Sinks == null || _loxy.Sinks.Count == 0)
            {
                throw new NoSinksRegisteredException();
            }
        }
예제 #5
0
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigureSerilog();

            services.AddLogging(x => x.AddSerilog());

            services.TryAddSingleton <HateoasService>();

            services.AddRequestInfo();
            services.AddLoxy()
            .Sinks.AddJsonSink()
            .WithMinimumLevel(LogLevel.Debug)
            .WithExtendedLevel(LogLevel.Error)
            .WithJsonFormatting(Formatting.Indented);

            // Configurations
            services.AddOptions <GtkOptions>()
            .Bind(Config.GetSection("Gatekeeper"))
            .ValidateEagerly();

            // Stores
            services.AddSingleton <IResourceStore>(_ => new InMemoryResourceStore(GetTestResources()));
            services.AddSingleton <IRoleStore>(_ => new InMemoryRoleStore(GetTestRoles()));
            services
            .AddSingleton <ICredentialStore>(serviceCollection =>
            {
                ISessionStore sessionStore = serviceCollection.GetService <ISessionStore>();
                return(new InMemoryCredentialStore(sessionStore, GetTestCredentials()));
            });
            services.AddSingleton <ISessionStore>(_ => new InMemorySessionStore());
            services.AddSingleton <ILoginAttemptStore>(_ => new InMemoryLoginAttemptStore());
            services.AddSingleton <ICredentialPenaltyStore>(_ => new InMemoryCredentialPenaltyStore());

            services.AddTransient <ILoginAttemptLimitingService, DefaultLoginAttemptLimitingService>();

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(x =>
            {
                x.Events = new JwtBearerEvents
                {
                    OnTokenValidated = async context =>
                    {
                        ILoxy loxy = context.HttpContext.RequestServices.GetService <ILoxy>();
                        loxy.Raise(new Event(LogLevel.Information, "Gatekeeper", context.Principal.GetCredentialId()));
                    }
                };

                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer = true,
                    //ValidateAudience = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Config["Auth:Issuer"],
                    ValidAudience    = Config["Auth:Audience"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Config["Auth:SigningSecret"])),
                    ClockSkew        = TimeSpan.Zero
                };
            });

            services.AddGatekeeper();

            services.AddControllers(conf => {
                conf.Filters.Add <GtkActionFilter>();
                conf.Filters.Add <HateoasFilter>();
            });
        }
예제 #6
0
 public LoggerProxy(ILoxy loxy, LoggerProxyOptions options)
 {
     _loxy   = loxy;
     Options = options;
 }
예제 #7
0
 public LoggerProxy(ILoxy loxy)
 {
     _loxy   = loxy;
     Options = new LoggerProxyOptions();
 }
예제 #8
0
 public ValuesController(ILoxy loxy)
 {
     _loxy = loxy;
 }
예제 #9
0
 public LoggerFactoryProxy(ILoxy eventLogger)
 {
     Id      = new Guid();
     _events = eventLogger;
 }
예제 #10
0
 public LoggerFactoryProxy(ILoxy eventLogger, LoggerProxyOptions options)
 {
     Id      = new Guid();
     _events = eventLogger;
     Options = options;
 }
예제 #11
0
 public LoggerProviderProxy(ILoxy eventLogger)
 {
     Id      = new Guid();
     _events = eventLogger;
 }
예제 #12
0
        public static DbContextOptionsBuilder UseLoxyAsLoggerFactory(this DbContextOptionsBuilder options, ILoxy loxy, string logCategory)
        {
            options.UseLoggerFactory(
                loxy.AsLoggerFactory(proxy =>
                                     proxy.WithCategory(logCategory)
                                     .WithStateFormatterFactory(new EfStateFormatterFactory()) // EXPERIMENTAL SHIT, TO BE SURE IT WORKS YOU ARE BETTER OFF USING THE DEFAULT StateFormatter
                                     )
                );

            return(options);
        }