1 18 package org.apache.geronimo.console.ca; 19 20 import java.io.IOException ; 21 import java.security.PublicKey ; 22 import java.security.cert.Certificate ; 23 import java.security.interfaces.RSAPublicKey ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 27 import javax.portlet.ActionRequest; 28 import javax.portlet.ActionResponse; 29 import javax.portlet.PortletException; 30 import javax.portlet.RenderRequest; 31 import javax.portlet.RenderResponse; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 import org.apache.geronimo.console.MultiPageModel; 36 import org.apache.geronimo.management.geronimo.CertificationAuthority; 37 import org.apache.geronimo.util.CaUtils; 38 import org.apache.geronimo.util.CertificateUtil; 39 40 45 public class CADetailsHandler extends BaseCAHandler { 46 private final static Log log = LogFactory.getLog(CADetailsHandler.class); 47 public CADetailsHandler() { 48 super(CADETAILS_MODE, "/WEB-INF/view/ca/caDetails.jsp"); 49 } 50 51 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 52 String [] params = {ERROR_MSG, INFO_MSG}; 53 for(int i = 0; i < params.length; ++i) { 54 String value = request.getParameter(params[i]); 55 if(value != null) response.setRenderParameter(params[i], value); 56 } 57 return getMode(); 58 } 59 60 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException { 61 String [] params = {ERROR_MSG, INFO_MSG}; 62 for(int i = 0; i < params.length; ++i) { 63 String value = request.getParameter(params[i]); 64 if(value != null) request.setAttribute(params[i], value); 65 } 66 try { 67 CertificationAuthority ca = getCertificationAuthority(request); 68 if(ca == null) { 69 throw new Exception ("CA is not running. CA may not have been initialized."); 70 } 71 if(ca.isLocked()) { 72 request.setAttribute("caLocked", Boolean.TRUE); 73 throw new Exception ("CA is locked. Unlock CA to view details."); 74 } 75 76 Certificate caCert = ca.getCertificate(); 78 request.setAttribute("cert", caCert); 79 request.setAttribute("highestSerial", ca.getHighestSerialNumber()); 80 request.setAttribute("certText", CaUtils.base64Certificate(caCert)); 81 PublicKey publickey = caCert.getPublicKey(); 82 String keySize = null; 83 if(publickey instanceof RSAPublicKey ) { 84 keySize = ""+((RSAPublicKey )publickey).getModulus().bitLength(); 85 request.setAttribute("keySize", keySize); 86 } 87 Map fingerPrints = new HashMap (); 88 fingerPrints.put("MD5", CertificateUtil.generateFingerprint(caCert, "MD5")); 89 fingerPrints.put("SHA1", CertificateUtil.generateFingerprint(caCert, "SHA1")); 90 request.setAttribute("fingerPrints", fingerPrints); 91 } catch (Exception e) { 92 request.setAttribute(ERROR_MSG, e.toString()); 93 log.error("Errors while trying to view CA Details.", e); 94 } 95 } 96 97 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 98 return getMode()+BEFORE_ACTION; 99 } 100 } 101 | Popular Tags |