public ActionResult Add(ClientCertificate newCertificate, ClientCertificateInputModel file) { if (String.IsNullOrEmpty(newCertificate.Thumbprint) && file != null && file.Cert != null) { newCertificate.Thumbprint = file.Cert.Thumbprint; if (newCertificate.Thumbprint != null) { ModelState["newCertificate.Thumbprint"].Errors.Clear(); ModelState["newCertificate.Thumbprint"].Value = new ValueProviderResult(newCertificate.Thumbprint, newCertificate.Thumbprint, ModelState["newCertificate.Thumbprint"].Value.Culture); } } if (ModelState.IsValid) { try { this.clientCertificatesRepository.Add(newCertificate); TempData["Message"] = "Certificate Added"; return RedirectToAction("Configure", new { id = newCertificate.UserName }); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); } catch { ModelState.AddModelError("", "Error adding client certificate."); } } var vm = new ClientCertificatesForUserViewModel(this.clientCertificatesRepository, this.userManagementRepository, newCertificate.UserName); vm.NewCertificate = newCertificate; return View("Configure", vm); }
public ClientCertificatesForUserViewModel(IClientCertificatesRepository clientCertificatesRepository, IUserManagementRepository userManagementRepository, string username) { this.clientCertificatesRepository = clientCertificatesRepository; this.userManagementRepository = userManagementRepository; var allnames = userManagementRepository.GetUsers() .Select(x => new SelectListItem { Text = x }).ToList(); allnames.Insert(0, new SelectListItem { Text = "-Choose-", Value = "" }); this.AllUserNames = allnames; this.UserName = username; NewCertificate = new ClientCertificate { UserName = username }; if (!IsNew) { var certs = this.clientCertificatesRepository .GetClientCertificatesForUser(this.UserName) .ToArray(); this.Certificates = certs; } else { this.Certificates = new ClientCertificate[0]; } }
public void Add(ClientCertificate certificate) { using (var entities = IdentityServerConfigurationContext.Get()) { var entity = new ClientCertificates { UserName = certificate.UserName, Thumbprint = certificate.Thumbprint, Description = certificate.Description }; entities.ClientCertificates.Add(entity); entities.SaveChanges(); } }
public ActionResult Add(AddClientCertificateModel model) { if (!ModelState.IsValid) { return View(); } var clientCert = new ClientCertificate { UserName = model.UserName, Description = model.Description }; if (model.CertificateUpload != null && model.CertificateUpload.ContentLength > 0) { var bytes = new byte[model.CertificateUpload.InputStream.Length]; model.CertificateUpload.InputStream.Read(bytes, 0, bytes.Length); clientCert.Thumbprint = new X509Certificate2(bytes).Thumbprint; } else { if (string.IsNullOrWhiteSpace(model.Thumbprint)) { ModelState.AddModelError("", "No certificate (or thumbprint) specified"); return View(); } clientCert.Thumbprint = model.Thumbprint; } try { Repository.Add(clientCert); } catch (Exception ex) { ModelState.AddModelError("", ex.InnerException.Message); return View("Add"); } return RedirectToAction("Index"); }
public void Add(ClientCertificate certificate) { using (var entities = DatabaseContext.Get()) { var record = (from entry in entities.ClientCertificates where entry.UserName.Equals(certificate.UserName, StringComparison.OrdinalIgnoreCase) && entry.Thumbprint.Equals(certificate.Thumbprint, StringComparison.OrdinalIgnoreCase) select entry) .SingleOrDefault(); if (record == null) { record = new ClientCertificates { UserName = certificate.UserName, Thumbprint = certificate.Thumbprint, }; entities.ClientCertificates.Add(record); } record.Description = certificate.Description; entities.SaveChanges(); } }
public void Delete(ClientCertificate certificate) { using (var entities = IdentityServerConfigurationContext.Get()) { var record = (from entry in entities.ClientCertificates where entry.UserName.Equals(certificate.UserName, StringComparison.OrdinalIgnoreCase) && entry.Thumbprint.Equals(certificate.Thumbprint, StringComparison.OrdinalIgnoreCase) select entry) .Single(); entities.ClientCertificates.Remove(record); entities.SaveChanges(); } }
public ActionResult Remove(ClientCertificate model) { if (ModelState.IsValid) { try { this.clientCertificatesRepository.Delete(model); TempData["Message"] = "Certificate Removed"; return RedirectToAction("Configure", new { id = model.UserName }); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); } catch { ModelState.AddModelError("", "Error removing client certificate."); } } var vm = new ClientCertificatesForUserViewModel(this.clientCertificatesRepository, this.userManagementRepository, model.UserName); return View("Configure", vm); }
public static ClientCertificate ToDomainModel(this ClientCertificateEntity entity) { var cc = new ClientCertificate { UserName = entity.UserName, Thumbprint = entity.RowKey, Description = entity.Description }; return cc; }
public void Delete(ClientCertificate certificate) { using (var entities = DatabaseContext.Get()) { var record = (from entry in entities.ClientCertificates where entry.UserName.Equals(certificate.UserName, StringComparison.OrdinalIgnoreCase) && entry.Thumbprint.Equals(certificate.Thumbprint, StringComparison.OrdinalIgnoreCase) select entry) .SingleOrDefault(); if (record != null) { entities.ClientCertificates.Remove(record); entities.SaveChanges(); } } }
public void Delete(ClientCertificate certificate) { NewContext.DeleteClientCertificate(certificate.ToEntity()); }
public void Add(ClientCertificate certificate) { NewContext.AddClientCertificate(certificate.ToEntity()); }
public void Delete(ClientCertificate certificate) { _apiClient.Delete<ClientCertificate>("api/clientcertificates", certificate); }
public void Add(ClientCertificate certificate) { _apiClient.Post<ClientCertificate>("api/clientcertificates", certificate); }