Beispiel #1
0
        public static HttpConfiguration Configure(WsFederationPluginOptions options)
        {
            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();
            config.SuppressDefaultHostAuthentication();

            config.MessageHandlers.Insert(0, new KatanaDependencyResolver());
            config.Services.Add(typeof(IExceptionLogger), new LogProviderExceptionLogger());
            config.Services.Replace(typeof(IHttpControllerTypeResolver), new HttpControllerTypeResolver());

            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;

            if (options.IdentityServerOptions.LoggingOptions.EnableWebApiDiagnostics)
            {
                var liblog = new TraceSource("LibLog");
                liblog.Switch.Level = SourceLevels.All;
                liblog.Listeners.Add(new LibLogTraceListener());

                var diag = config.EnableSystemDiagnosticsTracing();
                diag.IsVerbose   = options.IdentityServerOptions.LoggingOptions.WebApiDiagnosticsIsVerbose;
                diag.TraceSource = liblog;
            }

            if (options.IdentityServerOptions.LoggingOptions.EnableHttpLogging)
            {
                config.MessageHandlers.Add(new RequestResponseLogger());
            }

            return(config);
        }
        public static HttpConfiguration Configure(WsFederationPluginOptions options)
        {
            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();
            config.SuppressDefaultHostAuthentication();

            config.MessageHandlers.Insert(0, new KatanaDependencyResolver());
            config.Services.Add(typeof(IExceptionLogger), new LogProviderExceptionLogger());
            config.Services.Replace(typeof(IHttpControllerTypeResolver), new HttpControllerTypeResolver());

            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;

            if (options.IdentityServerOptions.LoggingOptions.EnableWebApiDiagnostics)
            {
                var liblog = new TraceSource("LibLog");
                liblog.Switch.Level = SourceLevels.All;
                liblog.Listeners.Add(new LibLogTraceListener());

                var diag = config.EnableSystemDiagnosticsTracing();
                diag.IsVerbose = options.IdentityServerOptions.LoggingOptions.WebApiDiagnosticsIsVerbose;
                diag.TraceSource = liblog;
            }

            if (options.IdentityServerOptions.LoggingOptions.EnableHttpLogging)
            {
                config.MessageHandlers.Add(new RequestResponseLogger());
            }

            return config;
        }
 public WsFederationController(SignInValidator validator, SignInResponseGenerator signInResponseGenerator, MetadataResponseGenerator metadataResponseGenerator, ITrackingCookieService cookies, WsFederationPluginOptions wsFedOptions)
 {
     _validator = validator;
     _signInResponseGenerator = signInResponseGenerator;
     _metadataResponseGenerator = metadataResponseGenerator;
     _cookies = cookies;
     _wsFedOptions = wsFedOptions;
 }
Beispiel #4
0
        private void ConfigurePlugins(IAppBuilder pluginApp, IdentityServerOptions options)
        {
            var wsFedOptions = new WsFederationPluginOptions(options);

            // data sources for in-memory services
            wsFedOptions.Factory.Register(new Registration<IEnumerable<RelyingParty>>(RelyingParties.Get()));
            wsFedOptions.Factory.RelyingPartyService = new Registration<IRelyingPartyService>(typeof(InMemoryRelyingPartyService));

            pluginApp.UseWsFederationPlugin(wsFedOptions);
        }
        public static IContainer Configure(WsFederationPluginOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            var factory = options.Factory;

            factory.Validate();

            var builder = new ContainerBuilder();

            // mandatory from factory
            builder.Register(factory.UserService);
            builder.Register(factory.RelyingPartyService);

            // optional from factory
            builder.RegisterDefaultType <ICustomWsFederationRequestValidator, DefaultCustomWsFederationRequestValidator>(factory.CustomRequestValidator);
            builder.RegisterDefaultType <Services.IRedirectUriValidator, DefaultRedirectUriValidator>(factory.RedirectUriValidator);
            builder.RegisterDefaultType <ICustomWsFederationClaimsService, DefaultCustomWsFederationClaimsService>(factory.CustomClaimsService);

            // validators
            builder.RegisterType <SignInValidator>().AsSelf();

            // processors
            builder.RegisterType <SignInResponseGenerator>().AsSelf();
            builder.RegisterType <MetadataResponseGenerator>().AsSelf();

            // general services
            builder.RegisterType <CookieMiddlewareTrackingCookieService>().As <ITrackingCookieService>();
            builder.RegisterInstance(options).AsSelf();
            builder.RegisterInstance(options.IdentityServerOptions).AsSelf();

            // load core controller
            builder.RegisterApiControllers(typeof(WsFederationController).Assembly);

            builder.Register <OwinEnvironmentService>(resolver => new OwinEnvironmentService(resolver.Resolve <IOwinContext>().Environment));

            // register additional dependencies from identity server
            foreach (var registration in options.IdentityServerOptions.Factory.Registrations)
            {
                builder.Register(registration);
            }

            // add any additional dependencies from hosting application
            foreach (var registration in factory.Registrations)
            {
                builder.Register(registration, registration.Name);
            }

            return(builder.Build());
        }
        private void ConfigureWsFederation(IAppBuilder pluginApp, IdentityServerOptions options)
        {
            var factory = new WsFederationServiceFactory(options.Factory);

            factory.RelyingPartyService = new Registration<IRelyingPartyService>(typeof(RelyingPartiesService));

            var wsFedOptions = new WsFederationPluginOptions
            {
                IdentityServerOptions = options,
                Factory = factory
                
            };

            pluginApp.UseWsFederationPlugin(wsFedOptions);

        }
        /// <summary>
        /// Add the WS-Federation plugin to the IdentityServer pipeline.
        /// </summary>
        /// <param name="app">The appBuilder.</param>
        /// <param name="options">The options.</param>
        /// <returns>The appBuilder</returns>
        /// <exception cref="System.ArgumentNullException">options</exception>
        public static IAppBuilder UseWsFederationPlugin(this IAppBuilder app, WsFederationPluginOptions options)
        {
            if (options == null) throw new ArgumentNullException("options");
            options.Validate();

            options.IdentityServerOptions.ProtocolLogoutUrls.Add(options.LogoutUrl);

            app.Map(options.MapPath, wsfedApp =>
                {
                    wsfedApp.UseCookieAuthentication(new CookieAuthenticationOptions
                    {
                        AuthenticationType = WsFederationPluginOptions.CookieName,
                        AuthenticationMode = AuthenticationMode.Passive,
                        CookieName = options.IdentityServerOptions.AuthenticationOptions.CookieOptions.Prefix + WsFederationPluginOptions.CookieName,
                    });

                    wsfedApp.Use<AutofacContainerMiddleware>(AutofacConfig.Configure(options));
                    Microsoft.Owin.Infrastructure.SignatureConversions.AddConversions(app);
                    wsfedApp.UseWebApi(WebApiConfig.Configure(options));
                });

            return app;
        }
 /// <summary>
 /// Initializes a new instance of the DefaultRedirectUriValidator class
 /// </summary>
 /// <param name="wsFedOptions">Plugin options which contain the set of valid redirect URIs</param>
 public DefaultRedirectUriValidator(WsFederationPluginOptions wsFedOptions)
 {
     _wsFedOptions = wsFedOptions;
 }