01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
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: */package org.apache.geronimo.console.ca;
18:
19: import java.io.IOException;
20:
21: import javax.portlet.ActionRequest;
22: import javax.portlet.ActionResponse;
23: import javax.portlet.PortletException;
24: import javax.portlet.RenderRequest;
25: import javax.portlet.RenderResponse;
26:
27: import org.apache.commons.logging.Log;
28: import org.apache.commons.logging.LogFactory;
29: import org.apache.geronimo.console.MultiPageModel;
30: import org.apache.geronimo.management.geronimo.CertificationAuthority;
31:
32: /**
33: * Handler for unlock CA screen.
34: *
35: * @version $Rev: 514091 $ $Date: 2007-03-02 22:26:39 -0800 (Fri, 02 Mar 2007) $
36: */
37: public class UnlockCAHandler extends BaseCAHandler {
38: private final static Log log = LogFactory
39: .getLog(UnlockCAHandler.class);
40:
41: public UnlockCAHandler() {
42: super (UNLOCKCA_MODE, "/WEB-INF/view/ca/unlockCA.jsp");
43: }
44:
45: public String actionBeforeView(ActionRequest request,
46: ActionResponse response, MultiPageModel model)
47: throws PortletException, IOException {
48: String[] params = { ERROR_MSG, INFO_MSG };
49: for (int i = 0; i < params.length; ++i) {
50: String value = request.getParameter(params[i]);
51: if (value != null)
52: response.setRenderParameter(params[i], value);
53: }
54: return getMode();
55: }
56:
57: public void renderView(RenderRequest request,
58: RenderResponse response, MultiPageModel model)
59: throws PortletException, IOException {
60: String[] params = { ERROR_MSG, INFO_MSG };
61: for (int i = 0; i < params.length; ++i) {
62: Object value = request.getParameter(params[i]);
63: if (value != null)
64: request.setAttribute(params[i], value);
65: }
66: }
67:
68: public String actionAfterView(ActionRequest request,
69: ActionResponse response, MultiPageModel model)
70: throws PortletException, IOException {
71: String errorMsg = null;
72: try {
73: String password = request.getParameter("password");
74: if (password == null) {
75: throw new Exception("Password is null.");
76: }
77: CertificationAuthority ca = getCertificationAuthority(request);
78: if (ca == null) {
79: throw new Exception(
80: "CA is not running. CA may not have been initialized.");
81: }
82: ca.unlock(password.toCharArray());
83:
84: // Return to CA's index page
85: response.setRenderParameter(INFO_MSG,
86: "CA has been unlocked successfully!");
87: log.info("CA has been unlocked successfully!");
88: return INDEX_MODE + BEFORE_ACTION;
89: } catch (Exception e) {
90: errorMsg = e.toString();
91: log.error("Errors in unlocking CA.", e);
92: }
93: // An error occurred. Set the error message and load the page again.
94: response.setRenderParameter(ERROR_MSG, errorMsg);
95: return getMode() + BEFORE_ACTION;
96: }
97: }
|