001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.geronimo.console.ca;
018:
019: import java.io.IOException;
020: import java.math.BigInteger;
021: import java.security.PublicKey;
022: import java.security.cert.Certificate;
023: import java.security.interfaces.RSAPublicKey;
024: import java.util.HashMap;
025: import java.util.Map;
026:
027: import javax.portlet.ActionRequest;
028: import javax.portlet.ActionResponse;
029: import javax.portlet.PortletException;
030: import javax.portlet.RenderRequest;
031: import javax.portlet.RenderResponse;
032:
033: import org.apache.commons.logging.Log;
034: import org.apache.commons.logging.LogFactory;
035: import org.apache.geronimo.console.MultiPageModel;
036: import org.apache.geronimo.management.geronimo.CertificationAuthority;
037: import org.apache.geronimo.crypto.CertificateUtil;
038:
039: /**
040: * Handler for view certificate screen.
041: *
042: * @version $Rev: 617588 $ $Date: 2008-02-01 10:20:07 -0800 (Fri, 01 Feb 2008) $
043: */
044: public class ViewCertificateHandler extends BaseCAHandler {
045: private final static Log log = LogFactory
046: .getLog(ViewCertificateHandler.class);
047:
048: public ViewCertificateHandler() {
049: super (VIEW_CERT_MODE, "/WEB-INF/view/ca/viewCertificate.jsp");
050: }
051:
052: public String actionBeforeView(ActionRequest request,
053: ActionResponse response, MultiPageModel model)
054: throws PortletException, IOException {
055: String[] params = { ERROR_MSG, INFO_MSG, "sNo" };
056: for (int i = 0; i < params.length; ++i) {
057: String value = request.getParameter(params[i]);
058: if (value != null)
059: response.setRenderParameter(params[i], value);
060: }
061: return getMode();
062: }
063:
064: public void renderView(RenderRequest request,
065: RenderResponse response, MultiPageModel model)
066: throws PortletException, IOException {
067: String[] params = { ERROR_MSG, INFO_MSG };
068: for (int i = 0; i < params.length; ++i) {
069: String value = request.getParameter(params[i]);
070: if (value != null)
071: request.setAttribute(params[i], value);
072: }
073: String errorMsg = request.getParameter(ERROR_MSG);
074: String sNo = request.getParameter("sNo");
075: try {
076: if (!request.getParameterMap().containsKey("sNo")) {
077: // Show the page to get serial number of the certificate to be viewed
078: request.setAttribute("sNo", null);
079: return;
080: }
081: CertificationAuthority ca = getCertificationAuthority(request);
082:
083: String certText = ca
084: .getCertificateBase64Text(new BigInteger(sNo.trim()));
085: Certificate cert = ca.getCertificate(new BigInteger(sNo
086: .trim()));
087: PublicKey publickey = cert.getPublicKey();
088: String keySize = null;
089: if (publickey instanceof RSAPublicKey) {
090: keySize = ""
091: + ((RSAPublicKey) publickey).getModulus()
092: .bitLength();
093: }
094: request.setAttribute("sNo", sNo);
095: request.setAttribute("cert", cert);
096: request.setAttribute("certText", certText);
097: request.setAttribute("keySize", keySize);
098: // Generate Certificate Fingerprints
099: Map fingerPrints = new HashMap();
100: fingerPrints.put("MD5", CertificateUtil
101: .generateFingerprint(cert, "MD5"));
102: fingerPrints.put("SHA1", CertificateUtil
103: .generateFingerprint(cert, "SHA1"));
104: request.setAttribute("fingerPrints", fingerPrints);
105: // Check if the certificate issue process started from "requests to be fulfilled" page.
106: // If so, provide a link to go back to that page
107: if ("true".equalsIgnoreCase(request
108: .getParameter("linkToListRequests")))
109: request
110: .setAttribute("linkToListRequests",
111: Boolean.TRUE);
112: } catch (Exception e) {
113: errorMsg = e.toString();
114: log.error(
115: "Errors trying to view certificate with serial number '"
116: + sNo + "'", e);
117: }
118: request.setAttribute(ERROR_MSG, errorMsg);
119: }
120:
121: public String actionAfterView(ActionRequest request,
122: ActionResponse response, MultiPageModel model)
123: throws PortletException, IOException {
124: return getMode() + BEFORE_ACTION;
125: }
126: }
|