KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > protocol > OCSPServlet


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.ui.web.protocol;
15
16 import java.math.BigInteger JavaDoc;
17 import java.security.cert.Certificate JavaDoc;
18 import java.util.Collection JavaDoc;
19
20 import javax.ejb.EJBException JavaDoc;
21 import javax.servlet.ServletConfig JavaDoc;
22 import javax.servlet.ServletException JavaDoc;
23
24 import org.ejbca.core.ejb.ServiceLocator;
25 import org.ejbca.core.ejb.ca.sign.ISignSessionLocal;
26 import org.ejbca.core.ejb.ca.sign.ISignSessionLocalHome;
27 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal;
28 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocalHome;
29 import org.ejbca.core.model.ca.caadmin.CADoesntExistsException;
30 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceNotActiveException;
31 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceRequestException;
32 import org.ejbca.core.model.ca.caadmin.extendedcaservices.IllegalExtendedCAServiceRequestException;
33 import org.ejbca.core.model.ca.caadmin.extendedcaservices.OCSPCAServiceRequest;
34 import org.ejbca.core.model.ca.caadmin.extendedcaservices.OCSPCAServiceResponse;
35 import org.ejbca.core.model.ca.crl.RevokedCertInfo;
36 import org.ejbca.core.model.log.Admin;
37
38 /**
39  * Servlet implementing server side of the Online Certificate Status Protocol (OCSP)
40  * For a detailed description of OCSP refer to RFC2560.
41  *
42  * @web.servlet name = "OCSP"
43  * display-name = "OCSPServlet"
44  * description="Answers OCSP requests"
45  * load-on-startup = "99"
46  *
47  * @web.servlet-mapping url-pattern = "/ocsp"
48  *
49  * @web.ejb-local-ref
50  * name="ejb/CertificateStoreSessionLocal"
51  * type="Session"
52  * link="CertificateStoreSession"
53  * home="org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocalHome"
54  * local="org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal"
55  *
56  * @web.ejb-local-ref
57  * name="ejb/RSASignSessionLocal"
58  * type="Session"
59  * link="RSASignSession"
60  * home="org.ejbca.core.ejb.ca.sign.ISignSessionLocalHome"
61  * local="org.ejbca.core.ejb.ca.sign.ISignSessionLocal"
62  *
63  * @web.ejb-local-ref
64  * name="ejb/CAAdminSessionLocal"
65  * type="Session"
66  * link="CAAdminSession"
67  * home="org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome"
68  * local="org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal"
69  *
70  * @web.resource-ref
71  * name="${datasource.jndi-name-prefix}${datasource.jndi-name}"
72  * type="javax.sql.DataSource"
73  * auth="Container"
74  *
75  * @author Thomas Meckel (Ophios GmbH), Tomas Gustavsson, Lars Silven
76  * @version $Id: OCSPServlet.java,v 1.10 2007/01/09 12:47:44 anatom Exp $
77  */

78 public class OCSPServlet extends OCSPServletBase {
79
80     private ICertificateStoreSessionLocal m_certStore = null;
81     private ISignSessionLocal m_signsession = null;
82     
83     public void init(ServletConfig JavaDoc config)
84             throws ServletException JavaDoc {
85         super.init(config);
86     }
87     
88     private synchronized ICertificateStoreSessionLocal getStoreSession(){
89         if(m_certStore == null){
90             try {
91                 ICertificateStoreSessionLocalHome storehome = (ICertificateStoreSessionLocalHome)ServiceLocator.getInstance().getLocalHome(ICertificateStoreSessionLocalHome.COMP_NAME);
92                 m_certStore = storehome.create();
93             }catch(Exception JavaDoc e){
94                 throw new EJBException JavaDoc(e);
95             }
96         }
97         return m_certStore;
98     }
99     
100     private synchronized ISignSessionLocal getSignSession(){
101         if(m_signsession == null){
102             try {
103                 ISignSessionLocalHome signhome = (ISignSessionLocalHome)ServiceLocator.getInstance().getLocalHome(ISignSessionLocalHome.COMP_NAME);
104                 m_signsession = signhome.create();
105             }catch(Exception JavaDoc e){
106                 throw new EJBException JavaDoc(e);
107             }
108         }
109         return m_signsession;
110     }
111
112     protected Collection JavaDoc findCertificatesByType(Admin adm, int i, String JavaDoc issuerDN) {
113         return getStoreSession().findCertificatesByType(adm, i, issuerDN);
114     }
115
116     protected Certificate JavaDoc findCertificateByIssuerAndSerno(Admin adm, String JavaDoc issuer, BigInteger JavaDoc serno) {
117         return getStoreSession().findCertificateByIssuerAndSerno(adm, issuer, serno);
118     }
119     
120     protected OCSPCAServiceResponse extendedService(Admin adm, int caid, OCSPCAServiceRequest request) throws CADoesntExistsException, ExtendedCAServiceRequestException, IllegalExtendedCAServiceRequestException, ExtendedCAServiceNotActiveException {
121         return (OCSPCAServiceResponse)getSignSession().extendedService(adm, caid, request);
122     }
123
124     protected RevokedCertInfo isRevoked(Admin adm, String JavaDoc name, BigInteger JavaDoc serialNumber) {
125         return getStoreSession().isRevoked(adm, name, serialNumber);
126     }
127
128     protected void loadPrivateKeys(Admin adm) {
129         // not used by this servlet
130
}
131 } // OCSPServlet
132
Popular Tags