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.SMAdapter; 025import org.jpos.util.NameRegistrar; 026import org.jpos.util.Realm; 027 028/** 029 * SMAdaptor Adaptor 030 * 031 * <b>Sample Configuration</b> 032 * <pre> 033 * <s-m-adaptor class="org.jpos.q2.security.SMAdaptor" logger="Q2"> 034 * <attr name="impl">org.jpos.security.jceadapter.JCESecurityModule</attr> 035 * 036 * <property name="provider" value="com.sun.crypto.provider.SunJCE" /> 037 * <property name="lmk" value="path/to/your/lmk" /> 038 * </s-m-adaptor> 039 * </pre> 040 * 041 * @author Hani Kirollos 042 * @author Alejandro Revilla 043 * @version $Revision$ $Date$ 044 */ 045public class SMAdaptor extends QBeanSupport implements SMAdaptorMBean 046{ 047 private static final String DEFAULT_IMPL = "org.jpos.security.jceadapter.JCESecurityModule"; 048 String clazz; 049 SMAdapter sm; 050 /** Default constructor. */ 051 public SMAdaptor () { 052 super (); 053 clazz = DEFAULT_IMPL; 054 } 055 056 @Override 057 protected String defaultRealm() { 058 return Realm.SECURITY; 059 } 060 061 protected void initService () throws Exception { 062 Element e = getPersist (); 063 QFactory factory = getServer().getFactory(); 064 sm = (SMAdapter) factory.newInstance (getImpl ()); 065 factory.setLogger (sm, e); 066 factory.setConfiguration (sm, e); 067 NameRegistrar.register (getName (), sm); 068 } 069 070 public void setImpl (String clazz) { 071 this.clazz = clazz; 072 } 073 074 public String getImpl() { 075 return clazz; 076 } 077 protected void stopService () throws Exception { 078 NameRegistrar.unregister (getName ()); 079 } 080}