📄 localraadminsessionbean.java
字号:
/** * Function that saves the default admin preference. * * @throws EJBException if a communication or other error occurs. */ public void saveDefaultAdminPreference(Admin admin, AdminPreference defaultadminpreference){ debug(">saveDefaultAdminPreference()"); try { AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(DEFAULTUSERPREFERENCE); apdata.setAdminPreference(defaultadminpreference); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,"Default administrator preference changed."); } catch (Exception e) { getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ADMINISTRATORPREFERENCECHANGED,"Error saving default administrator preference."); throw new EJBException(e); } debug("<saveDefaultAdminPreference()"); } // saveDefaultAdminPreference /** * Adds a profile to the database. * * @param admin administrator performing task * @param profilename readable profile name * @param profile profile to be added * * @return true if added succesfully, false otherwise if profile already exist */ public void addEndEntityProfile(Admin admin, String profilename, EndEntityProfile profile) throws EndEntityProfileExistsException { addEndEntityProfile(admin,findFreeEndEntityProfileId(),profilename,profile); } // addEndEntityProfile /** * Adds a profile to the database. * * @param admin administrator performing task * @param profileid internal ID of new profile, use only if you know it's right. * @param profilename readable profile name * @param profile profile to be added * * @return true if added succesfully, false otherwise if profile already exist */ public void addEndEntityProfile(Admin admin, int profileid, String profilename, EndEntityProfile profile) throws EndEntityProfileExistsException{ if(profilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME)){ getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,"Error adding end entity profile "+ profilename); throw new EndEntityProfileExistsException(); } if (isFreeEndEntityProfileId(profileid) == false) { getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,"Error adding end entity profile "+ profilename); throw new EndEntityProfileExistsException(); } try { profiledatahome.findByProfileName(profilename); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,"Error adding end entity profile "+ profilename); throw new EndEntityProfileExistsException(); } catch (FinderException e) { try { profiledatahome.create(new Integer(profileid), profilename, profile); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE, "End entity profile " + profilename + " added."); } catch (Exception f) { error("Error adding end entity profile: ", e); logsession.log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE, "Error adding end entity profile " + profilename); } } } // addEndEntityProfile /** * Adds a end entity profile to a group with the same content as the original profile. */ public void cloneEndEntityProfile(Admin admin, String originalprofilename, String newprofilename) throws EndEntityProfileExistsException{ EndEntityProfile profile = null; if(newprofilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME)){ getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,"Error adding end entity profile " + newprofilename + " using profile " + originalprofilename + " as template."); throw new EndEntityProfileExistsException(); } try{ EndEntityProfileDataLocal pdl = profiledatahome.findByProfileName(originalprofilename); profile = (EndEntityProfile) pdl.getProfile().clone(); try{ profiledatahome.findByProfileName(newprofilename); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,"Error adding end entity profile " + newprofilename + " using profile " + originalprofilename + " as template."); throw new EndEntityProfileExistsException(); }catch(FinderException e){ profiledatahome.create(new Integer(findFreeEndEntityProfileId()),newprofilename,profile); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE,"New end entity profile " + newprofilename + " used profile " + originalprofilename + " as template."); } }catch(Exception e){ getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,"Error adding end entity profile " + newprofilename + " using profile " + originalprofilename + " as template."); } } // cloneEndEntityProfile /** * Removes an end entity profile from the database. * @throws EJBException if a communication or other error occurs. */ public void removeEndEntityProfile(Admin admin, String profilename) { try{ EndEntityProfileDataLocal pdl = profiledatahome.findByProfileName(profilename); pdl.remove(); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE,"End entity profile " + profilename + " removed."); }catch(Exception e){ getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,"Error removing end entity profile " + profilename + "."); } } // removeEndEntityProfile /** * Renames a end entity profile */ public void renameEndEntityProfile(Admin admin, String oldprofilename, String newprofilename) throws EndEntityProfileExistsException{ if(newprofilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME) || oldprofilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME)){ getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE," Error renaming end entity profile " + oldprofilename + " to " + newprofilename + "." ); throw new EndEntityProfileExistsException(); } try{ profiledatahome.findByProfileName(newprofilename); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE," Error renaming end entity profile " + oldprofilename + " to " + newprofilename + "." ); throw new EndEntityProfileExistsException(); }catch(FinderException e){ try{ EndEntityProfileDataLocal pdl = profiledatahome.findByProfileName(oldprofilename); pdl.setProfileName(newprofilename); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE,"End entity profile " + oldprofilename + " renamed to " + newprofilename + "." ); }catch(FinderException f){ getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE," Error renaming end entity profile " + oldprofilename + " to " + newprofilename + "." ); } } } // renameProfile /** * Updates profile data */ public void changeEndEntityProfile(Admin admin, String profilename, EndEntityProfile profile){ try{ EndEntityProfileDataLocal pdl = profiledatahome.findByProfileName(profilename); pdl.setProfile(profile); getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE,"End entity profile " + profilename + " edited."); }catch(FinderException e){ getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_RA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,"Error editing end entity profile " + profilename + "."); } }// changeEndEntityProfile /** * Retrives a Collection of id:s (Integer) to authorized profiles. */ public Collection getAuthorizedEndEntityProfileIds(Admin admin){ ArrayList returnval = new ArrayList(); Collection result = null; HashSet authorizedcaids = new HashSet(getAuthorizationSession().getAuthorizedCAIds(admin)); //debug("Admin authorized to "+authorizedcaids.size()+" CAs."); try{ if(getAuthorizationSession().isAuthorizedNoLog(admin, "/super_administrator")) returnval.add(new Integer(SecConst.EMPTY_ENDENTITYPROFILE)); }catch(AuthorizationDeniedException e){} try{ result = profiledatahome.findAll(); Iterator i = result.iterator(); while(i.hasNext()){ EndEntityProfileDataLocal next = (EndEntityProfileDataLocal) i.next(); // Check if all profiles available CAs exists in authorizedcaids. String value = next.getProfile().getValue(EndEntityProfile.AVAILCAS, 0); //debug("AvailCAs: "+value); if (value != null) { String[] availablecas = value.split(EndEntityProfile.SPLITCHAR); //debug("No of available CAs: "+availablecas.length); boolean allexists = true; for(int j=0; j < availablecas.length; j++){ //debug("Available CA["+j+"]: "+availablecas[j]); if(!authorizedcaids.contains( new Integer(availablecas[j]))){ allexists = false; //debug("Profile "+next.getId()+" not authorized"); break; } } if(allexists) { //debug("Adding "+next.getId()); returnval.add(next.getId()); } } } }catch(Exception e){ error("Error getting authorized entity profile ids: ", e); } return returnval; } // getAuthorizedEndEntityProfileNames /** * Method creating a hashmap mapping profile id (Integer) to profile name (String). */ public HashMap getEndEntityProfileIdToNameMap(Admin admin){ debug(">getEndEntityProfileIdToNameMap"); HashMap returnval = new HashMap(); Collection result = null; returnval.put(new Integer(SecConst.EMPTY_ENDENTITYPROFILE),EMPTY_ENDENTITYPROFILENAME); try{ result = profiledatahome.findAll(); //debug("Found "+result.size()+ " end entity profiles."); Iterator i = result.iterator(); while(i.hasNext()){ EndEntityProfileDataLocal next = (EndEntityProfileDataLocal) i.next(); //debug("Added "+next.getId()+ ", "+next.getProfileName()); returnval.put(next.getId(),next.getProfileName()); } }catch(Exception e) { error("Error reading entity profiles: ", e); } debug(">getEndEntityProfileIdToNameMap"); return returnval; } // getEndEntityProfileIdToNameMap /** * Finds a end entity profile by id. */ public EndEntityProfile getEndEntityProfile(Admin admin, int id){ debug(">getEndEntityProfile(id)"); 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 } debug("<getEndEntityProfile(id)"); return returnval; } // getEndEntityProfile /** * Finds a end entity profile by id. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -