/// <summary> /// Called whenever the authentication has changed; act dependent on the authentication state. /// </summary> /// <param name="context">The authentication context holding information on credentials</param> /// <param name="isAuthenticated">A flag specifying whether the user is authenticated</param> protected override async void OnAuthenticationChanged(AuthenticationContext context, bool isAuthenticated) { int fadeInMs = 500; base.OnAuthenticationChanged(context, isAuthenticated); if (isAuthenticated) { // Set the new Search Postfix on the GeoLocator this.PlaceFinderViewModel.SearchPostfix = ClientSettingsViewModel.GeoLocatorSearchPostfix; // Set the maximum number of records for the result list this.FeatureCollectionResultViewModel.GridProperties.DefaultBatchSize = ClientSettingsViewModel.ResultListMaximumNumberOfRecords; // Set up the MapDefinitions, waiting (asynchronously) for completion await this.MapsViewModel.GetServiceProviderMapDefinitionsAsync(); // Wait a bit to have some map information drawn, showing some more interesting // Map when it comes available await TaskEx.Delay(fadeInMs); // With everything loaded and set up; start showing the application AuthenticationOpacity.FadeIn(fadeInMs); // We could do something with the number of sessions currently active on this server. // Note that not signing off will retain the session's token active on the server (for a // period equal to the lease time). int numberOfActiveSessions = await MainXYServiceProvider.GetActiveSessionsCountAsync(); } // Only allow (visibility of) trace logging in case of admin rights this.TraceLogger.AllowLogging = isAuthenticated && context.HasAdminRights; }
/// <summary> /// Called whenever the authentication is about to change. The order in which calls are made are: /// /// ViewModelLocator - OnAuthenticationChanging /// /// ViewModels - OnAuthenticationChanged /// ViewModelLocator - OnAuthenticationChanged /// /// This method gives the possibility to change global settings before individual viewModels are /// setting their state when the user has been authenticated. (ie add ServiceProviders depending /// on some server setting). /// </summary> protected override async Task OnAuthenticationChanging(AuthenticationContext context, bool isAuthenticated) { // Get some base behavior happening and wait for it to complete await base.OnAuthenticationChanging(context, isAuthenticated); // Clear all referenced service providers - include the local defined ones ServiceProviderManager.Instance.RemoveServiceProviders(includeLocalDefined: true, leaveMainProvider: true); // Drive the client settings actively, to make sure these are done before any // other viewModel kicks in await ClientSettingsViewModel.SetupFor(context, isAuthenticated); if (isAuthenticated) { // Make sure we set up the client side GeoLocator (if it is indicated via the client // settings that this user uses the client-side one). ApplyClientSettingsToViewModels(); // Tell the LiteAnalyticsTracker our prefered prefix for the Application. // Note: Do not make this language dependent, since different clients' identical categories wouldn't match anymore // // Do not use in case no category prefix is required in Analytics (ie when this is handled using account properties // in Google Analytics). // // AnalyticsAppName Category Event Label // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Set 'GSA Lite (Cambridge): Authentication' 'SignIn' 'test' // Not Set 'Authentication' 'SignIn' 'test' // // LiteAnalyticsTracker.AnalyticsAppName = string.Format("{0} ({1}): ", AnalyticsName, context.ServiceProviderInfo.Name ?? ""); // Track the fact that we are signing in LiteAnalyticsTracker.TrackSignIn(context.UserName); // Get reference providers var referenceProviders = await this.ServerInfoViewModel.GetReferenceServiceProvidersAsync(); foreach (var provider in referenceProviders) { ServiceProviderManager.Instance.ServiceProviders.Add(provider); } } else { // Let's handle the fading out as early as possible int fadeOutMs = 1000; // When signing in, there is an AuthenticationContext available. bool triedLoggingIn = context != null; // First of all - fade the application out AuthenticationOpacity.FadeOut(fadeOutMs); if (triedLoggingIn) { // Dependent on the state, track errors to the Analytics Module switch (context.Status) { case AuthenticationStatus.FailedConnectionError: var mainProvider = ServiceProviderManager.Instance.MainServiceProvider as XYServiceProvider; if (mainProvider != null) { // Notify the user/tracker that we have failed to connect var address = mainProvider.ServiceAddress ?? "?"; var message = String.Format("{0} {1}", FrameworkResources.AuthenticationFailedConnectionError, address); // Use the analytics tracker LiteAnalyticsTracker.TrackAuthServerError(message); } break; case AuthenticationStatus.FailedInvalidCredentials: // Track in analytics LiteAnalyticsTracker.TrackAuthCredentialsError(context.UserName); break; case AuthenticationStatus.FailedInvalidApplication: // Track in analytics LiteAnalyticsTracker.TrackAuthInvalidApplicationError(context.UserName); break; case AuthenticationStatus.FailedInvalidApplicationUser: // Track in analytics LiteAnalyticsTracker.TrackAuthInvalidApplicationUserError(context.UserName); break; } } else // so !triedLoggingIn - deliberately signing out { // Track the signing out LiteAnalyticsTracker.TrackSignOut(); } } }