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 * &lt;key-store class="org.jpos.q2.security.KeyStoreAdaptor" logger="Q2"&gt;
034 *  &lt;attr name="impl"&gt;org.jpos.security.SimpleKeyFile&lt;/attr&gt;
035 *  &lt;property name="key-file" value="deploy/keys" /&gt;
036 * &lt;/key-store&gt;
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    public static final String DEFAULT_IMPL="org.jpos.security.SimpleKeyFile";
046    String clazz;
047    SecureKeyStore ks;
048    public KeyStoreAdaptor () {
049        super ();
050        clazz = DEFAULT_IMPL;
051    }
052    protected void initService () throws Exception {
053        Element e = getPersist ();
054        QFactory factory = getServer().getFactory();
055        ks = (SecureKeyStore) factory.newInstance (getImpl ());
056        factory.setLogger  (ks, e);
057        factory.setConfiguration (ks, e);
058        NameRegistrar.register (getName (), ks);
059    }
060
061    public void setImpl (String clazz) {
062        this.clazz = clazz;
063    }
064
065    public String getImpl() {
066        return clazz;
067    }
068
069    protected void destroyService () throws Exception {
070        NameRegistrar.unregister (getName ());
071    }
072}