📄 localpublishersessionbean.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.publisher;import java.security.cert.Certificate;import java.security.cert.X509Certificate;import java.util.Collection;import java.util.Date;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Random;import javax.ejb.CreateException;import javax.ejb.EJBException;import javax.ejb.FinderException;import org.ejbca.core.ejb.BaseSessionBean;import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal;import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocalHome;import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal;import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome;import org.ejbca.core.ejb.log.ILogSessionLocal;import org.ejbca.core.ejb.log.ILogSessionLocalHome;import org.ejbca.core.model.InternalResources;import org.ejbca.core.model.authorization.AuthorizationDeniedException;import org.ejbca.core.model.authorization.AvailableAccessRules;import org.ejbca.core.model.ca.publisher.BasePublisher;import org.ejbca.core.model.ca.publisher.PublisherConnectionException;import org.ejbca.core.model.ca.publisher.PublisherException;import org.ejbca.core.model.ca.publisher.PublisherExistsException;import org.ejbca.core.model.log.Admin;import org.ejbca.core.model.log.LogEntry;import org.ejbca.core.model.ra.ExtendedInformation;/** * Stores data used by web server clients. * Uses JNDI name for datasource as defined in env 'Datasource' in ejb-jar.xml. * * @ejb.bean description="Session bean handling interface with publisher data" * display-name="PublisherSessionSB" * name="PublisherSession" * jndi-name="PublisherSession" * local-jndi-name="PublisherSessionLocal" * view-type="both" * type="Stateless" * transaction-type="Container" * * @ejb.transaction type="Required" * * @weblogic.enable-call-by-reference True * * @ejb.env-entry name="DataSource" * type="java.lang.String" * value="${datasource.jndi-name-prefix}${datasource.jndi-name}" * * * @ejb.ejb-external-ref description="The Publisher entity bean" * view-type="local" * ref-name="ejb/PublisherDataLocal" * type="Entity" * home="org.ejbca.core.ejb.ca.publisher.PublisherDataLocalHome" * business="org.ejbca.core.ejb.ca.publisher.PublisherDataLocal" * link="PublisherData" * * @ejb.ejb-external-ref description="The Authorization Session Bean" * view-type="local" * ref-name="ejb/AuthorizationSessionLocal" * type="Session" * home="org.ejbca.core.ejb.authorization.IAuthorizationSessionLocalHome" * business="org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal" * link="AuthorizationSession" * * @ejb.ejb-external-ref description="The CAAdmin Session Bean" * view-type="local" * ref-name="ejb/CAAdminSessionLocal" * type="Session" * home="org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome" * business="org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal" * link="CAAdminSession" * * @ejb.ejb-external-ref description="The log session bean" * view-type="local" * ref-name="ejb/LogSessionLocal" * type="Session" * home="org.ejbca.core.ejb.log.ILogSessionLocalHome" * business="org.ejbca.core.ejb.log.ILogSessionLocal" * link="LogSession" * * @ejb.home extends="javax.ejb.EJBHome" * local-extends="javax.ejb.EJBLocalHome" * local-class="org.ejbca.core.ejb.ca.publisher.IPublisherSessionLocalHome" * remote-class="org.ejbca.core.ejb.ca.publisher.IPublisherSessionHome" * * @ejb.interface extends="javax.ejb.EJBObject" * local-extends="javax.ejb.EJBLocalObject" * local-class="org.ejbca.core.ejb.ca.publisher.IPublisherSessionLocal" * remote-class="org.ejbca.core.ejb.ca.publisher.IPublisherSessionRemote" * * @jonas.bean ejb-name="PublisherSession" */public class LocalPublisherSessionBean extends BaseSessionBean { /** Internal localization of logs and errors */ private static final InternalResources intres = InternalResources.getInstance(); /** * The local home interface of publisher entity bean. */ private PublisherDataLocalHome publisherhome = null; /** * The local interface of ca admin session bean */ private ICAAdminSessionLocal caadminsession = null; /** * The local interface of authorization session bean */ private IAuthorizationSessionLocal authorizationsession = null; /** * The remote interface of log session bean */ private ILogSessionLocal logsession = null; /** * Default create for SessionBean without any creation Arguments. * * @throws CreateException if bean instance can't be created */ public void ejbCreate() throws CreateException { publisherhome = (PublisherDataLocalHome) getLocator().getLocalHome(PublisherDataLocalHome.COMP_NAME); } /** * Gets connection to log session bean * * @return Connection */ private ILogSessionLocal getLogSession() { if (logsession == null) { try { ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME); logsession = logsessionhome.create(); } catch (CreateException e) { throw new EJBException(e); } } return logsession; } //getLogSession /** * Gets connection to authorization session bean * * @return IAuthorizationSessionLocal */ private IAuthorizationSessionLocal getAuthorizationSession() { if (authorizationsession == null) { try { IAuthorizationSessionLocalHome authorizationsessionhome = (IAuthorizationSessionLocalHome) getLocator().getLocalHome(IAuthorizationSessionLocalHome.COMP_NAME); authorizationsession = authorizationsessionhome.create(); } catch (CreateException e) { throw new EJBException(e); } } return authorizationsession; } //getAuthorizationSession /** * Gets connection to caadmin session bean * * @return ICAAdminSessionLocal */ private ICAAdminSessionLocal getCAAdminSession() { if (caadminsession == null) { try { ICAAdminSessionLocalHome caadminsessionhome = (ICAAdminSessionLocalHome) getLocator().getLocalHome(ICAAdminSessionLocalHome.COMP_NAME); caadminsession = caadminsessionhome.create(); } catch (CreateException e) { throw new EJBException(e); } } return caadminsession; } //getCAAdminSession /** * Stores the certificate to the given collection of publishers. * See BasePublisher class for further documentation about function * * @param publisherids a Collection (Integer) of publisherids. * @return true if sucessfull result on all given publishers * @ejb.interface-method view-type="both" * @see org.ejbca.core.model.ca.publisher.BasePublisher */ public boolean storeCertificate(Admin admin, Collection publisherids, Certificate incert, String username, String password, String cafp, int status, int type, long revocationDate, int revocationReason, ExtendedInformation extendedinformation) { Iterator iter = publisherids.iterator(); boolean returnval = true; while (iter.hasNext()) { Integer id = (Integer) iter.next(); try { PublisherDataLocal pdl = publisherhome.findByPrimaryKey(id); try { returnval &= pdl.getPublisher().storeCertificate(admin, incert, username, password, cafp, status, type, revocationDate, revocationReason, extendedinformation); String msg = intres.getLocalizedMessage("publisher.store", ((X509Certificate) incert).getSubjectDN().toString(), pdl.getName()); getLogSession().log(admin, (X509Certificate) incert, LogEntry.MODULE_CA, new java.util.Date(), username, (X509Certificate) incert, LogEntry.EVENT_INFO_STORECERTIFICATE, msg); } catch (PublisherException pe) { String msg = intres.getLocalizedMessage("publisher.errorstore", pdl.getName()); getLogSession().log(admin, (X509Certificate) incert, LogEntry.MODULE_CA, new java.util.Date(), username, (X509Certificate) incert, LogEntry.EVENT_ERROR_STORECERTIFICATE, msg, pe); } } catch (FinderException fe) { String msg = intres.getLocalizedMessage("publisher.nopublisher", id); getLogSession().log(admin, (X509Certificate) incert, LogEntry.MODULE_CA, new java.util.Date(), null, (X509Certificate) incert, LogEntry.EVENT_ERROR_STORECERTIFICATE, msg); } } return returnval; } /** * Stores the crl to the given collection of publishers. * See BasePublisher class for further documentation about function * * @param publisherids a Collection (Integer) of publisherids. * @return true if sucessfull result on all given publishers * @ejb.interface-method view-type="both" * @see org.ejbca.core.model.ca.publisher.BasePublisher */ public boolean storeCRL(Admin admin, Collection publisherids, byte[] incrl, String cafp, int number) { Iterator iter = publisherids.iterator(); boolean returnval = true; while (iter.hasNext()) { Integer id = (Integer) iter.next(); try { PublisherDataLocal pdl = publisherhome.findByPrimaryKey(id); try { returnval &= pdl.getPublisher().storeCRL(admin, incrl, cafp, number); String msg = intres.getLocalizedMessage("publisher.store", "CRL", pdl.getName()); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_STORECRL, msg); } catch (PublisherException pe) { String msg = intres.getLocalizedMessage("publisher.errorstorecert", pdl.getName()); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_STORECRL, msg, pe); } } catch (FinderException fe) { String msg = intres.getLocalizedMessage("publisher.nopublisher", id); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_STORECRL, msg); } } return returnval; } /** * Revokes the certificate in the given collection of publishers. * See BasePublisher class for further documentation about function * * @param publisherids a Collection (Integer) of publisherids. * @ejb.interface-method view-type="both" * @see org.ejbca.core.model.ca.publisher.BasePublisher */ public void revokeCertificate(Admin admin, Collection publisherids, Certificate cert, int reason) { Iterator iter = publisherids.iterator(); while (iter.hasNext()) { Integer id = (Integer) iter.next(); try { PublisherDataLocal pdl = publisherhome.findByPrimaryKey(id); try { pdl.getPublisher().revokeCertificate(admin, cert, reason); String msg = intres.getLocalizedMessage("publisher.store", ((X509Certificate) cert).getSubjectDN().toString(), pdl.getName()); getLogSession().log(admin, (X509Certificate) cert, LogEntry.MODULE_CA, new java.util.Date(), null, (X509Certificate) cert, LogEntry.EVENT_INFO_REVOKEDCERT, msg); } catch (PublisherException pe) { String msg = intres.getLocalizedMessage("publisher.errorstore", pdl.getName()); getLogSession().log(admin, (X509Certificate) cert, LogEntry.MODULE_CA, new java.util.Date(), null, (X509Certificate) cert, LogEntry.EVENT_ERROR_REVOKEDCERT, msg, pe); } } catch (FinderException fe) { String msg = intres.getLocalizedMessage("publisher.nopublisher", id); getLogSession().log(admin, (X509Certificate) cert, LogEntry.MODULE_CA, new java.util.Date(), null, (X509Certificate) cert, LogEntry.EVENT_ERROR_REVOKEDCERT, msg); } } } /** * Test the connection to of a publisher * * @param publisherid the id of the publisher to test. * @ejb.interface-method view-type="both" * @see org.ejbca.core.model.ca.publisher.BasePublisher */ public void testConnection(Admin admin, int publisherid) throws PublisherConnectionException { debug(">testConnection(id: " + publisherid + ")"); try { PublisherDataLocal pdl = publisherhome.findByPrimaryKey(new Integer(publisherid)); try { pdl.getPublisher().testConnection(admin); String msg = intres.getLocalizedMessage("publisher.testedpublisher", pdl.getName()); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, msg); } catch (PublisherConnectionException pe) { String msg = intres.getLocalizedMessage("publisher.errortestpublisher", pdl.getName()); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, msg, pe); throw new PublisherConnectionException(pe.getMessage()); } } catch (FinderException fe) { String msg = intres.getLocalizedMessage("publisher.nopublisher", new Integer(publisherid)); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, msg); } debug("<testConnection(id: " + publisherid + ")"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -