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 java.io.IOException;
019: import java.util.HashMap;
020: import java.util.Map;
021: import javax.portlet.ActionRequest;
022: import javax.portlet.ActionResponse;
023: import javax.portlet.PortletException;
024: import javax.portlet.PortletSession;
025: import javax.portlet.RenderRequest;
026: import javax.portlet.RenderResponse;
027: import org.apache.geronimo.console.MultiPageModel;
028: import org.apache.geronimo.console.util.PortletManager;
029: import org.apache.geronimo.gbean.AbstractName;
030: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
031: import org.apache.geronimo.management.geronimo.KeystoreException;
032: import org.apache.geronimo.management.geronimo.KeystoreInstance;
033: import org.apache.geronimo.management.geronimo.KeystoreIsLocked;
034: import org.apache.geronimo.management.geronimo.KeystoreManager;
035:
036: /**
037: * Handler for the keystore list screen.
038: *
039: * @version $Rev: 477134 $ $Date: 2006-11-20 02:19:42 -0800 (Mon, 20 Nov 2006) $
040: */
041: public class ListHandler extends BaseKeystoreHandler {
042: public ListHandler() {
043: super (LIST_MODE, "/WEB-INF/view/keystore/index.jsp");
044: }
045:
046: public String actionBeforeView(ActionRequest request,
047: ActionResponse response, MultiPageModel model)
048: throws PortletException, IOException {
049: return getMode();
050: }
051:
052: public void renderView(RenderRequest request,
053: RenderResponse response, MultiPageModel model)
054: throws PortletException, IOException {
055: String[] params = { ERROR_MSG, INFO_MSG };
056: for (int i = 0; i < params.length; ++i) {
057: String value = request.getParameter(params[i]);
058: if (value != null)
059: request.setAttribute(params[i], value);
060: }
061: KeystoreManager manager = PortletManager.getCurrentServer(
062: request).getKeystoreManager();
063: KeystoreInstance[] keystores = manager.getKeystores();
064: PortletSession session = request.getPortletSession(true);
065: KeystoreData[] datas = new KeystoreData[keystores.length];
066: Map keys = new HashMap();
067: for (int i = 0; i < datas.length; i++) {
068: AbstractName aName = PortletManager.getNameFor(request,
069: keystores[i]);
070: String name = (String) aName.getName().get(
071: NameFactory.J2EE_NAME);
072: KeystoreData data = (KeystoreData) session
073: .getAttribute(KEYSTORE_DATA_PREFIX + name);
074: if (data == null) {
075: data = new KeystoreData();
076: data.setInstance(keystores[i]);
077: session.setAttribute(KEYSTORE_DATA_PREFIX + name, data);
078: }
079: datas[i] = data;
080: if (!data.getInstance().isKeystoreLocked()) {
081: try {
082: String[] all = data.getInstance().getUnlockedKeys(
083: null);
084: if (all.length > 0) {
085: keys.put(data.getInstance().getKeystoreName(),
086: all.length + " key"
087: + (all.length > 1 ? "s" : "")
088: + " ready");
089: } else {
090: keys.put(data.getInstance().getKeystoreName(),
091: "trust store only");
092: }
093: } catch (KeystoreException locked) {
094: }
095: }
096: }
097: request.setAttribute("keystores", datas);
098: request.setAttribute("keys", keys);
099: }
100:
101: public String actionAfterView(ActionRequest request,
102: ActionResponse response, MultiPageModel model)
103: throws PortletException, IOException {
104: return getMode() + BEFORE_ACTION;
105: }
106:
107: }
|