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.geronimo.console.MultiPageModel;
19: import org.apache.geronimo.management.geronimo.KeystoreException;
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.IOException;
27: import java.security.cert.Certificate;
28:
29: /**
30: * Handler for displaying Trusted Certificate or Private Key Certificate details
31: *
32: * @version $Rev: 599515 $ $Date: 2007-11-29 08:52:21 -0800 (Thu, 29 Nov 2007) $
33: */
34: public class CertificateDetailsHandler extends BaseKeystoreHandler {
35: public CertificateDetailsHandler() {
36: super (CERTIFICATE_DETAILS,
37: "/WEB-INF/view/keystore/certificateDetails.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: String alias = request.getParameter("alias");
45: response.setRenderParameter("id", id);
46: response.setRenderParameter("alias", alias);
47: return getMode();
48: }
49:
50: public void renderView(RenderRequest request,
51: RenderResponse response, MultiPageModel model)
52: throws PortletException, IOException {
53: String[] params = { ERROR_MSG, INFO_MSG };
54: for (int i = 0; i < params.length; ++i) {
55: String value = request.getParameter(params[i]);
56: if (value != null)
57: request.setAttribute(params[i], value);
58: }
59: String id = request.getParameter("id");
60: String alias = request.getParameter("alias");
61: if (alias == null
62: && request.getParameterMap().containsKey("alias")) {
63: // Happens with an alias ""
64: alias = "";
65: }
66: KeystoreData data = ((KeystoreData) request.getPortletSession(
67: true).getAttribute(KEYSTORE_DATA_PREFIX + id));
68: Certificate cert;
69: try {
70: cert = data.getCertificate(alias);
71: } catch (KeystoreException e) {
72: throw new PortletException(e);
73: }
74: String type = "Trusted Certificate";
75: boolean keyLocked = true;
76: String[] keys = data.getKeys();
77: for (int i = 0; i < keys.length; ++i) {
78: if (keys[i].equals(alias)) {
79: type = "Private Key";
80: keyLocked = data.getInstance().isKeyLocked(alias);
81: }
82: }
83: request.setAttribute("id", id);
84: request.setAttribute("alias", alias);
85: request.setAttribute("type", type);
86: request.setAttribute("keyLocked", new Boolean(keyLocked));
87: // TODO: Handle certificate chain
88: request.setAttribute("certs", new Certificate[] { cert });
89: }
90:
91: public String actionAfterView(ActionRequest request,
92: ActionResponse response, MultiPageModel model)
93: throws PortletException, IOException {
94: String id = request.getParameter("id");
95: response.setRenderParameter("id", id);
96: return VIEW_KEYSTORE + BEFORE_ACTION;
97: }
98: }
|