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

📄 localuserdatasourcesessionbean.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/************************************************************************* *                                                                       * *  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.ra.userdatasource;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.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.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.log.Admin;import org.ejbca.core.model.log.LogEntry;import org.ejbca.core.model.ra.userdatasource.BaseUserDataSource;import org.ejbca.core.model.ra.userdatasource.UserDataSourceConnectionException;import org.ejbca.core.model.ra.userdatasource.UserDataSourceException;import org.ejbca.core.model.ra.userdatasource.UserDataSourceExistsException;/** * 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 user data sources" *   display-name="UserDataSourceSessionSB" *   name="UserDataSourceSession" *   jndi-name="UserDataSourceSession" *   local-jndi-name="UserDataSourceSessionLocal" *   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 UserDataSource entity bean" *   view-type="local" *   ref-name="ejb/UserDataSourceDataLocal" *   type="Entity" *   home="org.ejbca.core.ejb.ra.userdatasource.UserDataSourceDataLocalHome" *   business="org.ejbca.core.ejb.ra.userdatasource.UserDataSourceDataLocal" *   link="UserDataSourceData" * * @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 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.ra.userdatasource.IUserDataSourceSessionLocalHome" *   remote-class="org.ejbca.core.ejb.ra.userdatasource.IUserDataSourceSessionHome" * * @ejb.interface extends="javax.ejb.EJBObject" *   local-extends="javax.ejb.EJBLocalObject" *   local-class="org.ejbca.core.ejb.ra.userdatasource.IUserDataSourceSessionLocal" *   remote-class="org.ejbca.core.ejb.ra.userdatasource.IUserDataSourceSessionRemote" * *  @jonas.bean ejb-name="UserDataSourceSession" */public class LocalUserDataSourceSessionBean extends BaseSessionBean {    /** Internal localization of logs and errors */    private static final InternalResources intres = InternalResources.getInstance();        /**     * The local home interface of user data source entity bean.     */    private UserDataSourceDataLocalHome userdatasourcehome = 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 {    	userdatasourcehome = (UserDataSourceDataLocalHome) getLocator().getLocalHome(UserDataSourceDataLocalHome.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        /**     * Main method used to fetch userdata from the given user data sources     * See BaseUserDataSource class for further documentation about function     *     * @param userdatasourceids a Collection (Integer) of userdatasource Ids.     * @return Collection of UserDataSourceVO, empty if no userdata could be found.     * @ejb.interface-method view-type="both"     * @see org.ejbca.core.model.ra.userdatasource.BaseUserDataSource     */    public Collection fetch(Admin admin, Collection userdatasourceids, String searchstring) throws UserDataSourceException{        Iterator iter = userdatasourceids.iterator();        ArrayList result = new ArrayList();        while (iter.hasNext()) {            Integer id = (Integer) iter.next();            try {                UserDataSourceDataLocal pdl = userdatasourcehome.findByPrimaryKey(id);                BaseUserDataSource userdatasource = pdl.getUserDataSource();                if(isAuthorizedToUserDataSource(admin,userdatasource)){                  try {                    result.addAll(pdl.getUserDataSource().fetchUserDataSourceVOs(admin,searchstring));                    String msg = intres.getLocalizedMessage("userdatasource.fetcheduserdatasource", pdl.getName());            	                    getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(), null,                           null, LogEntry.EVENT_INFO_USERDATAFETCHED,msg);                  } catch (UserDataSourceException pe) {                      String msg = intres.getLocalizedMessage("userdatasource.errorfetchuserdatasource", pdl.getName());            	                      getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(), null,                              null, LogEntry.EVENT_ERROR_USERDATAFETCHED,msg);                    throw pe;                  }                }else{                	getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_RA,new Date(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,"Error, not authorized to user data source :" + pdl.getName());                }            } catch (FinderException fe) {                String msg = intres.getLocalizedMessage("userdatasource.erroruserdatasourceexist", id);            	                getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(), null, null,                        LogEntry.EVENT_ERROR_USERDATAFETCHED, msg);                throw new UserDataSourceException(msg);            }        }        return result;    }	/**     * Test the connection to a user data source     *     * @param userdatasourceid the id of the userdatasource to test.     * @ejb.interface-method view-type="both"     * @see org.ejbca.core.model.ra.userdatasource.BaseUserDataSource     */    public void testConnection(Admin admin, int userdatasourceid) throws UserDataSourceConnectionException {        debug(">testConnection(id: " + userdatasourceid + ")");        try {        	UserDataSourceDataLocal pdl = userdatasourcehome.findByPrimaryKey(new Integer(userdatasourceid));        	BaseUserDataSource userdatasource = pdl.getUserDataSource();        	if(isAuthorizedToEditUserDataSource(admin,userdatasource)){        		try {        			userdatasource.testConnection(admin);        			String msg = intres.getLocalizedMessage("userdatasource.testedcon", pdl.getName());            	        			getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(), null,        					null, LogEntry.EVENT_INFO_USERDATASOURCEDATA,msg);        		} catch (UserDataSourceConnectionException pe) {        			String msg = intres.getLocalizedMessage("userdatasource.errortestcon", pdl.getName());            	        			getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(), null, null,        					LogEntry.EVENT_ERROR_USERDATASOURCEDATA, msg, pe);        			

⌨️ 快捷键说明

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