1 18 package org.apache.geronimo.console.ca; 19 20 import java.io.IOException ; 21 import java.math.BigInteger ; 22 import java.security.PublicKey ; 23 import java.security.cert.Certificate ; 24 import java.security.interfaces.RSAPublicKey ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 import javax.portlet.ActionRequest; 29 import javax.portlet.ActionResponse; 30 import javax.portlet.PortletException; 31 import javax.portlet.RenderRequest; 32 import javax.portlet.RenderResponse; 33 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 import org.apache.geronimo.console.MultiPageModel; 37 import org.apache.geronimo.management.geronimo.CertificationAuthority; 38 import org.apache.geronimo.util.CertificateUtil; 39 40 45 public class ViewCertificateHandler extends BaseCAHandler { 46 private final static Log log = LogFactory.getLog(ViewCertificateHandler.class); 47 public ViewCertificateHandler() { 48 super(VIEW_CERT_MODE, "/WEB-INF/view/ca/viewCertificate.jsp"); 49 } 50 51 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 52 String [] params = {ERROR_MSG, INFO_MSG, "sNo"}; 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 String errorMsg = request.getParameter(ERROR_MSG); 67 String sNo = request.getParameter("sNo"); 68 try { 69 if(!request.getParameterMap().containsKey("sNo")) { 70 request.setAttribute("sNo", null); 72 return; 73 } 74 CertificationAuthority ca = getCertificationAuthority(request); 75 76 String certText = ca.getCertificateBase64Text(new BigInteger (sNo.trim())); 77 Certificate cert = ca.getCertificate(new BigInteger (sNo.trim())); 78 PublicKey publickey = cert.getPublicKey(); 79 String keySize = null; 80 if(publickey instanceof RSAPublicKey ) { 81 keySize = ""+((RSAPublicKey )publickey).getModulus().bitLength(); 82 } 83 request.setAttribute("sNo", sNo); 84 request.setAttribute("cert", cert); 85 request.setAttribute("certText", certText); 86 request.setAttribute("keySize", keySize); 87 Map fingerPrints = new HashMap (); 89 fingerPrints.put("MD5", CertificateUtil.generateFingerprint(cert, "MD5")); 90 fingerPrints.put("SHA1", CertificateUtil.generateFingerprint(cert, "SHA1")); 91 request.setAttribute("fingerPrints", fingerPrints); 92 if("true".equalsIgnoreCase(request.getParameter("linkToListRequests"))) 95 request.setAttribute("linkToListRequests", Boolean.TRUE); 96 } catch (Exception e) { 97 errorMsg = e.toString(); 98 log.error("Errors trying to view certificate with serial number '"+sNo+"'", e); 99 } 100 request.setAttribute(ERROR_MSG, errorMsg); 101 } 102 103 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 104 return getMode()+BEFORE_ACTION; 105 } 106 } 107 | Popular Tags |