01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.console.keystores;
17:
18: import org.apache.commons.logging.Log;
19: import org.apache.commons.logging.LogFactory;
20: import org.apache.geronimo.console.MultiPageModel;
21: import org.apache.geronimo.management.geronimo.KeystoreException;
22:
23: import javax.portlet.ActionRequest;
24: import javax.portlet.ActionResponse;
25: import javax.portlet.PortletException;
26: import javax.portlet.RenderRequest;
27: import javax.portlet.RenderResponse;
28: import java.io.IOException;
29:
30: /**
31: * Handler for entering a password to allow editing of a keystore
32: *
33: * @version $Rev: 477134 $ $Date: 2006-11-20 02:19:42 -0800 (Mon, 20 Nov 2006) $
34: */
35: public class EditKeystoreHandler extends BaseKeystoreHandler {
36: private final static Log log = LogFactory
37: .getLog(EditKeystoreHandler.class);
38:
39: public EditKeystoreHandler() {
40: super (UNLOCK_KEYSTORE_FOR_EDITING,
41: "/WEB-INF/view/keystore/unlockKeystore.jsp");
42: }
43:
44: public String actionBeforeView(ActionRequest request,
45: ActionResponse response, MultiPageModel model)
46: throws PortletException, IOException {
47: String keystore = request.getParameter("keystore");
48: if (keystore != null) {
49: response.setRenderParameter("keystore", keystore);
50: } // else we hope this is after a failure and the actionAfterView took care of it below!
51: return getMode();
52: }
53:
54: public void renderView(RenderRequest request,
55: RenderResponse response, MultiPageModel model)
56: throws PortletException, IOException {
57: String[] params = { ERROR_MSG, INFO_MSG };
58: for (int i = 0; i < params.length; ++i) {
59: String value = request.getParameter(params[i]);
60: if (value != null)
61: request.setAttribute(params[i], value);
62: }
63: request.setAttribute("keystore", request
64: .getParameter("keystore"));
65: request.setAttribute("mode", "unlockEdit");
66: }
67:
68: public String actionAfterView(ActionRequest request,
69: ActionResponse response, MultiPageModel model)
70: throws PortletException, IOException {
71: String keystore = request.getParameter("keystore");
72: String password = request.getParameter("password");
73: if (keystore == null || keystore.equals("")) {
74: return getMode(); // todo: this is bad; if there's no ID, then the form on the page is just not valid!
75: } else if (password == null) {
76: response.setRenderParameter("keystore", keystore);
77: return getMode();
78: }
79: KeystoreData data = ((KeystoreData) request.getPortletSession(
80: true).getAttribute(KEYSTORE_DATA_PREFIX + keystore));
81: char[] storePass = password.toCharArray();
82: try {
83: data.unlockEdit(storePass);
84: } catch (KeystoreException e) {
85: response.setRenderParameter(ERROR_MSG,
86: "Unable to unlock keystore " + keystore
87: + " for editing. " + e.toString());
88: log.error("Unable to unlock keystore " + keystore
89: + " for editing.", e);
90: return getMode() + BEFORE_ACTION;
91: }
92: response.setRenderParameter(INFO_MSG, "Keystore " + keystore
93: + " successfully unlocked for editing.");
94: return LIST_MODE + BEFORE_ACTION;
95: }
96: }
|