KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > keystores > EditKeystoreHandler


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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  */

17 package org.apache.geronimo.console.keystores;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.geronimo.console.MultiPageModel;
22 import org.apache.geronimo.management.geronimo.KeystoreException;
23
24 import javax.portlet.ActionRequest;
25 import javax.portlet.ActionResponse;
26 import javax.portlet.PortletException;
27 import javax.portlet.RenderRequest;
28 import javax.portlet.RenderResponse;
29 import java.io.IOException JavaDoc;
30
31 /**
32  * Handler for entering a password to allow editing of a keystore
33  *
34  * @version $Rev: 477134 $ $Date: 2006-11-20 05:19:42 -0500 (Mon, 20 Nov 2006) $
35  */

36 public class EditKeystoreHandler extends BaseKeystoreHandler {
37     private final static Log log = LogFactory.getLog(EditKeystoreHandler.class);
38     public EditKeystoreHandler() {
39         super(UNLOCK_KEYSTORE_FOR_EDITING, "/WEB-INF/view/keystore/unlockKeystore.jsp");
40     }
41
42     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
43         String JavaDoc keystore = request.getParameter("keystore");
44         if(keystore != null) {
45             response.setRenderParameter("keystore", keystore);
46         } // else we hope this is after a failure and the actionAfterView took care of it below!
47
return getMode();
48     }
49
50     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
51         String JavaDoc[] params = {ERROR_MSG, INFO_MSG};
52         for(int i = 0; i < params.length; ++i) {
53             String JavaDoc value = request.getParameter(params[i]);
54             if(value != null) request.setAttribute(params[i], value);
55         }
56         request.setAttribute("keystore", request.getParameter("keystore"));
57         request.setAttribute("mode", "unlockEdit");
58     }
59
60     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
61         String JavaDoc keystore = request.getParameter("keystore");
62         String JavaDoc password = request.getParameter("password");
63         if(keystore == null || keystore.equals("")) {
64             return getMode(); // todo: this is bad; if there's no ID, then the form on the page is just not valid!
65
} else if(password == null) {
66             response.setRenderParameter("keystore", keystore);
67             return getMode();
68         }
69         KeystoreData data = ((KeystoreData) request.getPortletSession(true).getAttribute(KEYSTORE_DATA_PREFIX + keystore));
70         char[] storePass = password.toCharArray();
71         try {
72             data.unlockEdit(storePass);
73         } catch (KeystoreException e) {
74             response.setRenderParameter(ERROR_MSG, "Unable to unlock keystore "+keystore+" for editing. "+e.toString());
75             log.error("Unable to unlock keystore "+keystore+" for editing.", e);
76             return getMode()+BEFORE_ACTION;
77         }
78         response.setRenderParameter(INFO_MSG, "Keystore "+keystore+" successfully unlocked for editing.");
79         return LIST_MODE+BEFORE_ACTION;
80     }
81 }
82
Popular Tags