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 java.io.IOException;
19: import javax.portlet.ActionRequest;
20: import javax.portlet.ActionResponse;
21: import javax.portlet.PortletException;
22: import javax.portlet.RenderRequest;
23: import javax.portlet.RenderResponse;
24: import javax.portlet.PortletSession;
25: import org.apache.geronimo.console.MultiPageModel;
26: import org.apache.geronimo.console.util.PortletManager;
27: import org.apache.geronimo.management.geronimo.KeystoreException;
28: import org.apache.geronimo.management.geronimo.KeystoreInstance;
29: import org.apache.geronimo.crypto.KeystoreUtil;
30:
31: /**
32: * Handler for creating a keystore
33: *
34: * @version $Rev: 617588 $ $Date: 2008-02-01 10:20:07 -0800 (Fri, 01 Feb 2008) $
35: */
36: public class CreateKeystoreHandler extends BaseKeystoreHandler {
37: public CreateKeystoreHandler() {
38: super (CREATE_KEYSTORE,
39: "/WEB-INF/view/keystore/createKeystore.jsp");
40: }
41:
42: public String actionBeforeView(ActionRequest request,
43: ActionResponse response, MultiPageModel model)
44: throws PortletException, IOException {
45: return getMode();
46: }
47:
48: public void renderView(RenderRequest request,
49: RenderResponse response, MultiPageModel model)
50: throws PortletException, IOException {
51: if (request.getParameter("filename") != null) {
52: request.setAttribute("filename", request
53: .getParameter("filename"));
54: }
55: request.setAttribute("keystoreTypes",
56: KeystoreUtil.emptyKeystoreTypes);
57: request.setAttribute("defaultType", KeystoreUtil.defaultType);
58: }
59:
60: public String actionAfterView(ActionRequest request,
61: ActionResponse response, MultiPageModel model)
62: throws PortletException, IOException {
63: String filename = request.getParameter("filename");
64: String password = request.getParameter("password");
65: String type = request.getParameter("type");
66: if (filename == null || filename.equals("")) {
67: return getMode();
68: } else if (password == null) {
69: response.setRenderParameter("filename", filename);
70: return getMode();
71: }
72: try {
73: KeystoreInstance instance = PortletManager
74: .getCurrentServer(request).getKeystoreManager()
75: .createKeystore(filename, password.toCharArray(),
76: type);
77: PortletSession session = request.getPortletSession(true);
78: KeystoreData data = new KeystoreData();
79: data.setInstance(instance);
80: session.setAttribute(KEYSTORE_DATA_PREFIX + filename, data);
81: char[] cpw = password.toCharArray();
82: data.unlockEdit(cpw);
83: } catch (KeystoreException e) {
84: throw new PortletException(e);
85: }
86: return LIST_MODE + BEFORE_ACTION;
87: }
88: }
|