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.fileupload.FileItem;
19: import org.apache.geronimo.console.MultiPageModel;
20:
21: import javax.portlet.ActionRequest;
22: import javax.portlet.ActionResponse;
23: import javax.portlet.PortletException;
24: import javax.portlet.RenderRequest;
25: import javax.portlet.RenderResponse;
26: import java.io.File;
27: import java.io.IOException;
28:
29: /**
30: * Handler for entering a password to unlock a keystore
31: *
32: * @version $Rev: 476061 $ $Date: 2006-11-16 22:36:50 -0800 (Thu, 16 Nov 2006) $
33: */
34: public class UploadCertificateHandler extends BaseKeystoreHandler {
35: public UploadCertificateHandler() {
36: super (UPLOAD_CERTIFICATE,
37: "/WEB-INF/view/keystore/uploadCertificate.jsp");
38: }
39:
40: public String actionBeforeView(ActionRequest request,
41: ActionResponse response, MultiPageModel model)
42: throws PortletException, IOException {
43: String id = request.getParameter("id");
44: if (id != null) {
45: response.setRenderParameter("id", id);
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,
51: RenderResponse response, MultiPageModel model)
52: throws PortletException, IOException {
53: request.setAttribute("id", request.getParameter("id"));
54: }
55:
56: public String actionAfterView(ActionRequest request,
57: ActionResponse response, MultiPageModel model)
58: throws PortletException, IOException {
59: String id = getUploadFields().getProperty("id");
60: if (id == null) {
61: return LIST_MODE + BEFORE_ACTION;
62: }
63: String alias = getUploadFields().getProperty("alias");
64: if (alias == null) {
65: return getMode() + BEFORE_ACTION; //todo: some kind of error message
66: }
67: /* // Uploading certificate using a disk file fails on Windows. Certificate text is used instead.
68: File certFile;
69: FileItem item = (FileItem) getUploadFiles().get("certificate");
70: if(item != null) {
71: certFile = File.createTempFile("geronimo", ".cert");
72: certFile.deleteOnExit();
73: try {
74: item.write(certFile);
75: } catch (Exception e) {
76: throw new PortletException("Unable to save uploaded file", e);
77: }
78: } else {
79: response.setRenderParameter("id", id);
80: return getMode()+BEFORE_ACTION;
81: }
82: */
83: response.setRenderParameter("id", id); // the Keystore
84: // Uploading certificate using a disk file fails on Windows. Certificate text is used instead.
85: //response.setRenderParameter("certificate", certFile.getAbsolutePath());
86: response.setRenderParameter("certificate", getUploadFields()
87: .getProperty("certificate"));
88: response.setRenderParameter("alias", alias);
89:
90: return CONFIRM_CERTIFICATE + BEFORE_ACTION;
91: }
92: }
|