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