📄 localraadminsessionbean.java
字号:
public EndEntityProfile getEndEntityProfile(Admin admin, String profilename){ 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. */ public int getEndEntityProfileId(Admin admin, String 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 } return returnval; } // getEndEntityrofileId /** * Returns a end entity profiles name given it's id. * * @return profilename or null if profile id doesn't exists. */ 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. */ 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. */ 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. */ 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. */ 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. */ public void saveGlobalConfiguration(Admin admin, GlobalConfiguration globalconfiguration) { debug(">saveGlobalConfiguration()"); String pk = "0"; try { GlobalConfigurationDataLocal gcdata = globalconfigurationhome.findByPrimaryKey(pk); gcdata.setGlobalConfiguration(globalconfiguration); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_EDITSYSTEMCONFIGURATION,""); }catch (javax.ejb.FinderException fe) { // Global configuration doesn't yet exists. try{ GlobalConfigurationDataLocal data1= globalconfigurationhome.create(pk,globalconfiguration); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_EDITSYSTEMCONFIGURATION,""); } catch(CreateException e){ getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_EDITSYSTEMCONFIGURATION,""); } } 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 { AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(certificatefingerprint); adminpreferenceshome.remove(certificatefingerprint); try{ AdminPreferencesDataLocal apdata2 = adminpreferenceshome.findByPrimaryKey(certificatefingerprint); } catch (javax.ejb.FinderException fe) { } apdata= adminpreferenceshome.create(certificatefingerprint,adminpreference); try{ AdminPreferencesDataLocal apdata3 = adminpreferenceshome.findByPrimaryKey(certificatefingerprint); } catch (javax.ejb.FinderException fe) { } if (dolog) getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,"Administrator preference changed."); ret = true; } catch (javax.ejb.FinderException fe) { ret=false; if (dolog){ getLogSession().log(admin,admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ADMINISTRATORPREFERENCECHANGED,"Administrator cannot be found i database."); } } catch(Exception e){ throw new EJBException(e); } debug("<updateAdminPreference()"); return ret; } // changeAdminPreference } // LocalRaAdminSessionBean
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -