001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.q2.security; 020 021import org.jdom2.Element; 022import org.jpos.q2.QBeanSupport; 023import org.jpos.q2.QFactory; 024import org.jpos.security.SecureKeyStore; 025import org.jpos.util.NameRegistrar; 026 027/** 028 * KeyStoreAdaptor 029 * 030 * <b>Sample Configuration</b> 031 * 032 * <pre> 033 * <key-store class="org.jpos.q2.security.KeyStoreAdaptor" logger="Q2"> 034 * <attr name="impl">org.jpos.security.SimpleKeyFile</attr> 035 * <property name="key-file" value="deploy/keys" /> 036 * </key-store> 037 * </pre> 038 * 039 * @author Hani Kirollos 040 * @author Alejandro Revilla 041 * @version $Revision$ $Date$ 042 */ 043public class KeyStoreAdaptor extends QBeanSupport implements KeyStoreAdaptorMBean 044{ 045 /** Default {@link SecureKeyStore} implementation used when no class is configured. */ 046 public static final String DEFAULT_IMPL="org.jpos.security.SimpleKeyFile"; 047 String clazz; 048 SecureKeyStore ks; 049 /** Default constructor. */ 050 public KeyStoreAdaptor () { 051 super (); 052 clazz = DEFAULT_IMPL; 053 } 054 protected void initService () throws Exception { 055 Element e = getPersist (); 056 QFactory factory = getServer().getFactory(); 057 ks = (SecureKeyStore) factory.newInstance (getImpl ()); 058 factory.setLogger (ks, e); 059 factory.setConfiguration (ks, e); 060 NameRegistrar.register (getName (), ks); 061 } 062 063 public void setImpl (String clazz) { 064 this.clazz = clazz; 065 } 066 067 public String getImpl() { 068 return clazz; 069 } 070 071 protected void destroyService () throws Exception { 072 NameRegistrar.unregister (getName ()); 073 } 074}