⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localcertificatestoresessionbean.java

📁 JAVA做的J2EE下CA认证系统 基于EJB开发
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/************************************************************************* *                                                                       * *  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 se.anatom.ejbca.ca.store;import java.math.BigInteger;import java.security.cert.Certificate;import java.security.cert.X509CRL;import java.security.cert.X509Certificate;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.ArrayList;import java.util.Collection;import java.util.Date;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Random;import javax.ejb.CreateException;import javax.ejb.EJBException;import javax.ejb.FinderException;import se.anatom.ejbca.BaseSessionBean;import se.anatom.ejbca.JNDINames;import se.anatom.ejbca.SecConst;import se.anatom.ejbca.authorization.AuthorizationDeniedException;import se.anatom.ejbca.authorization.IAuthorizationSessionLocal;import se.anatom.ejbca.authorization.IAuthorizationSessionLocalHome;import se.anatom.ejbca.ca.crl.RevokedCertInfo;import se.anatom.ejbca.ca.exception.CertificateProfileExistsException;import se.anatom.ejbca.ca.publisher.IPublisherSessionLocal;import se.anatom.ejbca.ca.publisher.IPublisherSessionLocalHome;import se.anatom.ejbca.ca.store.certificateprofiles.CACertificateProfile;import se.anatom.ejbca.ca.store.certificateprofiles.CertificateProfile;import se.anatom.ejbca.ca.store.certificateprofiles.EndUserCertificateProfile;import se.anatom.ejbca.ca.store.certificateprofiles.HardTokenAuthCertificateProfile;import se.anatom.ejbca.ca.store.certificateprofiles.HardTokenAuthEncCertificateProfile;import se.anatom.ejbca.ca.store.certificateprofiles.HardTokenEncCertificateProfile;import se.anatom.ejbca.ca.store.certificateprofiles.HardTokenSignCertificateProfile;import se.anatom.ejbca.ca.store.certificateprofiles.RootCACertificateProfile;import se.anatom.ejbca.common.UserDataVO;import se.anatom.ejbca.log.Admin;import se.anatom.ejbca.log.ILogSessionLocal;import se.anatom.ejbca.log.ILogSessionLocalHome;import se.anatom.ejbca.log.LogConstants;import se.anatom.ejbca.log.LogEntry;import se.anatom.ejbca.util.CertTools;import se.anatom.ejbca.util.JDBCUtil;import se.anatom.ejbca.util.StringTools;/** * 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. * * @version $Id: LocalCertificateStoreSessionBean.java,v 1.84.2.1 2005/11/17 20:39:28 herrvendil Exp $ * @ejb.bean display-name="CertificateStoreSB" * name="CertificateStoreSession" * view-type="both" * type="Stateless" * transaction-type="Container" * * @ejb.transaction type="Supports" * @ejb.security-identity run-as="InternalUser" * @ejb.permission role-name="InternalUser" * * @ejb.env-entry description="JDBC datasource to be used" * name="DataSource" * type="java.lang.String" * value="java:/${datasource.jndi-name}" * * @ejb.ejb-external-ref description="The Certificate entity bean used to store and fetch certificates" * view-type="local" * ejb-name="CertificateDataLocal" * type="Entity" * home="se.anatom.ejbca.ca.store.CertificateDataLocalHome" * business="se.anatom.ejbca.ca.store.CertificateDataLocal" * link="CertificateData" * * @ejb.ejb-external-ref description="The CRL entity bean used to store and fetch CRLs" * view-type="local" * ejb-name="CRLDataLocal" * type="Entity" * home="se.anatom.ejbca.ca.store.CRLDataLocalHome" * business="se.anatom.ejbca.ca.store.CRLDataLocal" * link="CRLData" * * @ejb.ejb-external-ref description="The CertReqHistoryData Entity bean" * view-type="local" * ejb-name="CertReqHistoryDataLocal" * type="Entity" * home="se.anatom.ejbca.ca.store.CertReqHistoryDataLocalHome" * business="se.anatom.ejbca.ca.store.CertReqHistoryDataLocal" * link="CertReqHistoryData" * * @ejb.ejb-external-ref description="The CertificateProfileData Entity bean" * view-type="local" * ejb-name="CertificateProfileDataLocal" * type="Entity" * home="se.anatom.ejbca.ca.store.CertificateProfileDataLocalHome" * business="se.anatom.ejbca.ca.store.CertificateProfileDataLocal" * link="CertificateProfileData" *  * @ejb.ejb-external-ref description="The Log session bean" * view-type="local" * ejb-name="LogSessionLocal" * type="Session" * home="se.anatom.ejbca.log.ILogSessionLocalHome" * business="se.anatom.ejbca.log.ILogSessionLocal" * link="LogSession" * * @ejb.ejb-external-ref description="The Authorization session bean" * view-type="local" * ejb-name="AuthorizationSessionLocal" * type="Session" * home="se.anatom.ejbca.authorization.IAuthorizationSessionLocalHome" * business="se.anatom.ejbca.authorization.IAuthorizationSessionLocal" * link="AuthorizationSession" * * @ejb.ejb-external-ref description="Publishers are configured to store certificates and CRLs in additional places from the main database. * Publishers runs as local beans" * view-type="local" * ejb-name="PublisherSessionLocal" * type="Session" * home="se.anatom.ejbca.ca.publisher.IPublisherSessionLocalHome" * business="se.anatom.ejbca.ca.publisher.IPublisherSessionLocal" * link="PublisherSession" * * @ejb.home extends="javax.ejb.EJBHome" * local-extends="javax.ejb.EJBLocalHome" * local-class="se.anatom.ejbca.ca.store.ICertificateStoreSessionLocalHome" * remote-class="se.anatom.ejbca.ca.store.ICertificateStoreSessionHome" * * @ejb.interface extends="javax.ejb.EJBObject" * local-extends="javax.ejb.EJBLocalObject" * local-class="se.anatom.ejbca.ca.store.ICertificateStoreSessionLocal" * remote-class="se.anatom.ejbca.ca.store.ICertificateStoreSessionRemote" */public class LocalCertificateStoreSessionBean extends BaseSessionBean {    /**     * The home interface of Certificate entity bean     */    private CertificateDataLocalHome certHome = null;    /**     * The home interface of Certificate Type entity bean     */    private CertificateProfileDataLocalHome certprofilehome = null;    /**     * The home interface of CRL entity bean     */    private CRLDataLocalHome crlHome = null;        /**     * The home interface of CRL entity bean     */    private CertReqHistoryDataLocalHome certReqHistoryHome = null;        /**     * The local interface of the log session bean     */    private ILogSessionLocal logsession = null;    /**     * The local interface of the authorization session bean     */    private IAuthorizationSessionLocal authorizationsession = null;    /**     * The local interface of the publisher session bean     */    private IPublisherSessionLocal publishersession = null;    /**     * Default create for SessionBean without any creation Arguments.     *     * @throws CreateException if bean instance can't be created     */    public void ejbCreate() throws CreateException {        crlHome = (CRLDataLocalHome) getLocator().getLocalHome(CRLDataLocalHome.COMP_NAME);        certHome = (CertificateDataLocalHome) getLocator().getLocalHome(CertificateDataLocalHome.COMP_NAME);        certReqHistoryHome = (CertReqHistoryDataLocalHome) getLocator().getLocalHome(CertReqHistoryDataLocalHome.COMP_NAME);        certprofilehome = (CertificateProfileDataLocalHome) getLocator().getLocalHome(CertificateProfileDataLocalHome.COMP_NAME);    }    /**     * Gets connection to log session bean     */    private ILogSessionLocal getLogSession() {        if (logsession == null) {            try {                ILogSessionLocalHome home = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME);                logsession = home.create();            } catch (Exception e) {                throw new EJBException(e);            }        }        return logsession;    } //getLogSession    /**     * Gets connection to authorization session bean     *     * @return Connection     */    private IAuthorizationSessionLocal getAuthorizationSession() {        if (authorizationsession == null) {            try {                IAuthorizationSessionLocalHome home = (IAuthorizationSessionLocalHome) getLocator().getLocalHome(IAuthorizationSessionLocalHome.COMP_NAME);                authorizationsession = home.create();            } catch (Exception e) {                throw new EJBException(e);            }        }        return authorizationsession;    } //getAuthorizationSession    /**     * Gets connection to publisher session bean     *     * @return Connection     */    private IPublisherSessionLocal getPublisherSession() {        if (publishersession == null) {            try {                IPublisherSessionLocalHome home = (IPublisherSessionLocalHome) getLocator().getLocalHome(IPublisherSessionLocalHome.COMP_NAME);                publishersession = home.create();            } catch (Exception e) {                throw new EJBException(e);            }        }        return publishersession;    } //getPublisherSession    /**     * Stores a certificate.     *     * @param incert   The certificate to be stored.     * @param cafp     Fingerprint (hex) of the CAs certificate.     * @param username username of end entity owning the certificate.     * @param status   Status of the certificate (from CertificateData).     * @param type     Type of certificate (CERTTYPE_ENDENTITY etc from CertificateDataBean).     * @return true if storage was successful.     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public boolean storeCertificate(Admin admin, Certificate incert, String username, String cafp,                                    int status, int type) {        debug(">storeCertificate(" + cafp + ", " + status + ", " + type + ")");        try {            // Strip dangerous chars            username = StringTools.strip(username);            X509Certificate cert = (X509Certificate) incert;            CertificateDataPK pk = new CertificateDataPK();            pk.fingerprint = CertTools.getFingerprintAsString(cert);                        CertificateDataLocal data1 = null;            data1 = certHome.create(cert);            data1.setUsername(username);            data1.setCAFingerprint(cafp);            data1.setStatus(status);            data1.setType(type);            getLogSession().log(admin, cert, LogEntry.MODULE_CA, new java.util.Date(), username, (X509Certificate) incert, LogEntry.EVENT_INFO_STORECERTIFICATE, "");        } catch (Exception e) {            getLogSession().log(admin, (X509Certificate) incert, LogEntry.MODULE_CA, new java.util.Date(), username, (X509Certificate) incert, LogEntry.EVENT_ERROR_STORECERTIFICATE, "");            throw new EJBException(e);        }        debug("<storeCertificate()");        return true;    } // storeCertificate    /**     * Stores a CRL     *     * @param incrl  The DER coded CRL to be stored.     * @param cafp   Fingerprint (hex) of the CAs certificate.     * @param number CRL number.     * @return true if storage was successful.     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public boolean storeCRL(Admin admin, byte[] incrl, String cafp, int number) {        debug(">storeCRL(" + cafp + ", " + number + ")");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -