001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.console.keystores;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.apache.geronimo.console.MultiPageModel;
021:
022: import javax.portlet.ActionRequest;
023: import javax.portlet.ActionResponse;
024: import javax.portlet.PortletException;
025: import javax.portlet.RenderRequest;
026: import javax.portlet.RenderResponse;
027: import java.io.IOException;
028:
029: /**
030: * Handler for changing keystore and private key passwords.
031: *
032: * @version $Rev: 599515 $ $Date: 2007-11-29 08:52:21 -0800 (Thu, 29 Nov 2007) $
033: */
034: public class ChangePasswordHandler extends BaseKeystoreHandler {
035: private final static Log log = LogFactory
036: .getLog(ChangePasswordHandler.class);
037:
038: public ChangePasswordHandler() {
039: super (CHANGE_PASSWORD,
040: "/WEB-INF/view/keystore/changePassword.jsp");
041: }
042:
043: public String actionBeforeView(ActionRequest request,
044: ActionResponse response, MultiPageModel model)
045: throws PortletException, IOException {
046: String[] params = { ERROR_MSG, INFO_MSG, "keystore", "alias" };
047: for (int i = 0; i < params.length; ++i) {
048: String value = request.getParameter(params[i]);
049: if (value != null)
050: response.setRenderParameter(params[i], value);
051: }
052: return getMode();
053: }
054:
055: public void renderView(RenderRequest request,
056: RenderResponse response, MultiPageModel model)
057: throws PortletException, IOException {
058: String[] params = { ERROR_MSG, INFO_MSG, "keystore", "alias" };
059: for (int i = 0; i < params.length; ++i) {
060: String value = request.getParameter(params[i]);
061: if (value != null)
062: request.setAttribute(params[i], value);
063: }
064: request.setAttribute("mode", getMode() + AFTER_ACTION);
065: }
066:
067: public String actionAfterView(ActionRequest request,
068: ActionResponse response, MultiPageModel model)
069: throws PortletException, IOException {
070: String keystore = request.getParameter("keystore");
071: String alias = request.getParameter("alias");
072: String password = request.getParameter("password");
073: String newPassword = request.getParameter("newPassword");
074: if (keystore == null || keystore.equals("")) {
075: return getMode();
076: } else if (password == null) {
077: response.setRenderParameter("keystore", keystore);
078: if (alias != null && !alias.equals("")) {
079: response.setRenderParameter("alias", alias);
080: }
081: return getMode();
082: }
083: KeystoreData data = ((KeystoreData) request.getPortletSession(
084: true).getAttribute(KEYSTORE_DATA_PREFIX + keystore));
085: try {
086: if (alias == null || alias.equals("")) {
087: // Keystore password is to be changed.
088: data.changeKeystorePassword(password.toCharArray(),
089: newPassword.toCharArray());
090: response.setRenderParameter("id", keystore);
091: response.setRenderParameter(INFO_MSG,
092: "Password changed for keystore '" + keystore
093: + "'.");
094: return VIEW_KEYSTORE + BEFORE_ACTION;
095: } else {
096: // Private key password is to be changed.
097: data.changeKeyPassword(alias, password.toCharArray(),
098: newPassword.toCharArray());
099: response.setRenderParameter("id", keystore);
100: response.setRenderParameter("alias", alias);
101: response.setRenderParameter(INFO_MSG,
102: "Password changed for private key '" + alias
103: + "'.");
104: return CERTIFICATE_DETAILS;
105: }
106: } catch (Exception e) {
107: String message = "Unable to change password for "
108: + (alias == null || alias.equals("") ? "keystore "
109: + keystore : "private key " + alias) + ".";
110: response.setRenderParameter(ERROR_MSG, message + " "
111: + e.toString());
112: log.error(message, e);
113: return getMode() + BEFORE_ACTION;
114: }
115: }
116: }
|