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 unlock a key
32: *
33: * @version $Rev: 477279 $ $Date: 2006-11-20 10:42:26 -0800 (Mon, 20 Nov 2006) $
34: */
35: public class UnlockKeyHandler extends BaseKeystoreHandler {
36: private final static Log log = LogFactory
37: .getLog(UnlockKeyHandler.class);
38:
39: public UnlockKeyHandler() {
40: super (UNLOCK_KEY, "/WEB-INF/view/keystore/unlockKey.jsp");
41: }
42:
43: public String actionBeforeView(ActionRequest request,
44: ActionResponse response, MultiPageModel model)
45: throws PortletException, IOException {
46: return getMode();
47: }
48:
49: public void renderView(RenderRequest request,
50: RenderResponse response, MultiPageModel model)
51: throws PortletException, IOException {
52: String[] params = { ERROR_MSG, INFO_MSG };
53: for (int i = 0; i < params.length; ++i) {
54: String value = request.getParameter(params[i]);
55: if (value != null)
56: request.setAttribute(params[i], value);
57: }
58: String keystore = request.getParameter("keystore");
59: String password = request.getParameter("password");
60: request.setAttribute("keystore", keystore);
61: request.setAttribute("password", password);
62: KeystoreData data = ((KeystoreData) request.getPortletSession(
63: true).getAttribute(KEYSTORE_DATA_PREFIX + keystore));
64: try {
65: request.setAttribute("keys", data.getInstance()
66: .listPrivateKeys(password.toCharArray()));
67: } catch (KeystoreException e) {
68: throw new PortletException(e);
69: }
70: }
71:
72: public String actionAfterView(ActionRequest request,
73: ActionResponse response, MultiPageModel model)
74: throws PortletException, IOException {
75: String keystore = request.getParameter("keystore");
76: String password = request.getParameter("password");
77: String alias = request.getParameter("keyAlias");
78: String keyPassword = request.getParameter("keyPassword");
79: if (keystore == null || keystore.equals("")) {
80: return getMode(); // todo: this is bad; if there's no ID, then the form on the page is just not valid!
81: }
82: KeystoreData data = ((KeystoreData) request.getPortletSession(
83: true).getAttribute(KEYSTORE_DATA_PREFIX + keystore));
84: try {
85: data.unlockPrivateKey(alias, keyPassword.toCharArray());
86: } catch (KeystoreException e) {
87: response.setRenderParameter("keystore", keystore);
88: response.setRenderParameter("password", password);
89: response.setRenderParameter(ERROR_MSG,
90: "Unable to unlock key '" + alias + "'." + e);
91: log.error("Unable to unlock key '" + alias + "'.", e);
92: return getMode() + BEFORE_ACTION;
93: }
94: response.setRenderParameter(INFO_MSG,
95: "Successfully unlocked key '" + alias
96: + "' in keystore '" + keystore + "'.");
97: return LIST_MODE + BEFORE_ACTION;
98: }
99: }
|