Ejemplo n.º 1
0
 public LoginController(
     ApplicationUserManager userManager,
     ApplicationSignInManager signInManager,
     ApplicationInvitationManager invitationManager,
     ApplicationOrganizationManager organizationManager,
     ApplicationWebsiteManager websiteManager)
 {
     UserManager         = userManager;
     SignInManager       = signInManager;
     InvitationManager   = invitationManager;
     OrganizationManager = organizationManager;
     WebsiteManager      = websiteManager;
 }
Ejemplo n.º 2
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and role manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationOrganizationManager>(ApplicationOrganizationManager.Create);
            app.CreatePerOwinContext <ApplicationWebsiteManager>(ApplicationWebsiteManager.Create);
            app.CreatePerOwinContext <ApplicationWebsite>(ApplicationWebsite.Create);
            app.CreatePerOwinContext <ApplicationPortalContextManager>(ApplicationPortalContextManager.Create);
            app.CreatePerOwinContext <ApplicationInvitationManager>(ApplicationInvitationManager.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create);

            var request                   = HttpContext.Current.Request.RequestContext;
            var websiteManager            = ApplicationWebsiteManager.Create(ApplicationDbContext.Create());
            var url                       = new UrlHelper(request);
            var loginPath                 = new PathString(url.Action("Login", "Login", new { area = "Account" }));
            var externalLoginCallbackPath = new PathString(url.Action("ExternalLoginCallback", "Login", new { area = "Account" }));
            var website                   = websiteManager.Find(request);
            var settingsManager           = new ApplicationStartupSettingsManager(website, (manager, user) => user.GenerateUserIdentityAsync(manager), loginPath, externalLoginCallbackPath);



            app.UseSiteMapAuthentication(settingsManager.ApplicationCookie);

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie
            app.UseKentorOwinCookieSaver();
            app.UseCookieAuthentication(settingsManager.ApplicationCookie);
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, settingsManager.TwoFactorCookie.ExpireTimeSpan);

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            app.UsePortalsAuthentication(settingsManager);
        }
Ejemplo n.º 3
0
 public ManageController(ApplicationUserManager userManager, ApplicationOrganizationManager organizationManager, ApplicationWebsiteManager websiteManager)
 {
     UserManager         = userManager;
     OrganizationManager = organizationManager;
     WebsiteManager      = websiteManager;
 }
        public void ConfigurePortal(IAppBuilder app)
        {
            var host           = new PortalHostingEnvironment();
            var webAppSettings = WebAppSettings.Instance;

            // For cache we create one subscription per instance of web app, that's why we use instance id as the subscription name.
            var cacheEventHubJobSettings = new EventHubJobSettings(webAppSettings.InstanceId, EventHubSubscriptionType.CacheSubscription);

            // For search we create one subscription per webapp, that's why we use site name as the subscription name.
            var searchEventHubJobSettings = new EventHubJobSettings(webAppSettings.SiteName, EventHubSubscriptionType.SearchSubscription);

            var requireSslOptions = new RequireSslOptions(webAppSettings);

            var warmupCacheSettings = new WarmupCacheSettings();

            app.ConfigureApplicationLifecycleEvents();
            app.UseETWMiddleware();
            app.UseRequireSsl(requireSslOptions);
            app.UseAppInfo();
            app.UseHealth();
            app.UseScaleOutTelemetry();
            app.UseRequestTelemetry(SetupConfig.IsPortalConfigured);
            app.UseApplicationRestartPluginMessage(new PluginMessageOptions());
            app.UsePortalBus <ApplicationRestartPortalBusMessage>(webAppSettings, cacheEventHubJobSettings);
            app.UsePortalBus <CacheInvalidationPortalBusMessage>(webAppSettings, cacheEventHubJobSettings);
            app.CreatePerOwinContext <RequestElapsedTimeContext>(RequestElapsedTimeContext.Create);

            if (!SetupConfig.InitialSetupIsRunning() && !SetupConfig.ProvisioningInProgress())
            {
                using (PerformanceProfiler.Instance.StartMarker(PerformanceMarkerName.Startup, PerformanceMarkerArea.Crm, PerformanceMarkerTagName.StartUpConfiguration))
                {
                    // indepdendent components
                    app.CreatePerOwinContext(ApplicationDbContext.Create);
                    var portalSolutions = app.ConfigurePortalSolutionsDetails(ApplicationDbContext.Create());
                    app.CreatePerOwinContext <ApplicationOrganizationManager>(ApplicationOrganizationManager.Create);
                    app.CreatePerOwinContext <ApplicationWebsiteManager>(ApplicationWebsiteManager.Create);
                    app.CreatePerOwinContext <CrmWebsite>((options, context) => ApplicationWebsite.Create(options, context, host));

                    // Set the culture for this request.
                    app.UseCurrentThreadCulture();

                    ApplicationWebsiteManager websiteManager;

                    try
                    {
                        var settings = new CrmEntityStoreSettings {
                            PortalSolutions = portalSolutions
                        };
                        websiteManager = ApplicationWebsiteManager.Create(ApplicationDbContext.Create(), settings);
                    }
                    catch
                    {
                        //We need to unload app domain in order to reinitialize owin during next request
                        TelemetryState.ApplicationEndInfo = ApplicationEndFlags.Configuration;
                        Adxstudio.Xrm.Web.Extensions.RestartWebApplication();
                        return;
                    }

                    var website     = websiteManager.Find(HttpContext.Current.Request.RequestContext, host);
                    var hstsOptions = new StrictTransportSecurityOptions(website);

                    // components that depend on the website
                    app.UpdatePrimaryDomainName(websiteManager, website, portalSolutions);
                    app.ConfigureDisplayModes(website);
                    app.UseWebsiteHeaderSettings(website);
                    app.UseStrictTransportSecuritySettings(hstsOptions);
                    app.ConfigureSearchProvider(website);

                    var contentMapProvider = app.ConfigureContentMap(ApplicationDbContext.Create, website, cacheEventHubJobSettings, portalSolutions);

                    // configure user dependencies
                    this.ConfigureAuth(app, website);

                    // components that depend on the user
                    app.CreatePerOwinContext <ContextLanguageInfo>(ContextLanguageInfo.Create);

                    // Complete the authentication stage prior to invoking page handler
                    app.UseStageMarker(PipelineStage.Authenticate);

                    // components that depend on content map
                    app.ConfigureCulture(website, contentMapProvider, BundleTable.Bundles, BundleConfig.RegisterLanguageSpecificBundles);

                    // tail end components
                    app.ConfigureEventHubCacheInvalidation(website.Id, ApplicationDbContext.Create, cacheEventHubJobSettings, searchEventHubJobSettings, new CacheInvalidationJobSettings(webAppSettings));
                    app.WarmupCache(ApplicationDbContext.Create, warmupCacheSettings);
                    app.StartupComplete();
                }
            }
        }