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

📄 localraadminsessionbean.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        EndEntityProfile returnval=null;        try{            if(id==SecConst.EMPTY_ENDENTITYPROFILE) {                returnval = new EndEntityProfile(true);            }            if(id!=0 && id != SecConst.EMPTY_ENDENTITYPROFILE) {                returnval = (profiledatahome.findByPrimaryKey(new Integer(id))).getProfile();            }        }catch(FinderException e){            // Ignore so we'll return null        }        if (log.isDebugEnabled()) {            debug("<getEndEntityProfile(id): "+(returnval == null ? "null":"not null"));        	        }        return returnval;    } // getEndEntityProfile     /**     * Finds a end entity profile by id.     * @ejb.transaction type="Supports"      * @ejb.interface-method     */    public EndEntityProfile getEndEntityProfile(Admin admin, String profilename){    	if (log.isDebugEnabled()) {            debug(">getEndEntityProfile("+profilename+")");    		    	}        EndEntityProfile returnval=null;        try{          if(profilename.equals(EMPTY_ENDENTITYPROFILENAME)) {              returnval = new EndEntityProfile(true);          } else {              returnval = (profiledatahome.findByProfileName(profilename)).getProfile();          }        }catch(FinderException e){            // Ignore so we'll return null        }        debug("<getEndEntityProfile(profilename)");        return returnval;    } // getEndEntityProfile     /**     * Returns a end entity profiles id, given it's profilename     *     * @return the id or 0 if profile cannot be found.     * @ejb.transaction type="Supports"      * @ejb.interface-method     */    public int getEndEntityProfileId(Admin admin, String profilename){    	if (log.isDebugEnabled()) {            debug(">getEndEntityProfileId("+profilename+")");    		    	}      int returnval = 0;      if(profilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME))        return SecConst.EMPTY_ENDENTITYPROFILE;      try{        Integer id = (profiledatahome.findByProfileName(profilename)).getId();        returnval = id.intValue();      }catch(FinderException e){          // Ignore so we'll return 0      }      debug(">getEndEntityProfileId(profilename)");    		      return returnval;    } // getEndEntityrofileId     /**     * Returns a end entity profiles name given it's id.     *     * @return profilename or null if profile id doesn't exists.     * @ejb.transaction type="Supports"      * @ejb.interface-method     */    public String getEndEntityProfileName(Admin admin, int id){      String returnval = null;      if(id == SecConst.EMPTY_ENDENTITYPROFILE)        return EMPTY_ENDENTITYPROFILENAME;      try{        returnval = (profiledatahome.findByPrimaryKey(new Integer(id))).getProfileName();      }catch(FinderException e){}      return returnval;    } // getEndEntityProfileName     /**     * Method to check if a certificateprofile exists in any of the end entity profiles. Used to avoid desyncronization of certificate profile data.     *     * @param certificateprofileid the certificatetype id to search for.     * @return true if certificateprofile exists in any of the end entity profiles.     * @ejb.transaction type="Supports"      * @ejb.interface-method     */    public boolean existsCertificateProfileInEndEntityProfiles(Admin admin, int certificateprofileid){      String[] availablecertprofiles=null;      boolean exists = false;      try{        Collection result = profiledatahome.findAll();        Iterator i = result.iterator();        while(i.hasNext() && !exists){          availablecertprofiles = ((EndEntityProfileDataLocal) i.next()).getProfile().getValue(EndEntityProfile.AVAILCERTPROFILES, 0).split(EndEntityProfile.SPLITCHAR);          for(int j=0; j < availablecertprofiles.length; j++){            if(Integer.parseInt(availablecertprofiles[j]) == certificateprofileid){              exists=true;              break;            }          }        }      }catch(FinderException e){}      return exists;    }     /**     * Method to check if a CA exists in any of the end entity profiles. Used to avoid desyncronization of CA data.     *     * @param caid the caid to search for.     * @return true if ca exists in any of the end entity profiles.     * @ejb.transaction type="Supports"      * @ejb.interface-method     */    public boolean existsCAInEndEntityProfiles(Admin admin, int caid){      String[] availablecas=null;      boolean exists = false;      try{        Collection result = profiledatahome.findAll();        Iterator i = result.iterator();        while(i.hasNext() && !exists){          availablecas = ((EndEntityProfileDataLocal) i.next()).getProfile().getValue(EndEntityProfile.AVAILCAS, 0).split(EndEntityProfile.SPLITCHAR);          for(int j=0; j < availablecas.length; j++){            if(Integer.parseInt(availablecas[j]) == caid){              exists=true;              break;            }          }        }      }catch(FinderException e){}      return exists;    } // existsCAProfileInEndEntityProfiles         /**     * Loads the global configuration from the database.     *     * @throws EJBException if a communication or other error occurs.     * @ejb.transaction type="Supports"     * @ejb.interface-method     */    public GlobalConfiguration loadGlobalConfiguration(Admin admin)  {        debug(">loadGlobalConfiguration()");        if(globalconfiguration != null)          return globalconfiguration ;        GlobalConfiguration ret=null;        try{          GlobalConfigurationDataLocal gcdata = globalconfigurationhome.findByPrimaryKey("0");          if(gcdata!=null){            ret = gcdata.getGlobalConfiguration();          }        }catch (javax.ejb.FinderException fe) {             // Create new configuration             ret = new GlobalConfiguration();        }        debug("<loadGlobalConfiguration()");        return ret;    } //loadGlobalConfiguration    /**     * Sets the base url in the global configuration.     *     * @throws EJBException if a communication or other error occurs.     * @ejb.interface-method     */    public void initGlobalConfigurationBaseURL(Admin admin, String computername, String applicationpath)  {        debug(">initGlobalConfigurationBaseURL()");        GlobalConfiguration gc = this.loadGlobalConfiguration(admin);        gc.setComputerName(computername);        gc.setApplicationPath(applicationpath);        this.saveGlobalConfiguration(admin, gc);        debug("<initGlobalConfigurationBaseURL()");     } // initGlobalConfigurationBaseURL    /**     * Saves the globalconfiguration     *     * @throws EJBException if a communication or other error occurs.     * @ejb.interface-method     */    public void saveGlobalConfiguration(Admin admin, GlobalConfiguration globalconfiguration)  {    	debug(">saveGlobalConfiguration()");    	String pk = "0";    	try {    		GlobalConfigurationDataLocal gcdata = globalconfigurationhome.findByPrimaryKey(pk);    		gcdata.setGlobalConfiguration(globalconfiguration);			String msg = intres.getLocalizedMessage("ra.savedconf", gcdata.getConfigurationId());            	    		getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_EDITSYSTEMCONFIGURATION,msg);    	}catch (javax.ejb.FinderException fe) {    		// Global configuration doesn't yet exists.    		try{    			GlobalConfigurationDataLocal data1 = globalconfigurationhome.create(pk,globalconfiguration);    			String msg = intres.getLocalizedMessage("ra.createdconf", data1.getConfigurationId());            	    			getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_EDITSYSTEMCONFIGURATION, msg);    		} catch(CreateException e){    			String msg = intres.getLocalizedMessage("ra.errorcreateconf");            	    			getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_EDITSYSTEMCONFIGURATION,msg);    		}    	}    	this.globalconfiguration=globalconfiguration;    	debug("<saveGlobalConfiguration()");    } // saveGlobalConfiguration    // Private methods    private int findFreeEndEntityProfileId(){      int id = (new Random((new Date()).getTime())).nextInt();      boolean foundfree = false;      while(!foundfree){        try{          if(id > 1)            profiledatahome.findByPrimaryKey(new Integer(id));          id++;        }catch(FinderException e){           foundfree = true;        }      }      return id;    } // findFreeEndEntityProfileId	private boolean isFreeEndEntityProfileId(int id) {			boolean foundfree = false;			try {				if (id > 1) {					profiledatahome.findByPrimaryKey(new Integer(id));				}			} catch (FinderException e) {				foundfree = true;			}			return foundfree;		} // isFreeEndEntityProfileId    /**     * Changes the admin preference in the database. Returns false if admin doesn't exist.     */    private boolean updateAdminPreference(Admin admin, String certificatefingerprint, AdminPreference adminpreference, boolean dolog){       debug(">updateAdminPreference(fingerprint : " + certificatefingerprint + ")");       boolean ret = false;        try {            adminpreferenceshome.findByPrimaryKey(certificatefingerprint);            adminpreferenceshome.remove(certificatefingerprint);            try{                AdminPreferencesDataLocal apdata2 = adminpreferenceshome.findByPrimaryKey(certificatefingerprint);                debug("Found admin preferences with id "+apdata2.getId());            }  catch (javax.ejb.FinderException fe) {            }            adminpreferenceshome.create(certificatefingerprint,adminpreference);            try{                AdminPreferencesDataLocal apdata3 = adminpreferenceshome.findByPrimaryKey(certificatefingerprint);                debug("Found admin preferences with id "+apdata3.getId());            }  catch (javax.ejb.FinderException fe) {            }            if (dolog) {                    			String msg = intres.getLocalizedMessage("ra.changedadminpref", certificatefingerprint);            	                getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg);            }            ret = true;        } catch (javax.ejb.FinderException fe) {             ret=false;             if (dolog) {            	 String msg = intres.getLocalizedMessage("ra.adminprefnotfound", certificatefingerprint);            	                 getLogSession().log(admin,admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ADMINISTRATORPREFERENCECHANGED,msg);             }        } catch(Exception e){          throw new EJBException(e);        }        debug("<updateAdminPreference()");        return ret;    } // changeAdminPreference} // LocalRaAdminSessionBean

⌨️ 快捷键说明

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