KickJava   Java API By Example, From Geeks To Geeks.

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


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.math.BigInteger JavaDoc;
22 import java.security.PublicKey JavaDoc;
23 import java.security.cert.Certificate JavaDoc;
24 import java.security.interfaces.RSAPublicKey JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
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 /**
41  * Handler for view certificate screen.
42  *
43  * @version $Rev: 476291 $ $Date: 2006-11-17 15:05:24 -0500 (Fri, 17 Nov 2006) $
44  */

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 JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
52         String JavaDoc[] params = {ERROR_MSG, INFO_MSG, "sNo"};
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         String JavaDoc errorMsg = request.getParameter(ERROR_MSG);
67         String JavaDoc sNo = request.getParameter("sNo");
68         try {
69             if(!request.getParameterMap().containsKey("sNo")) {
70                 // Show the page to get serial number of the certificate to be viewed
71
request.setAttribute("sNo", null);
72                 return;
73             }
74             CertificationAuthority ca = getCertificationAuthority(request);
75             
76             String JavaDoc certText = ca.getCertificateBase64Text(new BigInteger JavaDoc(sNo.trim()));
77             Certificate JavaDoc cert = ca.getCertificate(new BigInteger JavaDoc(sNo.trim()));
78             PublicKey JavaDoc publickey = cert.getPublicKey();
79             String JavaDoc keySize = null;
80             if(publickey instanceof RSAPublicKey JavaDoc) {
81                 keySize = ""+((RSAPublicKey JavaDoc)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             // Generate Certificate Fingerprints
88
Map JavaDoc fingerPrints = new HashMap JavaDoc();
89             fingerPrints.put("MD5", CertificateUtil.generateFingerprint(cert, "MD5"));
90             fingerPrints.put("SHA1", CertificateUtil.generateFingerprint(cert, "SHA1"));
91             request.setAttribute("fingerPrints", fingerPrints);
92             // Check if the certificate issue process started from "requests to be fulfilled" page.
93
// If so, provide a link to go back to that page
94
if("true".equalsIgnoreCase(request.getParameter("linkToListRequests")))
95                 request.setAttribute("linkToListRequests", Boolean.TRUE);
96         } catch (Exception JavaDoc 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 JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
104         return getMode()+BEFORE_ACTION;
105     }
106 }
107
Popular Tags