KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import javax.portlet.ActionRequest;
23 import javax.portlet.ActionResponse;
24 import javax.portlet.PortletException;
25 import javax.portlet.RenderRequest;
26 import javax.portlet.RenderResponse;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.geronimo.console.MultiPageModel;
31 import org.apache.geronimo.management.geronimo.CertificationAuthority;
32
33 /**
34  * Handler for the CA home screen.
35  *
36  * @version $Rev: 476291 $ $Date: 2006-11-17 15:05:24 -0500 (Fri, 17 Nov 2006) $
37  */

38 public class IntroHandler extends BaseCAHandler {
39     private final static Log log = LogFactory.getLog(IntroHandler.class);
40     public IntroHandler() {
41         super(INDEX_MODE, "/WEB-INF/view/ca/index.jsp");
42     }
43
44     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
45         String JavaDoc[] params = new String JavaDoc[] {ERROR_MSG, INFO_MSG};
46         for(int i = 0; i < params.length; ++i) {
47             String JavaDoc value = request.getParameter(params[i]);
48             if(value != null) response.setRenderParameter(params[i], value);
49         }
50         return getMode();
51     }
52
53     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
54         String JavaDoc[] params = {ERROR_MSG, INFO_MSG};
55         for(int i = 0; i < params.length; ++i) {
56             String JavaDoc value = request.getParameter(params[i]);
57             if(value != null) request.setAttribute(params[i], value);
58         }
59         
60         CertificationAuthority ca = getCertificationAuthority(request);
61         if(ca == null) {
62             // CA GBean is not running or the CA has not been initialized.
63
request.setAttribute("caNotSetup", Boolean.TRUE);
64         } else {
65             request.setAttribute("caNotSetup", Boolean.FALSE);
66             request.setAttribute("caLocked", ca.isLocked() ? Boolean.TRUE : Boolean.FALSE);
67         }
68     }
69
70     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
71         if(request.getParameter("lock") != null) {
72             CertificationAuthority ca = getCertificationAuthority(request);
73             if(ca == null) {
74                 log.warn("CA is not running or CA may not have been initialized. Unable to lock CA.");
75                 response.setRenderParameter(ERROR_MSG, "CA is not running or CA may not have been initialized. Unable to lock CA.");
76             } else {
77                 ca.lock();
78                 log.info("CA is now locked.");
79                 response.setRenderParameter(INFO_MSG, "CA has been locked!");
80             }
81         } else if(request.getParameter("publish") != null) {
82             CertificationAuthority ca = getCertificationAuthority(request);
83             try {
84                 getCertificateStore(request).storeCACertificate(ca.getCertificate());
85                 response.setRenderParameter(INFO_MSG, "CA's certificate published to Certificate Store");
86             } catch (Exception JavaDoc e) {
87                 log.error("Error while publishing CA's certificate to Certificate Store", e);
88                 response.setRenderParameter(ERROR_MSG, "Error while publishing CA's certificate to Certificate Store. "+e);
89             }
90         }
91         return getMode()+BEFORE_ACTION;
92     }
93 }
94
Popular Tags