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.security.PublicKey;
021: import java.security.cert.Certificate;
022: import java.security.interfaces.RSAPublicKey;
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: import javax.portlet.ActionRequest;
027: import javax.portlet.ActionResponse;
028: import javax.portlet.PortletException;
029: import javax.portlet.RenderRequest;
030: import javax.portlet.RenderResponse;
031:
032: import org.apache.commons.logging.Log;
033: import org.apache.commons.logging.LogFactory;
034: import org.apache.geronimo.console.MultiPageModel;
035: import org.apache.geronimo.management.geronimo.CertificationAuthority;
036: import org.apache.geronimo.crypto.CaUtils;
037: import org.apache.geronimo.crypto.CertificateUtil;
038:
039: /**
040: * Handler for the CA details screen.
041: *
042: * @version $Rev: 617588 $ $Date: 2008-02-01 10:20:07 -0800 (Fri, 01 Feb 2008) $
043: */
044: public class CADetailsHandler extends BaseCAHandler {
045: private final static Log log = LogFactory
046: .getLog(CADetailsHandler.class);
047:
048: public CADetailsHandler() {
049: super (CADETAILS_MODE, "/WEB-INF/view/ca/caDetails.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 };
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: try {
074: CertificationAuthority ca = getCertificationAuthority(request);
075: if (ca == null) {
076: throw new Exception(
077: "CA is not running. CA may not have been initialized.");
078: }
079: if (ca.isLocked()) {
080: request.setAttribute("caLocked", Boolean.TRUE);
081: throw new Exception(
082: "CA is locked. Unlock CA to view details.");
083: }
084:
085: // Get CA details
086: Certificate caCert = ca.getCertificate();
087: request.setAttribute("cert", caCert);
088: request.setAttribute("highestSerial", ca
089: .getHighestSerialNumber());
090: request.setAttribute("certText", CaUtils
091: .base64Certificate(caCert));
092: PublicKey publickey = caCert.getPublicKey();
093: String keySize = null;
094: if (publickey instanceof RSAPublicKey) {
095: keySize = ""
096: + ((RSAPublicKey) publickey).getModulus()
097: .bitLength();
098: request.setAttribute("keySize", keySize);
099: }
100: Map fingerPrints = new HashMap();
101: fingerPrints.put("MD5", CertificateUtil
102: .generateFingerprint(caCert, "MD5"));
103: fingerPrints.put("SHA1", CertificateUtil
104: .generateFingerprint(caCert, "SHA1"));
105: request.setAttribute("fingerPrints", fingerPrints);
106: } catch (Exception e) {
107: request.setAttribute(ERROR_MSG, e.toString());
108: log.error("Errors while trying to view CA Details.", e);
109: }
110: }
111:
112: public String actionAfterView(ActionRequest request,
113: ActionResponse response, MultiPageModel model)
114: throws PortletException, IOException {
115: return getMode() + BEFORE_ACTION;
116: }
117: }
|