📄 localcertificatestoreonlydatasessionbean.java
字号:
/************************************************************************* * * * EJBCA: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/package org.ejbca.core.ejb.ca.store;import java.math.BigInteger;import java.security.cert.Certificate;import java.security.cert.X509Certificate;import java.util.Collection;import java.util.Date;import javax.ejb.CreateException;import org.apache.commons.lang.StringUtils;import org.apache.log4j.Logger;import org.ejbca.core.ejb.BaseSessionBean;import org.ejbca.core.ejb.protect.TableProtectSessionLocalHome;import org.ejbca.core.model.ca.crl.RevokedCertInfo;import org.ejbca.core.model.log.Admin;import org.ejbca.util.CertTools;/** * Stores certificate and CRL in the local database using Certificate and CRL Entity Beans. * Uses JNDI name for datasource as defined in env 'Datasource' in ejb-jar.xml. * * @ejb.bean display-name="CertificateStoreOnlyDataSB" * name="CertificateStoreOnlyDataSession" * jndi-name="CertificateStoreOnlyDataSession" * view-type="both" * type="Stateless" * transaction-type="Container" * * @ejb.transaction type="Supports" * * @weblogic.enable-call-by-reference True * * @ejb.env-entry description="JDBC datasource to be used" * name="DataSource" * type="java.lang.String" * value="${datasource.jndi-name-prefix}${datasource.jndi-name}" * * @ejb.env-entry description="Enable or disable protection of database entrys" * name="certSigning" * type="java.lang.String" * value="${protection.certprotect}" * * @ejb.ejb-external-ref description="The Certificate entity bean used to store and fetch certificates" * view-type="local" * ref-name="ejb/CertificateDataLocal" * type="Entity" * home="org.ejbca.core.ejb.ca.store.CertificateDataLocalHome" * business="org.ejbca.core.ejb.ca.store.CertificateDataLocal" * link="CertificateData" * * @ejb.ejb-external-ref * description="The table protection session bean" * view-type="local" * ref-name="ejb/TableProtectSessionLocal" * type="Session" * home="org.ejbca.core.ejb.protect.TableProtectSessionLocalHome" * business="org.ejbca.core.ejb.protect.TableProtectSessionLocal" * link="TableProtectSession" * * @ejb.home extends="javax.ejb.EJBHome" * local-extends="javax.ejb.EJBLocalHome" * local-class="org.ejbca.core.ejb.ca.store.ICertificateStoreOnlyDataSessionLocalHome" * remote-class="org.ejbca.core.ejb.ca.store.ICertificateStoreOnlyDataSessionHome" * * @ejb.interface extends="javax.ejb.EJBObject" * local-extends="javax.ejb.EJBLocalObject" * local-class="org.ejbca.core.ejb.ca.store.ICertificateStoreOnlyDataSessionLocal" * remote-class="org.ejbca.core.ejb.ca.store.ICertificateStoreOnlyDataSessionRemote" * * @version $Id: LocalCertificateStoreOnlyDataSessionBean.java,v 1.9 2006/12/10 16:19:59 anatom Exp $ */public class LocalCertificateStoreOnlyDataSessionBean extends BaseSessionBean { /** * The home interface of Certificate entity bean */ private CertificateDataLocalHome certHome = null; private final CertificateDataUtil.Adapter adapter; /** The come interface of the protection session bean */ private TableProtectSessionLocalHome protecthome = null; public LocalCertificateStoreOnlyDataSessionBean() { super(); CertTools.installBCProvider(); adapter = new MyAdapter(); } /** * Checks if a certificate is revoked. * * @param admin Administrator performing the operation * @param issuerDN the DN of the issuer. * @param serno the serialnumber of the certificate that will be checked * @return RevokedCertInfo with revocation information, with reason RevokedCertInfo.NOT_REVOKED if NOT revoked. Returns null if certificate is not found. * @ejb.interface-method */ public RevokedCertInfo isRevoked(Admin admin, String issuerDN, BigInteger serno) { return CertificateDataUtil.isRevoked(admin, issuerDN, serno, certHome, protecthome, adapter); } //isRevoked /** * Finds a certificate specified by issuer DN and serial number. * * @param admin Administrator performing the operation * @param issuerDN issuer DN of the desired certificate. * @param serno serial number of the desired certificate! * @return Certificate if found or null * @ejb.interface-method */ public Certificate findCertificateByIssuerAndSerno(Admin admin, String issuerDN, BigInteger serno) { return CertificateDataUtil.findCertificateByIssuerAndSerno(admin, issuerDN, serno, certHome, adapter); } //findCertificateByIssuerAndSerno /** * Lists all active (status = 20) certificates of a specific type and if * given from a specific issuer. * <p/> * The type is the bitwise OR value of the types listed * int {@link org.ejbca.core.ejb.ca.store.CertificateDataBean}:<br> * <ul> * <li><tt>CERTTYPE_ENDENTITY</tt><br> * An user or machine certificate, which identifies a subject. * </li> * <li><tt>CERTTYPE_CA</tt><br> * A CA certificate which is <b>not</b> a root CA. * </li> * <li><tt>CERTTYPE_ROOTCA</tt><br> * A Root CA certificate. * </li> * </ul> * <p/> * Usage examples:<br> * <ol> * <li>Get all root CA certificates * <p/> * <code> * ... * ICertificateStoreOnlyDataSessionRemote itf = ... * Collection certs = itf.findCertificatesByType(adm, * CertificateDataBean.CERTTYPE_ROOTCA, * null); * ... * </code> * </li> * <li>Get all subordinate CA certificates for a specific * Root CA. It is assumed that the <tt>subjectDN</tt> of the * Root CA certificate is located in the variable <tt>issuer</tt>. * <p/> * <code> * ... * ICertificateStoreOnlyDataSessionRemote itf = ... * Certficate rootCA = ... * String issuer = rootCA.getSubjectDN(); * Collection certs = itf.findCertificatesByType(adm, * CertificateDataBean.CERTTYPE_SUBCA, * issuer); * ... * </code> * </li> * <li>Get <b>all</b> CA certificates. * <p/> * <code> * ... * ICertificateStoreOnlyDataSessionRemote itf = ... * Collection certs = itf.findCertificatesByType(adm, * CertificateDataBean.CERTTYPE_SUBCA * + CERTTYPE_ROOTCA, * null); * ... * </code> * </li> * </ol> * * @param admin * @param issuerDN get all certificates issued by a specific issuer. * If <tt>null</tt> or empty return certificates regardless of * the issuer. * @param type CERTTYPE_* types from CertificateDataBean * @return Collection Collection of X509Certificate, never <tt>null</tt> * @ejb.interface-method */ public Collection findCertificatesByType(Admin admin, int type, String issuerDN) { return CertificateDataUtil.findCertificatesByType(admin, type, issuerDN, certHome, adapter); } // findCertificatesByType private class MyAdapter implements CertificateDataUtil.Adapter { /* (non-Javadoc) * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#getLogger() */ public Logger getLogger() { return log; } /* (non-Javadoc) * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#log(org.ejbca.core.model.log.Admin, int, int, java.util.Date, java.lang.String, java.security.cert.X509Certificate, int, java.lang.String) */ public void log(Admin admin, int caid, int module, Date time, String username, X509Certificate certificate, int event, String comment) { // no log bean available } /* (non-Javadoc) * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#debug(java.lang.String) */ public void debug(String s) { LocalCertificateStoreOnlyDataSessionBean.this.debug(s); } /* (non-Javadoc) * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#error(java.lang.String) */ public void error(String s) { LocalCertificateStoreOnlyDataSessionBean.this.error(s); } /* (non-Javadoc) * @see org.ejbca.core.ejb.ca.store.CertificateDataUtil.Adapter#error(java.lang.String) */ public void error(String s, Exception e) { LocalCertificateStoreOnlyDataSessionBean.this.error(s, e); } } /** * Default create for SessionBean without any creation Arguments. * * @throws CreateException if bean instance can't be created */ public void ejbCreate() { certHome = (CertificateDataLocalHome) getLocator().getLocalHome(CertificateDataLocalHome.COMP_NAME); String sign = getLocator().getString("java:comp/env/certSigning"); if (StringUtils.equalsIgnoreCase(sign, "true")) { protecthome = (TableProtectSessionLocalHome) getLocator().getLocalHome(TableProtectSessionLocalHome.COMP_NAME); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -