1 19 20 package com.sslexplorer.security.forms; 21 22 import javax.servlet.http.HttpServletRequest ; 23 24 import org.apache.struts.Globals; 25 import org.apache.struts.action.ActionErrors; 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.struts.action.ActionMessage; 28 29 import com.sslexplorer.core.FieldValidationException; 30 import com.sslexplorer.core.forms.CoreForm; 31 32 33 43 public class PromptForPrivateKeyPassphraseForm extends CoreForm { 44 45 private String passphrase; 47 private String confirmPassphrase; 48 private boolean newKey; 49 50 56 public void setNewKey(boolean newKey) { 57 this.newKey = newKey; 58 } 59 60 66 public boolean getNewKey() { 67 return newKey; 68 } 69 70 75 public String getPassphrase() { 76 return passphrase; 77 } 78 79 84 public void setPassphrase(String passphrase) { 85 this.passphrase = passphrase.trim(); 86 } 87 88 93 public String getConfirmPassphrase() { 94 return confirmPassphrase; 95 } 96 97 102 public void setConfirmPassphrase(String confirmPassphrase) { 103 this.confirmPassphrase = confirmPassphrase.trim(); 104 } 105 106 109 public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { 110 super.reset(mapping, request); 111 passphrase = null; 112 } 113 114 120 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 121 if(isCommiting()) { 122 ActionErrors errors = new ActionErrors(); 123 try { 124 if (getPassphrase().length() == 0) { 125 throw new FieldValidationException("noPassphrase"); 126 } 127 if(getNewKey()) { 128 if(!getPassphrase().equals(getConfirmPassphrase())) { 129 throw new FieldValidationException("passphraseAndConfirmPassphraseDontMatch"); 130 } 131 } 132 } catch (FieldValidationException fve) { 133 errors.add(Globals.ERROR_KEY, new ActionMessage("promptForPrivateKeyPassphrase.error." + fve.getResourceKey())); 134 } catch (Exception e) { 135 errors.add(Globals.ERROR_KEY, new ActionMessage("promptForPrivateKeyPassphrase.error.validateFailed", e.getMessage())); 136 } 137 return errors; 138 } 139 else { 140 return null; 141 } 142 } 143 } | Popular Tags |