📄 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 se.anatom.ejbca.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 se.anatom.ejbca.BaseSessionBean;import se.anatom.ejbca.authorization.AuthorizationDeniedException;import se.anatom.ejbca.authorization.AvailableAccessRules;import se.anatom.ejbca.authorization.IAuthorizationSessionLocal;import se.anatom.ejbca.authorization.IAuthorizationSessionLocalHome;import se.anatom.ejbca.ca.caadmin.ICAAdminSessionLocal;import se.anatom.ejbca.ca.caadmin.ICAAdminSessionLocalHome;import se.anatom.ejbca.ca.exception.PublisherConnectionException;import se.anatom.ejbca.ca.exception.PublisherException;import se.anatom.ejbca.ca.exception.PublisherExistsException;import se.anatom.ejbca.log.Admin;import se.anatom.ejbca.log.ILogSessionLocal;import se.anatom.ejbca.log.ILogSessionLocalHome;import se.anatom.ejbca.log.LogEntry;import se.anatom.ejbca.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 ra authorization" * display-name="PublisherSessionSB" * name="PublisherSession" * jndi-name="PublisherSession" * local-jndi-name="PublisherSessionLocal" * view-type="both" * type="Stateless" * transaction-type="Container" * * @ejb.transaction type="Required" * * @ejb.permission role-name="InternalUser" * * @ejb.env-entry name="DataSource" * type="java.lang.String" * value="java:/${datasource.jndi-name}" * * @ejb.env-entry description="Custom Available Access Rules, use ';' to separate multiple accessrules" * name="CustomAvailableAccessRules" * type="java.lang.String" * value="" * * @ejb.ejb-ref view-type="local" * ejb-name="PublisherData" * ref-name="ejb/PublisherDataLocal" * * @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="The CAAdmin Session Bean" * view-type="local" * ejb-name="CAAdminSessionLocal" * type="Session" * home="se.anatom.ejbca.ca.caadmin.ICAAdminSessionLocalHome" * business="se.anatom.ejbca.ca.caadmin.ICAAdminSessionLocal" * link="CAAdminSession" * * @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.home extends="javax.ejb.EJBHome" * local-extends="javax.ejb.EJBLocalHome" * local-class="se.anatom.ejbca.ca.publisher.IPublisherSessionLocalHome" * remote-class="se.anatom.ejbca.ca.publisher.IPublisherSessionHome" * * @ejb.interface extends="javax.ejb.EJBObject" * local-extends="javax.ejb.EJBLocalObject" * local-class="se.anatom.ejbca.ca.publisher.IPublisherSessionLocal" * remote-class="se.anatom.ejbca.ca.publisher.IPublisherSessionRemote" * * @jonas.bean ejb-name="PublisherSession" */public class LocalPublisherSessionBean extends BaseSessionBean { /** * 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 se.anatom.ejbca.ca.publisher.BasePublisher */ public boolean storeCertificate(Admin admin, Collection publisherids, Certificate incert, String username, String password, String cafp, int status, int type, 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, extendedinformation); getLogSession().log(admin, (X509Certificate) incert, LogEntry.MODULE_CA, new java.util.Date(), username, (X509Certificate) incert, LogEntry.EVENT_INFO_STORECERTIFICATE, "Added object: " + ((X509Certificate) incert).getSubjectDN().toString() + " successfully to publisher " + pdl.getName() + "."); } catch (PublisherException pe) { getLogSession().log(admin, (X509Certificate) incert, LogEntry.MODULE_CA, new java.util.Date(), username, (X509Certificate) incert, LogEntry.EVENT_ERROR_STORECERTIFICATE, "Error when publishing certificate to " + pdl.getName() + " : " + pe.getMessage()); } } catch (FinderException fe) { getLogSession().log(admin, (X509Certificate) incert, LogEntry.MODULE_CA, new java.util.Date(), null, (X509Certificate) incert, LogEntry.EVENT_ERROR_STORECERTIFICATE, "Publisher with id " + id + " doesn't exist."); } } 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 se.anatom.ejbca.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); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_STORECRL, "Published CRL successfully to publisher " + pdl.getName() + "."); } catch (PublisherException pe) { getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_STORECRL, "Error when publishing CRL to " + pdl.getName() + " : " + pe.getMessage()); } } catch (FinderException fe) { getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_STORECRL, "Publisher with id " + id + " doesn't exist."); } } 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 se.anatom.ejbca.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); getLogSession().log(admin, (X509Certificate) cert, LogEntry.MODULE_CA, new java.util.Date(), null, (X509Certificate) cert, LogEntry.EVENT_INFO_REVOKEDCERT, "Revoked certificate: " + ((X509Certificate) cert).getSubjectDN().toString() + " successfully in publisher " + pdl.getName() + "."); } catch (PublisherException pe) { getLogSession().log(admin, (X509Certificate) cert, LogEntry.MODULE_CA, new java.util.Date(), null, (X509Certificate) cert, LogEntry.EVENT_ERROR_REVOKEDCERT, "Error when revoking certificate in publisher " + pdl.getName() + " : " + pe.getMessage()); } } catch (FinderException fe) { getLogSession().log(admin, (X509Certificate) cert, LogEntry.MODULE_CA, new java.util.Date(), null, (X509Certificate) cert, LogEntry.EVENT_ERROR_REVOKEDCERT, "Publisher with id " + id + " doesn't exist."); } } } /** * Test the connection to of a publisher * * @param publisherid the id of the publisher to test. * @ejb.interface-method view-type="both" * @see se.anatom.ejbca.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); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, "Successfully tested the connection with publisher " + pdl.getName() + "."); } catch (PublisherConnectionException pe) { getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, "Error when testing the connection with publisher " + pdl.getName() + " : " + pe.getMessage()); throw new PublisherConnectionException(pe.getMessage()); } } catch (FinderException fe) { getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, "Publisher with id " + publisherid + " doesn't exist."); } debug("<testConnection(id: " + publisherid + ")"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -