KickJava   Java API By Example, From Geeks To Geeks.

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


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.ByteArrayInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import javax.portlet.ActionRequest;
26 import javax.portlet.ActionResponse;
27 import javax.portlet.PortletException;
28 import javax.portlet.RenderRequest;
29 import javax.portlet.RenderResponse;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.apache.geronimo.console.MultiPageModel;
34 import org.apache.geronimo.management.geronimo.CertificateRequestStore;
35 import org.apache.geronimo.util.CaUtils;
36 import org.apache.geronimo.util.asn1.x509.X509Name;
37
38 /**
39  * Handler for "Requests to be fulfilled" screen.
40  *
41  * @version $Rev: 476291 $ $Date: 2006-11-17 15:05:24 -0500 (Fri, 17 Nov 2006) $
42  */

43 public class ListRequestsIssueHandler extends BaseCAHandler {
44     private final static Log log = LogFactory.getLog(ListRequestsIssueHandler.class);
45     public ListRequestsIssueHandler() {
46         super(LIST_REQUESTS_ISSUE_MODE, "/WEB-INF/view/ca/listRequestsIssue.jsp");
47     }
48
49     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
50         String JavaDoc[] params = {ERROR_MSG, INFO_MSG};
51         for(int i = 0; i < params.length; ++i) {
52             String JavaDoc value = request.getParameter(params[i]);
53             if(value != null) response.setRenderParameter(params[i], value);
54         }
55         return getMode();
56     }
57
58     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
59         String JavaDoc[] params = {ERROR_MSG, INFO_MSG};
60         for(int i = 0; i < params.length; ++i) {
61             String JavaDoc value = request.getParameter(params[i]);
62             if(value != null) request.setAttribute(params[i], value);
63         }
64         CertificateRequestStore csrStore = getCertificateRequestStore(request);
65         String JavaDoc[] csrIds = csrStore.getVerifiedRequestIds();
66         request.setAttribute("csrIds", csrIds);
67     }
68
69     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
70         String JavaDoc errorMsg = null;
71         String JavaDoc requestId = request.getParameter("requestId");
72         try {
73             response.setRenderParameter("requestId", requestId);
74             // Retrieve the request info based on the requestId
75
String JavaDoc certreq = getCertificateRequestStore(request).getRequest(requestId);
76             if(certreq.startsWith(CaUtils.CERT_REQ_HEADER)) {
77                 // This is a PKCS 10 Request
78
Map JavaDoc certReqMap = CaUtils.processPKCS10Request(certreq);
79                 // Set the subject and publickey values to be displayed in subsequent screens
80
response.setRenderParameter("subject", certReqMap.get(CaUtils.CERT_REQ_SUBJECT).toString());
81                 response.setRenderParameter("publickey", certReqMap.get(CaUtils.CERT_REQ_PUBLICKEY_OBJ).toString());
82             } else {
83                 // This is a custom request containing SPKAC and X509Name attributes received through web browser
84
Properties JavaDoc csrProps = new Properties JavaDoc();
85                 csrProps.load(new ByteArrayInputStream JavaDoc(certreq.getBytes()));
86                 String JavaDoc spkac = csrProps.getProperty("SPKAC");
87                 String JavaDoc cn = csrProps.getProperty("CN");
88                 String JavaDoc ou = csrProps.getProperty("OU");
89                 String JavaDoc o = csrProps.getProperty("O");
90                 String JavaDoc l = csrProps.getProperty("L");
91                 String JavaDoc st = csrProps.getProperty("ST");
92                 String JavaDoc c = csrProps.getProperty("C");
93                 X509Name subject = CaUtils.getX509Name(cn, ou, o, l, st, c);
94                 Map JavaDoc certReqMap = CaUtils.processSPKAC(spkac);
95                 // Set the subject and publickey values to be displayed in subsequent screens
96
response.setRenderParameter("subject", subject.toString());
97                 response.setRenderParameter("publickey", certReqMap.get(CaUtils.CERT_REQ_PUBLICKEY_OBJ).toString());
98             }
99             return CERT_REQ_DETAILS_MODE+BEFORE_ACTION;
100         } catch(Exception JavaDoc e) {
101             errorMsg = e.toString();
102             log.error("Errors while processing a Certificate Request. id="+requestId, e);
103         }
104         response.setRenderParameter(ERROR_MSG, errorMsg);
105         return getMode()+BEFORE_ACTION;
106     }
107 }
108
Popular Tags