public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { // Validate Server is specified if (string.IsNullOrWhiteSpace(Server)) yield return new ValidationResult(Resources.ReportServerModelServerRequiredErrorMessage); // Validate WebServiceVirtualDirectory is specified if (string.IsNullOrWhiteSpace(WebServiceVirtualDirectory)) yield return new ValidationResult(Resources.ReportServerModelWebServiceVirtualDirectoryRequiredErrorMessage); // Validate UserName is specified if (string.IsNullOrWhiteSpace(UserName)) yield return new ValidationResult(Resources.ReportServerModelUserNameRequiredErrorMessage); // Validate Password is specified if (string.IsNullOrEmpty(Password)) yield return new ValidationResult(Resources.ReportServerModelPasswordRequiredErrorMessage); if (!string.IsNullOrWhiteSpace(WebServiceVirtualDirectory)) { var reportServerConfiguration = new ReportServerConfiguration(UseSsl, Server, WebServiceVirtualDirectory, Domain, UserName, Password, Password); // Validate the Server (based on ServiceUrl) if (!reportServerConfiguration.ServiceUrl.IsValidHttpAbsoluteUrl()) { yield return new ValidationResult(Resources.ReportServerModelInvalidServer); } } }
public IReportingClient CreateClient(ReportServerConfiguration reportServerConfiguration) { var binding = new BasicHttpBinding("ReportingServicesSoap"); var ntlmBinding = new BasicHttpBinding("ReportingServicesSoapNtlm"); if(reportServerConfiguration.ServiceUrl.StartsWith("https",StringComparison.InvariantCultureIgnoreCase)) { binding.Security.Mode = BasicHttpSecurityMode.Transport; ntlmBinding.Security.Mode = BasicHttpSecurityMode.Transport; } var client = new ReportingClient(reportServerConfiguration, binding); try { client.TestConnection(); } catch (ReportingAuthenticationException ex) { Log.Information("CreateClient ReportingAuthenticationException, Attempting ReportingServicesSoapNtlm Binding.\n{0}", ex.Message); client.Dispose(); client = new ReportingClient(reportServerConfiguration, ntlmBinding); } return client; }
public IKernel CreateKernel(Uri serviceUrl, string realTimeServiceAddress) { StandardKernel kernel = null; try { kernel = new StandardKernel(); kernel.Bind(x => x.FromAssembliesMatching("BuildingSecurity.*", "JohnsonControls.*") .SelectAllClasses() .Excluding<ReportingClient>() .Excluding<AlarmService>() .Excluding<MessageProcessingClient>() .Excluding<BuildingSecuritySessionStore>() .Excluding<BuildingSecurityClient>() .BindDefaultInterface() .Configure((b, c) => b.WithConstructorArgument("serviceUrl", serviceUrl)) ); #if IN_MEMORY_SETTINGS ReportServerConfiguration reportServer = new ReportServerConfiguration("http://10.10.93.183/ReportServer", "", "cwelchmi", "").CloneWithNewPassword("cwelchmi"); var appSettings = new SettingsDictionary { { ApplicationSettings.ReportServerConfiguration, new DataSerializer<ReportServerConfiguration>().Serialize( reportServer) } }; kernel.Bind<ITypedApplicationPreference>().ToMethod(x => new InMemoryApplicationSettings(appSettings, new Dictionary<string, SettingsDictionary>())).InSingletonScope(); #else kernel.Bind<ITypedApplicationPreference>().ToMethod(x => new CachingApplicationPreferences(new ApplicationPreferenceService(serviceUrl), new Cache(MemoryCache.Default, "ITypedApplicationPreference"))); #endif kernel.Bind<IBuildingSecuritySessionStore>().To<BuildingSecuritySessionStore>().InSingletonScope(); kernel.Rebind<IBuildingSecurityClient>().To<BuildingSecurityClient>().InSingletonScope(); kernel.Rebind<ISimulatorClient>().ToConstant<ISimulatorClient>(null); if (@"true".Equals(ConfigurationManager.AppSettings["UseSimulation"], StringComparison.InvariantCultureIgnoreCase)) { kernel.Rebind<IBuildingSecurityClient>().To<PseudoBuildingSecurityClient>().InSingletonScope(); kernel.Rebind<Scheduler>().To<Scheduler>().InSingletonScope(); kernel.Rebind<ISimulatorClient>().To<InMemorySimulationClient>().InSingletonScope(); } kernel.Bind<ITypedSessionManagement>().ToMethod(x => new SessionManagementService(serviceUrl)); kernel.Bind<ITypedAlarmService>().ToMethod(x => new AlarmService(serviceUrl, realTimeServiceAddress)).InSingletonScope(); kernel.Bind<ITypedSystemInformationService>().ToMethod(x => new SystemInformationService(serviceUrl)).InSingletonScope(); return kernel; } catch { if (kernel != null) { kernel.Dispose(); } throw; } }
public ActionResult Index(IUser user, ReportServerConfigurationModel model, string submitButton) { if (user == null) throw new ArgumentNullException("user"); // Retrieve the current EncryptedPassword string currentEncryptedPassword = ""; ReportServerConfiguration currentReportServerConfiguration; if (_buildingSecurityClient.TryReadApplicationPreference(user.BuildingSecurityCookie, ApplicationSettings.ReportServerConfiguration, out currentReportServerConfiguration)) { currentEncryptedPassword = currentReportServerConfiguration.EncryptedPassword; } if (model != null) { if(ModelState.IsValid) { // Construct the ReportServerConfiguration from the ReportServerModel properties var reportServerConfiguration = new ReportServerConfiguration(model.UseSsl, model.Server, model.WebServiceVirtualDirectory, model.Domain, model.UserName, model.Password, currentEncryptedPassword); // Test the connection bool connectionSucceded = TestConfiguration(reportServerConfiguration, model); // If the connection succeeded and submitButton = "Save", then SaveApplicationPreference and update the message if ((connectionSucceded) && (submitButton != null) && (submitButton.ToUpperInvariant() == "SAVE")) { //TODO:Refactor to notify the ReportServerConfigurationFactory of the change, and to pull setting name from a constant _buildingSecurityClient.SaveApplicationPreference(user.BuildingSecurityCookie, ApplicationSettings.ReportServerConfiguration, reportServerConfiguration); SetMessage(model, MessageType.Success, Resources.ReportServerOptionsSaveCompletedMessage); } } else { SetMessage(model, MessageType.Error, GetModelStateErrorMessages()); } } UserExtensions.PopulateViewBag(user, ViewBag); return View("Index", model); }
private bool TestConfiguration(ReportServerConfiguration reportServerConfiguration, ReportServerConfigurationModel model) { try { using (var reportingClient = _reportingClientFactory.CreateClient(reportServerConfiguration)) { reportingClient.TestConnection(); } // If CreateClient and TestConnection did not throw an exception, // then set the message in the model to succeeded, and return true SetMessage(model, MessageType.Success, Resources.ReportServerOptionsConnectionSucceeded); return true; } catch (ReportingEndpointException) { // Invalid Report Server Uri Format or Endpoint SetMessage(model, MessageType.Error, Resources.ReportingEndpointException); } catch (ReportingAuthenticationException) { // Invalid Credentials SetMessage(model, MessageType.Error, Resources.ReportingAuthenticationException); } catch (ReportingSchemeException) { // Invalid Scheme (http vs. https) SetMessage(model, MessageType.Error, Resources.ReportingSchemeException); } catch (UntrustedCertificateException) { SetMessage(model, MessageType.Error, Resources.ReportServerUntrustedCertificateMessage); } catch (Exception) { SetMessage(model, MessageType.Error, Resources.ReportServerOptionsConnectionFailedMessage); } return false; }
private static bool TryParseConfiguration(ReportServerConfiguration reportServerConfiguration, out bool useSsl, out string server, out string webServiceVirtualDirectory) { try { var serviceUri = new Uri(reportServerConfiguration.ServiceUrl); useSsl = serviceUri.GetLeftPart(UriPartial.Scheme).StartsWith("https", StringComparison.OrdinalIgnoreCase); string scheme = useSsl ? "https://" : "http://"; server = serviceUri.GetLeftPart(UriPartial.Authority).Replace(scheme, ""); webServiceVirtualDirectory = serviceUri.ToString().Replace(scheme + server + "/", ""); return true; } catch (Exception) { // If an exception was thrown, set set the output values to the default configuration useSsl = false; server = "localhost"; webServiceVirtualDirectory = "ReportServer"; return false; } }