@RequestMapping(value = "/update/{oid}", method = RequestMethod.POST)
  public String update(
      @PathVariable("oid") DomainKeyStore domainKeyStore,
      @RequestParam(value = "name", required = false) java.lang.String name,
      @RequestParam(value = "oldPassword", required = false) java.lang.String oldPassword,
      @RequestParam(value = "password", required = false) java.lang.String password,
      @RequestParam(value = "passwordVerification", required = false)
          java.lang.String passwordVerification,
      Model model) {

    setDomainKeyStore(domainKeyStore, model);

    if (domainKeyStore.isAbleToOpenKeyStore()
        && oldPassword != null
        && !domainKeyStore.getPassword().equals(oldPassword)) {
      addErrorMessage("Password incorrect", model);
      return "webservices/management/keystores/domainkeystore/update";
    }
    if (password != null && !password.equals(passwordVerification)) {
      addErrorMessage("Password and password verification did not match", model);
      if (!domainKeyStore.isAbleToOpenKeyStore()) {
        addWarningMessage(
            "Unable to open keystore. The most common problem is that the password is incorrect, hence when doing password update we'll only change in the system and not in the keystore itself. You can use this to fix the password problem.",
            model);
        model.addAttribute("noOldPasswordRequest", true);
      }
      return "webservices/management/keystores/domainkeystore/update";
    }

    updateDomainKeyStore(name, oldPassword, password, model);
    return "redirect:/webservices/management/keystores/domainkeystore/read/"
        + getDomainKeyStore(model).getExternalId();
  }
 @Atomic
 public void updateDomainKeyStore(
     java.lang.String name, java.lang.String oldPassword, java.lang.String password, Model m) {
   DomainKeyStore domainKeyStore = getDomainKeyStore(m);
   domainKeyStore.setName(name);
   if (password != null && oldPassword != null && !oldPassword.equals(password)) {
     domainKeyStore.changePassword(oldPassword, password);
   }
 }
 @RequestMapping(value = "/read/{oid}/downloadkeystore")
 public void processReadToDownloadKeystore(
     @PathVariable("oid") DomainKeyStore domainKeyStore, HttpServletResponse response) {
   InputStream is = domainKeyStore.getKeyStoreFile().getStream();
   response.setContentType("application/octet-stream");
   response.setHeader(
       "Content-disposition", "attachment; filename=" + domainKeyStore.getName() + ".jks");
   try {
     StreamUtils.copy(is, response.getOutputStream());
     response.flushBuffer();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 @RequestMapping(value = "/read/{oid}/uploadkeystore")
 public String processReadToUploadKeystore(
     @PathVariable("oid") DomainKeyStore domainKeyStore, Model model) {
   setDomainKeyStore(domainKeyStore, model);
   return "redirect:/webservices/management/keystores/uploadkeystore/"
       + domainKeyStore.getExternalId();
 }
  @RequestMapping(value = "/search/view/{oid}")
  public String processSearchToViewAction(
      @PathVariable("oid") DomainKeyStore domainKeyStore, Model model) {

    return "redirect:/webservices/management/keystores/domainkeystore/read"
        + "/"
        + domainKeyStore.getExternalId();
  }
  @RequestMapping(value = "/deleteEntry/{oid}")
  public String deleteEntry(
      @PathVariable("oid") DomainKeyStore domainKeyStore,
      @RequestParam(value = "alias", required = false) String alias,
      Model model) {

    deleteEntry(domainKeyStore, alias);
    return "redirect:/webservices/management/keystores/domainkeystore/read/"
        + domainKeyStore.getExternalId();
  }
  @RequestMapping(value = "/read/{oid}")
  public String read(@PathVariable("oid") DomainKeyStore domainKeyStore, Model model) {

    if (!domainKeyStore.isAbleToOpenKeyStore()) {
      addWarningMessage(
          "Unable to open keystore. The most common problem is that the password is incorrect",
          model);
    }
    setDomainKeyStore(domainKeyStore, model);
    return "webservices/management/keystores/domainkeystore/read";
  }
  @RequestMapping(value = "/update/{oid}", method = RequestMethod.GET)
  public String update(@PathVariable("oid") DomainKeyStore domainKeyStore, Model model) {
    setDomainKeyStore(domainKeyStore, model);
    if (!domainKeyStore.isAbleToOpenKeyStore()) {
      addWarningMessage(
          "Unable to open keystore. The most common problem is that the password is incorrect, hence when doing password update we'll only change in the system and not in the keystore itself. You can use this to fix the password problem.",
          model);
      model.addAttribute("noOldPasswordRequest", true);
    }

    return "webservices/management/keystores/domainkeystore/update";
  }
 @Atomic
 public void deleteDomainKeyStores(List<DomainKeyStore> domainKeyStore) {
   for (DomainKeyStore keyStore : domainKeyStore) {
     keyStore.delete();
   }
 }
 @Atomic
 public void deleteDomainKeyStore(DomainKeyStore domainKeyStore) {
   domainKeyStore.delete();
 }
 @Atomic
 private void deleteEntry(DomainKeyStore domainKeyStore, String alias) {
   domainKeyStore.deleteEntry(alias);
 }