1 13 14 package org.ejbca.core.protocol.xkms.generators; 15 16 import javax.ejb.CreateException ; 17 import javax.ejb.EJBException ; 18 import javax.naming.Context ; 19 import javax.naming.InitialContext ; 20 import javax.naming.NamingException ; 21 22 import org.apache.log4j.Logger; 23 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal; 24 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocalHome; 25 import org.ejbca.core.ejb.ca.auth.IAuthenticationSessionLocal; 26 import org.ejbca.core.ejb.ca.auth.IAuthenticationSessionLocalHome; 27 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal; 28 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome; 29 import org.ejbca.core.ejb.ca.sign.ISignSessionLocal; 30 import org.ejbca.core.ejb.ca.sign.ISignSessionLocalHome; 31 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal; 32 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocalHome; 33 import org.ejbca.core.ejb.keyrecovery.IKeyRecoverySessionLocal; 34 import org.ejbca.core.ejb.keyrecovery.IKeyRecoverySessionLocalHome; 35 import org.ejbca.core.ejb.ra.IUserAdminSessionLocal; 36 import org.ejbca.core.ejb.ra.IUserAdminSessionLocalHome; 37 import org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionLocal; 38 import org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionLocalHome; 39 import org.ejbca.core.model.InternalResources; 40 import org.ejbca.core.model.log.Admin; 41 42 51 52 public abstract class BaseResponseGenerator { 53 54 private static Logger log = Logger.getLogger(BaseResponseGenerator.class); 55 56 private static final InternalResources intres = InternalResources.getInstance(); 57 58 protected Admin raAdmin = null; 59 protected Admin pubAdmin = null; 60 61 protected String remoteIP = null; 62 63 public BaseResponseGenerator(String remoteIP){ 64 this.remoteIP = remoteIP; 65 raAdmin = new Admin(Admin.TYPE_RA_USER,remoteIP); 66 pubAdmin = new Admin(Admin.TYPE_PUBLIC_WEB_USER, remoteIP); 67 } 68 69 70 private ICAAdminSessionLocal caadminsession = null; 71 protected ICAAdminSessionLocal getCAAdminSession() throws ClassCastException , CreateException , NamingException { 72 if(caadminsession == null){ 73 Context context = new InitialContext (); 74 caadminsession = ((ICAAdminSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup( 75 "CAAdminSessionLocal"), ICAAdminSessionLocalHome.class)).create(); 76 } 77 return caadminsession; 78 } 79 80 private IRaAdminSessionLocal raadminsession = null; 81 protected IRaAdminSessionLocal getRAAdminSession() throws ClassCastException , CreateException , NamingException { 82 if(raadminsession == null){ 83 Context context = new InitialContext (); 84 raadminsession = ((IRaAdminSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup( 85 "RaAdminSessionLocal"), IRaAdminSessionLocalHome.class)).create(); 86 } 87 return raadminsession; 88 } 89 90 private ICertificateStoreSessionLocal certificatestoresession = null; 91 protected ICertificateStoreSessionLocal getCertStoreSession() throws ClassCastException , CreateException , NamingException { 92 if(certificatestoresession == null){ 93 Context context = new InitialContext (); 94 certificatestoresession = ((ICertificateStoreSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup( 95 "CertificateStoreSessionLocal"), ICertificateStoreSessionLocalHome.class)).create(); 96 } 97 return certificatestoresession; 98 } 99 100 private ISignSessionLocal signsession = null; 101 protected ISignSessionLocal getSignSession() throws ClassCastException , CreateException , NamingException { 102 if(signsession == null){ 103 Context context = new InitialContext (); 104 signsession = ((ISignSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup( 105 "SignSessionLocal"), ISignSessionLocalHome.class)).create(); 106 } 107 return signsession; 108 } 109 110 private IUserAdminSessionLocal usersession = null; 111 protected IUserAdminSessionLocal getUserAdminSession() { 112 try{ 113 if(usersession == null){ 114 Context context = new InitialContext (); 115 usersession = ((IUserAdminSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup( 116 "UserAdminSessionLocal"), IUserAdminSessionLocalHome.class)).create(); 117 } 118 }catch(Exception e) { 119 log.error(intres.getLocalizedMessage("xkms.errorinitadminsession")); 120 throw new EJBException (e); 121 } 122 return usersession; 123 } 124 125 126 private IAuthorizationSessionLocal authsession = null; 127 protected IAuthorizationSessionLocal getAuthorizationSession() { 128 try{ 129 if(authsession == null){ 130 Context context = new InitialContext (); 131 authsession = ((IAuthorizationSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup( 132 "AuthorizationSessionLocal"), IAuthorizationSessionLocalHome.class)).create(); 133 } 134 }catch(Exception e) { 135 log.error(intres.getLocalizedMessage("xkms.errorinitauthsession")); 136 throw new EJBException (e); 137 } 138 return authsession; 139 } 140 141 private IKeyRecoverySessionLocal keyrecoverysession = null; 142 protected IKeyRecoverySessionLocal getKeyRecoverySession() { 143 try{ 144 if(keyrecoverysession == null){ 145 Context context = new InitialContext (); 146 keyrecoverysession = ((IKeyRecoverySessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup( 147 "KeyRecoverySessionLocal"), IKeyRecoverySessionLocalHome.class)).create(); 148 } 149 }catch(Exception e) { 150 log.error(intres.getLocalizedMessage("xkms.errorinitkeyrecsession")); 151 throw new EJBException (e); 152 } 153 return keyrecoverysession; 154 } 155 156 private IAuthenticationSessionLocal authenticationSession = null; 157 protected IAuthenticationSessionLocal getAuthenticationSession() { 158 try{ 159 if(authenticationSession == null){ 160 Context context = new InitialContext (); 161 authenticationSession = ((IAuthenticationSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup( 162 "AuthenticationSessionLocal"), IAuthenticationSessionLocalHome.class)).create(); 163 } 164 }catch(Exception e) { 165 log.error(intres.getLocalizedMessage("xkms.errorinitauthentsession")); 166 throw new EJBException (e); 167 } 168 return authenticationSession; 169 } 170 171 172 } 173 | Popular Tags |