public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();
			SolutionUserDto = SolutionUserDtoOriginal.DeepCopy();
			TxtName.StringValue = SolutionUserDto.Name;
			TxtDescription.StringValue = string.IsNullOrEmpty(SolutionUserDto.Description)?string.Empty:SolutionUserDto.Description;
			CbDisabled.StringValue = SolutionUserDto.Disabled ? "1" : "0";
			Window.Title = SolutionUserDto.Name + " Properties";
			var cert = new X509Certificate2 (Encoding.ASCII.GetBytes(SolutionUserDto.Certificate.Encoded));
			try {
				TxtIssuer.StringValue =  cert.Issuer;
				TxtValidFrom.StringValue = cert.NotBefore.ToShortDateString();
				TxtValidTo.StringValue = cert.NotAfter.ToShortDateString();
				TxtDC.StringValue = cert.IssuerName.Format(true);
			} catch (Exception) {
				UtilityService.ShowAlert ("Invalid X509 certificate", "Alert");
			}

			//Events
			this.BtnSave.Activated += OnClickSaveButton;
			this.BtnClose.Activated += (object sender, EventArgs e) => {
				this.Close ();
				NSApplication.SharedApplication.StopModalWithCode (0);
			};

			this.BtnChangeCertificate.Activated += (object sender, EventArgs e) => {
				var openPanel = new NSOpenPanel();
				openPanel.ReleasedWhenClosed = true;
				openPanel.Prompt = "Select file";

				var result = openPanel.RunModal();
				if (result == 1)
				{
					var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty);
					var cert1 = new X509Certificate2 ();
					try {

						cert1.Import (filePath);
						TxtIssuer.StringValue =  cert1.Issuer;
						TxtValidFrom.StringValue = cert1.NotBefore.ToShortDateString();
						TxtValidTo.StringValue = cert1.NotAfter.ToShortDateString();
						TxtDC.StringValue = cert1.IssuerName.Format(true);
					} catch (Exception) {
						UtilityService.ShowAlert ("Invalid X509 certificate", "Alert");
					}
					SolutionUserDto.Certificate.Encoded = cert.ToPem();
				}
			};
		}
 public bool Delete(ServerDto serverDto, string tenantName, SolutionUserDto user, Token token)
 {
     tenantName = Uri.EscapeDataString(tenantName);
     var name = Uri.EscapeDataString(user.Name);
     var url = string.Format(ServiceConfigManager.SolutionUserEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenantName, name);
     ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
     var requestConfig = new RequestSettings
     {
         Method = HttpMethod.Delete
     };
     var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType);
     var json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower();
     var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json);
     return string.IsNullOrEmpty(response);
 }
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();
			SolutionUserDto = SolutionUserDtoOriginal.DeepCopy();
			TxtName.StringValue = SolutionUserDto.Name;
			TxtDescription.StringValue = string.IsNullOrEmpty(SolutionUserDto.Description)?string.Empty:SolutionUserDto.Description;
			cbDisabled.StringValue = SolutionUserDto.Disabled ? "0" : "1";
			_certificate = new X509Certificate2 (Encoding.ASCII.GetBytes(SolutionUserDto.Certificate.Encoded));
			ActionHelper.Execute (delegate() {
				TxtIssuer.StringValue = _certificate.Issuer;
				TxtValidFrom.StringValue = _certificate.NotBefore.ToShortDateString ();
				TxtValidTo.StringValue = _certificate.NotAfter.ToShortDateString ();
				TxtDn.StringValue = _certificate.IssuerName.Format (true);
			});

			//Events
			this.BtnSave.Activated += OnClickSaveButton;

			this.BtnChangeCertificate.Activated += (object sender, EventArgs e) => {
				var openPanel = new NSOpenPanel();
				openPanel.ReleasedWhenClosed = true;
				openPanel.Prompt = "Select file";

				var result = openPanel.RunModal();
				if (result == 1)
				{
					var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty);
					var cert1 = new X509Certificate2 ();
					ActionHelper.Execute (delegate() {

						cert1.Import (filePath);
						TxtIssuer.StringValue =  cert1.Issuer;
						TxtValidFrom.StringValue = cert1.NotBefore.ToShortDateString();
						TxtValidTo.StringValue = cert1.NotAfter.ToShortDateString();
						TxtDn.StringValue = cert1.IssuerName.Format(true);
						_certificate = cert1;
					});
					SolutionUserDto.Certificate.Encoded = _certificate.ToPem();
				}
			};

			BtnViewCertificate.Activated += (object sender, EventArgs e) => 
			{
				CertificateService.DisplayX509Certificate2(this, _certificate );
			};

			BtnSave.Hidden = !IsSystemDomain;
		}
Пример #4
0
		public void DeleteUser (SolutionUserDto userDto)
		{
			ActionHelper.Execute (delegate() {
				userDto.Domain = _domainName;
				var serverDto = SnapInContext.Instance.AuthTokenManager.GetAuthToken (_serverDto.ServerName);
				var success = SnapInContext.Instance.ServiceGateway.SolutionUser.Delete (_serverDto, _tenantName, userDto, serverDto.Token);
				if (success) {
					UIErrorHelper.ShowAlert ("Solution User " + userDto.Name + " deleted successfully", "Information");
				} else {

					UIErrorHelper.ShowAlert ("Failed to delete Solution User " + userDto.Name, "Information");
				}
				Refresh (this, EventArgs.Empty);
			});
		}
Пример #5
0
		private SolutionUserDto AddUser (SolutionUserDto userDto)
		{
			userDto.Domain = _domainName;
			var serverDto = SnapInContext.Instance.AuthTokenManager.GetAuthToken(_serverDto.ServerName);
			return SnapInContext.Instance.ServiceGateway.SolutionUser.Create(_serverDto, _tenantName, userDto, serverDto.Token);
		}
		public void OnClickAddButton (object sender, EventArgs e)
		{
			if (string.IsNullOrEmpty (TxtUsername.StringValue)) {
				UIErrorHelper.ShowAlert ("Please enter valid username", "Alert");
			} else if (string.IsNullOrEmpty (TxtDescription.StringValue)) {
				UIErrorHelper.ShowAlert ("Please enter valid Description", "Alert");
			} else if (string.IsNullOrEmpty (TxtCertificatePath.StringValue)) {
				UIErrorHelper.ShowAlert ("Please enter valid Certificate", "Alert");
			} else {
				var cert = new X509Certificate2 ();
				ActionHelper.Execute (delegate() {
					cert.Import (TxtCertificatePath.StringValue.Replace ("file://", string.Empty));
				});

				SolutionUserDto = new SolutionUserDto () {
					Name = TxtUsername.StringValue,
					Description = TxtDescription.StringValue,
					Certificate = new CertificateDto { Encoded = cert.ToPem() }
				};
				this.Close ();
				NSApplication.SharedApplication.StopModalWithCode (1);
			}
		}