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

📄 localraadminsessionbean.java

📁 一套JAVA的CA证书签发系统.
💻 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 se.anatom.ejbca.ra.raadmin;import java.sql.Connection;import java.sql.SQLException;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 javax.naming.NamingException;import javax.sql.DataSource;import se.anatom.ejbca.BaseSessionBean;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.log.Admin;import se.anatom.ejbca.log.ILogSessionLocal;import se.anatom.ejbca.log.ILogSessionLocalHome;import se.anatom.ejbca.log.LogEntry;/** * 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.37 2004/05/15 14:53:10 herrvendil Exp $ */public class LocalRaAdminSessionBean extends BaseSessionBean  {    /** Var holding JNDI name of datasource */    private String dataSource = "";    /** 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 final static String EMPTY_ENDENTITYPROFILENAME   = "EMPTY";    private static final String DEFAULTUSERPREFERENCE = "default";        /**     * Default create for SessionBean without any creation Arguments.     * @throws CreateException if bean instance can't be created     */    public void ejbCreate() throws CreateException {        debug(">ejbCreate()");      try{        dataSource = (String)lookup("java:comp/env/DataSource", java.lang.String.class);        debug("DataSource=" + dataSource);        adminpreferenceshome = (AdminPreferencesDataLocalHome)lookup("java:comp/env/ejb/AdminPreferencesDataLocal", AdminPreferencesDataLocalHome.class);        profiledatahome = (EndEntityProfileDataLocalHome)lookup("java:comp/env/ejb/EndEntityProfileDataLocal", EndEntityProfileDataLocalHome.class);        globalconfigurationhome = (GlobalConfigurationDataLocalHome)lookup("java:comp/env/ejb/GlobalConfigurationDataLocal", GlobalConfigurationDataLocalHome.class);                        debug("<ejbCreate()");      }catch(Exception e){         throw new EJBException(e);      }    }    /** Gets connection to Datasource used for manual SQL searches     * @return Connection     */    private Connection getConnection() throws SQLException, NamingException {        DataSource ds = (DataSource)getInitialContext().lookup(dataSource);        return ds.getConnection();    } //getConnection        /** Gets connection to log session bean     */    private ILogSessionLocal getLogSession() {        if(logsession == null){          try{            ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) lookup("java:comp/env/ejb/LogSessionLocal",ILogSessionLocalHome.class);            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) lookup("java:comp/env/ejb/AuthorizationSessionLocal",IAuthorizationSessionLocalHome.class);            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.     */    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.     */    public boolean addAdminPreference(Admin admin, String certificatefingerprint, AdminPreference adminpreference){        debug(">addAdminPreference(fingerprint : " + certificatefingerprint + ")");        boolean ret = false;        try {            AdminPreferencesDataLocal apdata= adminpreferenceshome.create(certificatefingerprint, adminpreference);            getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,"Administrator preference added.");            ret = true;        }        catch (Exception e) {          ret = false;          getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,"Trying to add preference for administrator that already exists.");        }        debug("<addAdminPreference()");        return ret;    } // addAdminPreference    /**     * Changes the admin preference in the database. Returns false if admin doesn't exists.     */    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.     */    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.     */    public boolean existsAdminPreference(Admin admin, String certificatefingerprint){       debug(">existsAdminPreference(fingerprint : " + certificatefingerprint + ")");       boolean ret = false;        try {            AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(certificatefingerprint);            ret = true;        } catch (javax.ejb.FinderException fe) {             ret=false;        } catch(Exception e){          throw new EJBException(e);        }        debug("<existsAdminPreference()");        return ret;    }// existsAdminPreference    /**     * Function that returns the default admin preference.     *     * @throws EJBException if a communication or other error occurs.     */    public AdminPreference getDefaultAdminPreference(Admin admin){        debug(">getDefaultAdminPreference()");        AdminPreference ret =null;        try {            AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(DEFAULTUSERPREFERENCE);            ret = apdata.getAdminPreference();        } catch (javax.ejb.FinderException fe) {            try{               // Create new configuration              AdminPreferencesDataLocal apdata = adminpreferenceshome.create(DEFAULTUSERPREFERENCE,new AdminPreference());              ret = apdata.getAdminPreference();            }catch(Exception e){              throw new EJBException(e);            }          } catch(Exception e){          throw new EJBException(e);        }        debug("<getDefaultAdminPreference()");        return ret;    } // getDefaultPreference()

⌨️ 快捷键说明

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