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

📄 localraadminsessionbean.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.raadmin;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.SecConst;import org.ejbca.core.model.authorization.AuthorizationDeniedException;import org.ejbca.core.model.log.Admin;import org.ejbca.core.model.log.LogEntry;import org.ejbca.core.model.ra.raadmin.AdminPreference;import org.ejbca.core.model.ra.raadmin.EndEntityProfile;import org.ejbca.core.model.ra.raadmin.EndEntityProfileExistsException;import org.ejbca.core.model.ra.raadmin.GlobalConfiguration;/** * Stores data used by web server clients. * Uses JNDI name for datasource as defined in env 'Datasource' in ejb-jar.xml. * * @version $Id: LocalRaAdminSessionBean.java,v 1.10 2007/01/11 09:35:07 anatom Exp $ * * @ejb.bean description="Session bean handling core CA function,signing certificates" *   display-name="RaAdminSB" *   name="RaAdminSession" *   jndi-name="RaAdminSession" *   local-jndi-name="RaAdminSessionLocal" *   view-type="both" *   type="Stateless" *   transaction-type="Container" * * @ejb.transaction type="Required" * * @weblogic.enable-call-by-reference True * * @ejb.home *   extends="javax.ejb.EJBHome" *   remote-class="org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionHome" *   local-extends="javax.ejb.EJBLocalHome" *   local-class="org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionLocalHome" * * @ejb.interface *   extends="javax.ejb.EJBObject" *   remote-class="org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionRemote" *   local-extends="javax.ejb.EJBLocalObject" *   local-class="org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionLocal" * * @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.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 AdminPreferencesData Entity bean" *   view-type="local" *   ref-name="ejb/AdminPreferencesDataLocal" *   type="Entity" *   home="org.ejbca.core.ejb.ra.raadmin.AdminPreferencesDataLocalHome" *   business="org.ejbca.core.ejb.ra.raadmin.AdminPreferencesDataLocal" *   link="AdminPreferencesData" * * @ejb.ejb-external-ref description="The EndEntityProfileData Entity bean" *   view-type="local" *   ref-name="ejb/EndEntityProfileDataLocal" *   type="Entity" *   home="org.ejbca.core.ejb.ra.raadmin.EndEntityProfileDataLocalHome" *   business="org.ejbca.core.ejb.ra.raadmin.EndEntityProfileDataLocal" *   link="EndEntityProfileData" * * @ejb.ejb-external-ref description="The GlobalConfigurationData Entity bean" *   view-type="local" *   ref-name="ejb/GlobalConfigurationDataLocal" *   type="Entity" *   home="org.ejbca.core.ejb.ra.raadmin.GlobalConfigurationDataLocalHome" *   business="org.ejbca.core.ejb.ra.raadmin.GlobalConfigurationDataLocal" *   link="GlobalConfigurationData" * */public class LocalRaAdminSessionBean extends BaseSessionBean  {    /** Internal localization of logs and errors */    private static final InternalResources intres = InternalResources.getInstance();    /** The home interface of  AdminPreferences entity bean */    private AdminPreferencesDataLocalHome adminpreferenceshome=null;    /** The home interface of  EndEntityProfileData entity bean */    private EndEntityProfileDataLocalHome profiledatahome=null;    /** The home interface of  GlobalConfiguration entity bean */    private GlobalConfigurationDataLocalHome globalconfigurationhome = null;    /** Var containing the global configuration. */    private GlobalConfiguration globalconfiguration;    /** The local interface of  log session bean */    private ILogSessionLocal logsession = null;    /** the local inteface of authorization session */    private IAuthorizationSessionLocal authorizationsession = null;    public static final String EMPTY_ENDENTITYPROFILENAME   = "EMPTY";    private static final String DEFAULTUSERPREFERENCE = "default";    public static final String EMPTY_ENDENTITYPROFILE = LocalRaAdminSessionBean.EMPTY_ENDENTITYPROFILENAME;    public static final int EMPTY_ENDENTITYPROFILEID  = SecConst.EMPTY_ENDENTITYPROFILE;    /**     * Default create for SessionBean without any creation Arguments.     * @throws CreateException if bean instance can't be created     * @ejb.create-method     */    public void ejbCreate() throws CreateException {      try{        adminpreferenceshome = (AdminPreferencesDataLocalHome)getLocator().getLocalHome(AdminPreferencesDataLocalHome.COMP_NAME);        profiledatahome = (EndEntityProfileDataLocalHome)getLocator().getLocalHome(EndEntityProfileDataLocalHome.COMP_NAME);        globalconfigurationhome = (GlobalConfigurationDataLocalHome)getLocator().getLocalHome(GlobalConfigurationDataLocalHome.COMP_NAME);              }catch(Exception e){         throw new EJBException(e);      }    }    /** Gets connection to log session bean     */    private ILogSessionLocal getLogSession() {        if(logsession == null){          try{            ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME);            logsession = logsessionhome.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 authorizationsessionhome = (IAuthorizationSessionLocalHome) getLocator().getLocalHome(IAuthorizationSessionLocalHome.COMP_NAME);            authorizationsession = authorizationsessionhome.create();          }catch(Exception e){             throw new EJBException(e);          }        }        return authorizationsession;    } //getAuthorizationSession     /**     * Finds the admin preference belonging to a certificate serialnumber. Returns null if admin doesn't exists.     * @ejb.interface-method     */    public AdminPreference getAdminPreference(Admin admin, String certificatefingerprint){        debug(">getAdminPreference()");        AdminPreference ret =null;        try {            AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(certificatefingerprint);            ret = apdata.getAdminPreference();        } catch (javax.ejb.FinderException fe) {             // Create new configuration             ret=null;        } catch(Exception e){          throw new EJBException(e);        }        debug("<getAdminPreference()");        return ret;    } // getAdminPreference    /**     * Adds a admin preference to the database. Returns false if admin already exists.     * @ejb.interface-method     */    public boolean addAdminPreference(Admin admin, String certificatefingerprint, AdminPreference adminpreference){    	debug(">addAdminPreference(fingerprint : " + certificatefingerprint + ")");    	boolean ret = false;    	boolean exists = false;    	try {        	// We must actually check if there is one before we try to add it, because wls does not allow us to catch any errors if creating fails, that sux        	AdminPreferencesDataLocal data = adminpreferenceshome.findByPrimaryKey(certificatefingerprint);        	if (data != null) {        		exists = true;        	}    	} catch (FinderException e) {    		// This is what we hope will happen    	}    	if (!exists) {    		try {    			AdminPreferencesDataLocal apdata= adminpreferenceshome.create(certificatefingerprint, adminpreference);    			String msg = intres.getLocalizedMessage("ra.adminprefadded", apdata.getId());            	    			getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg);    			ret = true;        		    		} catch (Exception e) {    			ret = false;    			String msg = intres.getLocalizedMessage("ra.adminprefexists");            	    			getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg);    		}    	} else {    		ret = false;    		String msg = intres.getLocalizedMessage("ra.adminprefexists");            	    		getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg);            	        		    	}    	debug("<addAdminPreference()");    	return ret;    } // addAdminPreference    /**     * Changes the admin preference in the database. Returns false if admin doesn't exists.     * @ejb.interface-method     */    public boolean changeAdminPreference(Admin admin, String certificatefingerprint, AdminPreference adminpreference){       debug(">changeAdminPreference(fingerprint : " + certificatefingerprint + ")");       return updateAdminPreference(admin, certificatefingerprint, adminpreference, true);    } // changeAdminPreference    /**     * Changes the admin preference in the database. Returns false if admin doesn't exists.     * @ejb.interface-method     */    public boolean changeAdminPreferenceNoLog(Admin admin, String certificatefingerprint, AdminPreference adminpreference){       debug(">changeAdminPreferenceNoLog(fingerprint : " + certificatefingerprint + ")");       return updateAdminPreference(admin, certificatefingerprint, adminpreference, false);    } // changeAdminPreference    /**     * Checks if a admin preference exists in the database.     * @ejb.interface-method     * @ejb.transaction type="Supports"     */    public boolean existsAdminPreference(Admin admin, String certificatefingerprint){       debug(">existsAdminPreference(fingerprint : " + certificatefingerprint + ")");       boolean ret = false;        try {            AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(certificatefingerprint);            debug("Found admin preferences with id "+apdata.getId());            ret = true;        } catch (javax.ejb.FinderException fe) {             ret=false;        } catch(Exception e){

⌨️ 快捷键说明

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