KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > protocol > xkms > generators > BaseResponseGenerator


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package org.ejbca.core.protocol.xkms.generators;
15
16 import javax.ejb.CreateException JavaDoc;
17 import javax.ejb.EJBException JavaDoc;
18 import javax.naming.Context JavaDoc;
19 import javax.naming.InitialContext JavaDoc;
20 import javax.naming.NamingException JavaDoc;
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 /**
43  *
44  * The most basic response generator that manages connections
45  * with EJBCA session beans
46  *
47  * @author Philip Vendil 2006 sep 27
48  *
49  * @version $Id: BaseResponseGenerator.java,v 1.3 2007/01/07 19:44:14 herrvendil Exp $
50  */

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 JavaDoc remoteIP = null;
62     
63     public BaseResponseGenerator(String JavaDoc 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 JavaDoc, CreateException JavaDoc, NamingException JavaDoc{
72         if(caadminsession == null){
73             Context JavaDoc context = new InitialContext JavaDoc();
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 JavaDoc, CreateException JavaDoc, NamingException JavaDoc{
82         if(raadminsession == null){
83           Context JavaDoc context = new InitialContext JavaDoc();
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 JavaDoc, CreateException JavaDoc, NamingException JavaDoc{
92         if(certificatestoresession == null){
93             Context JavaDoc context = new InitialContext JavaDoc();
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 JavaDoc, CreateException JavaDoc, NamingException JavaDoc{
102         if(signsession == null){
103             Context JavaDoc context = new InitialContext JavaDoc();
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 JavaDoc context = new InitialContext JavaDoc();
115                 usersession = ((IUserAdminSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup(
116                 "UserAdminSessionLocal"), IUserAdminSessionLocalHome.class)).create();
117             }
118         }catch(Exception JavaDoc e) {
119             log.error(intres.getLocalizedMessage("xkms.errorinitadminsession"));
120             throw new EJBException JavaDoc(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 JavaDoc context = new InitialContext JavaDoc();
131                 authsession = ((IAuthorizationSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup(
132                 "AuthorizationSessionLocal"), IAuthorizationSessionLocalHome.class)).create();
133             }
134         }catch(Exception JavaDoc e) {
135             log.error(intres.getLocalizedMessage("xkms.errorinitauthsession"));
136             throw new EJBException JavaDoc(e);
137         }
138         return authsession;
139     }
140     
141     private IKeyRecoverySessionLocal keyrecoverysession = null;
142     protected IKeyRecoverySessionLocal getKeyRecoverySession() {
143         try{
144             if(keyrecoverysession == null){
145                 Context JavaDoc context = new InitialContext JavaDoc();
146                 keyrecoverysession = ((IKeyRecoverySessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup(
147                 "KeyRecoverySessionLocal"), IKeyRecoverySessionLocalHome.class)).create();
148             }
149         }catch(Exception JavaDoc e) {
150             log.error(intres.getLocalizedMessage("xkms.errorinitkeyrecsession"));
151             throw new EJBException JavaDoc(e);
152         }
153         return keyrecoverysession;
154     }
155     
156     private IAuthenticationSessionLocal authenticationSession = null;
157     protected IAuthenticationSessionLocal getAuthenticationSession() {
158         try{
159             if(authenticationSession == null){
160                 Context JavaDoc context = new InitialContext JavaDoc();
161                 authenticationSession = ((IAuthenticationSessionLocalHome) javax.rmi.PortableRemoteObject.narrow(context.lookup(
162                 "AuthenticationSessionLocal"), IAuthenticationSessionLocalHome.class)).create();
163             }
164         }catch(Exception JavaDoc e) {
165             log.error(intres.getLocalizedMessage("xkms.errorinitauthentsession"));
166             throw new EJBException JavaDoc(e);
167         }
168         return authenticationSession;
169     }
170
171     
172 }
173
Popular Tags