KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > ca > CADetailsHandler


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.console.ca;
19
20 import java.io.IOException JavaDoc;
21 import java.security.PublicKey JavaDoc;
22 import java.security.cert.Certificate JavaDoc;
23 import java.security.interfaces.RSAPublicKey JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
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 /**
41  * Handler for the CA details screen.
42  *
43  * @version $Rev: 476291 $ $Date: 2006-11-17 15:05:24 -0500 (Fri, 17 Nov 2006) $
44  */

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 JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
52         String JavaDoc[] params = {ERROR_MSG, INFO_MSG};
53         for(int i = 0; i < params.length; ++i) {
54             String JavaDoc 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 JavaDoc {
61         String JavaDoc[] params = {ERROR_MSG, INFO_MSG};
62         for(int i = 0; i < params.length; ++i) {
63             String JavaDoc 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 JavaDoc("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 JavaDoc("CA is locked. Unlock CA to view details.");
74             }
75             
76             // Get CA details
77
Certificate JavaDoc caCert = ca.getCertificate();
78             request.setAttribute("cert", caCert);
79             request.setAttribute("highestSerial", ca.getHighestSerialNumber());
80             request.setAttribute("certText", CaUtils.base64Certificate(caCert));
81             PublicKey JavaDoc publickey = caCert.getPublicKey();
82             String JavaDoc keySize = null;
83             if(publickey instanceof RSAPublicKey JavaDoc) {
84                 keySize = ""+((RSAPublicKey JavaDoc)publickey).getModulus().bitLength();
85                 request.setAttribute("keySize", keySize);
86             }
87             Map JavaDoc fingerPrints = new HashMap JavaDoc();
88             fingerPrints.put("MD5", CertificateUtil.generateFingerprint(caCert, "MD5"));
89             fingerPrints.put("SHA1", CertificateUtil.generateFingerprint(caCert, "SHA1"));
90             request.setAttribute("fingerPrints", fingerPrints);
91         } catch (Exception JavaDoc 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 JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
98         return getMode()+BEFORE_ACTION;
99     }
100 }
101
Popular Tags