1 19 20 package com.sslexplorer.keystore.forms; 21 22 import java.util.Enumeration ; 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpSession ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.Globals; 31 import org.apache.struts.action.ActionErrors; 32 import org.apache.struts.action.ActionMapping; 33 import org.apache.struts.action.ActionMessage; 34 35 import com.sslexplorer.boot.KeyStoreManager; 36 import com.sslexplorer.keystore.CertificateItem; 37 import com.sslexplorer.setup.CertificatesTableItemModel; 38 import com.sslexplorer.table.forms.AbstractPagerForm; 39 40 46 public class ShowKeyStoreForm extends AbstractPagerForm { 47 48 private static final long serialVersionUID = 2153872643060037840L; 49 50 static Log log = LogFactory.getLog(ShowKeyStoreForm.class); 51 52 private String password; 54 private String confirmPassword; 55 private String selectedKeyStoreName; 56 57 60 public ShowKeyStoreForm() { 61 super(new CertificatesTableItemModel()); 62 selectedKeyStoreName = KeyStoreManager.DEFAULT_KEY_STORE; 63 } 64 65 70 public String getPassword() { 71 return password; 72 } 73 74 79 public void setPassword(String password) { 80 this.password = password.trim(); 81 } 82 83 86 public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { 87 super.reset(mapping, request); 88 this.password = null; 89 this.confirmPassword = null; 90 } 91 92 95 public void setSelectedKeyStoreName(String selectedKeyStoreName) { 96 this.selectedKeyStoreName = selectedKeyStoreName; 97 } 98 99 102 public String getSelectedKeyStoreName() { 103 return selectedKeyStoreName; 104 } 105 106 109 public KeyStoreManager getSelectedKeyStore() { 110 return KeyStoreManager.getInstance(getSelectedKeyStoreName()); 111 } 112 113 116 public List getKeyStores() { 117 return KeyStoreManager.getKeyStores(); 118 } 119 120 123 public void initialize(HttpSession session) { 124 super.initialize(session, "alias"); 125 CertificateItem[] c = getCertificateItems(); 126 if(c != null) { 127 for(int i = 0 ; i < c.length; i++) { 128 getModel().addItem(c[i]); 129 } 130 } 131 getPager().rebuild(getFilterText()); 132 } 133 134 140 public CertificateItem[] getCertificateItems() { 141 KeyStoreManager sel = getSelectedKeyStore(); 142 if (!sel.isKeyStoreEmpty()){ 143 Enumeration e = sel.getCertificateAliases(); 144 if(e != null) { 145 CertificateItem[] cert = new CertificateItem[sel.getSize()]; 146 int i = 0; 147 while(e.hasMoreElements()) { 148 String alias = (String ) e.nextElement(); 149 cert[i++] = new CertificateItem(alias, sel.getCertificate(alias), sel); 150 } 151 return cert; 152 } 153 } 154 return null; 155 } 156 157 160 public String getConfirmPassword() { 161 return confirmPassword; 162 } 163 164 167 public void setConfirmPassword(String confirmPassword) { 168 this.confirmPassword = confirmPassword; 169 } 170 171 @Override 172 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 173 if ("exportPrivate".equals(request.getParameter("actionTarget"))) { 174 ActionErrors errors = new ActionErrors(); 175 try { 176 if (getPassword().length() == 0) { 177 errors.add(Globals.ERROR_KEY, new ActionMessage("setPassword.error.noNewPassword")); 178 } else if (!getPassword().equals(getConfirmPassword())) { 179 errors.add(Globals.ERROR_KEY, new ActionMessage("setPassword.error.newAndConfirmPasswordsDontMatch")); 180 } 181 } catch (Exception e) { 182 errors.add(Globals.ERROR_KEY, new ActionMessage("setPassword.error.validateFailed", e.getMessage())); 183 } 184 return errors; 185 } 186 return null; 187 } 188 189 } | Popular Tags |