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 */
018 package org.apache.geronimo.console.ca;
019
020 import java.io.IOException;
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.CaUtils;
038 import org.apache.geronimo.crypto.CertificateUtil;
039
040 /**
041 * Handler for the CA details screen.
042 *
043 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
044 */
045 public class CADetailsHandler extends BaseCAHandler {
046 private final static Log log = LogFactory.getLog(CADetailsHandler.class);
047 public CADetailsHandler() {
048 super(CADETAILS_MODE, "/WEB-INF/view/ca/caDetails.jsp");
049 }
050
051 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
052 String[] params = {ERROR_MSG, INFO_MSG};
053 for(int i = 0; i < params.length; ++i) {
054 String value = request.getParameter(params[i]);
055 if(value != null) response.setRenderParameter(params[i], value);
056 }
057 return getMode();
058 }
059
060 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException {
061 String[] params = {ERROR_MSG, INFO_MSG};
062 for(int i = 0; i < params.length; ++i) {
063 String value = request.getParameter(params[i]);
064 if(value != null) request.setAttribute(params[i], value);
065 }
066 try {
067 CertificationAuthority ca = getCertificationAuthority(request);
068 if(ca == null) {
069 throw new Exception("CA is not running. CA may not have been initialized.");
070 }
071 if(ca.isLocked()) {
072 request.setAttribute("caLocked", Boolean.TRUE);
073 throw new Exception("CA is locked. Unlock CA to view details.");
074 }
075
076 // Get CA details
077 Certificate caCert = ca.getCertificate();
078 request.setAttribute("cert", caCert);
079 request.setAttribute("highestSerial", ca.getHighestSerialNumber());
080 request.setAttribute("certText", CaUtils.base64Certificate(caCert));
081 PublicKey publickey = caCert.getPublicKey();
082 String keySize = null;
083 if(publickey instanceof RSAPublicKey) {
084 keySize = ""+((RSAPublicKey)publickey).getModulus().bitLength();
085 request.setAttribute("keySize", keySize);
086 }
087 Map fingerPrints = new HashMap();
088 fingerPrints.put("MD5", CertificateUtil.generateFingerprint(caCert, "MD5"));
089 fingerPrints.put("SHA1", CertificateUtil.generateFingerprint(caCert, "SHA1"));
090 request.setAttribute("fingerPrints", fingerPrints);
091 } catch (Exception e) {
092 request.setAttribute(ERROR_MSG, e.toString());
093 log.error("Errors while trying to view CA Details.", e);
094 }
095 }
096
097 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
098 return getMode()+BEFORE_ACTION;
099 }
100 }