KickJava   Java API By Example, From Geeks To Geeks.

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


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 unlock CA screen.
35  *
36  * @version $Rev: 476291 $ $Date: 2006-11-17 15:05:24 -0500 (Fri, 17 Nov 2006) $
37  */

38 public class UnlockCAHandler extends BaseCAHandler {
39     private final static Log log = LogFactory.getLog(UnlockCAHandler.class);
40     public UnlockCAHandler() {
41         super(UNLOCKCA_MODE, "/WEB-INF/view/ca/unlockCA.jsp");
42     }
43
44     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
45         String JavaDoc[] params = {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             Object JavaDoc value = request.getParameter(params[i]);
57             if(value != null) request.setAttribute(params[i], value);
58         }
59     }
60
61     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
62         String JavaDoc errorMsg = null;
63         try {
64             String JavaDoc password = request.getParameter("password");
65             if(password == null) {
66                 throw new Exception JavaDoc("Password is null.");
67             }
68             CertificationAuthority ca = getCertificationAuthority(request);
69             if(ca == null) {
70                 throw new Exception JavaDoc("CA is not running. CA may not have been initialized.");
71             }
72             ca.unlock(password.toCharArray());
73
74             // Return to CA's index page
75
response.setRenderParameter(INFO_MSG, "CA has been unlocked successfully!");
76             log.info("CA has been unlocked successfully!");
77             return INDEX_MODE+BEFORE_ACTION;
78         } catch(Exception JavaDoc e) {
79             errorMsg = e.toString();
80             log.error("Errors in unlocking CA.", e);
81         }
82         // An error occurred. Set the error message and load the page again.
83
response.setRenderParameter(ERROR_MSG, errorMsg);
84         return getMode()+BEFORE_ACTION;
85     }
86 }
87
Popular Tags