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

📄 localpublishersessionbean.java

📁 一套JAVA的CA证书签发系统.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     	   if(success)		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_PUBLISHERDATA,"Publisher " + name + " added.");	   else		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(),null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA,"Error adding publisher "+ name);       		if(!success)		  throw new PublisherExistsException();             	   debug("<addPublisher()");	} // addPublisher	/**	 * Adds a publisher to the database.	 * Used for importing and exporting profiles from xml-files.	 * 	 * @throws PublisherExistsException if hard token already exists.	 * @throws EJBException if a communication or other error occurs.	 */	public void addPublisher(Admin admin, int id, String name, BasePublisher publisher) throws PublisherExistsException{	   debug(">addPublisher(name: " + name + ", id: " + id +")");	   boolean success=false;	   	   try{		  publisherhome.findByName(name);	   }catch(FinderException e){	   	 try{	   	 			publisherhome.findByPrimaryKey(new Integer(id));			 }catch(FinderException f){	  	       try{		     publisherhome.create(new Integer(id), name, publisher);		     success = true;		   }catch(CreateException g){}		 	   	 }	   }     	   if(success)		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_PUBLISHERDATA,"Publisher " + name + " added.");	   else		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(),null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA,"Error adding publisher "+ name);              if(!success)         throw new PublisherExistsException();	   debug("<addPublisher()");	   	} // addPublisher	/**	 * Updates publisher data	 *	 	 * @throws EJBException if a communication or other error occurs.	 */	public void changePublisher(Admin admin, String name, BasePublisher publisher){	   debug(">changePublisher(name: " + name + ")");	   boolean success = false;	   	   try{	   	 PublisherDataLocal htp = publisherhome.findByName(name);		 htp.setPublisher(publisher);		 		 success = true;	   }catch(FinderException e){}      	   if(success)		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_PUBLISHERDATA,"Publisher " +  name + " edited.");	   else		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA,"Error editing publisher " + name + ".");	   debug("<changePublisher()");	   	} // changePublisher	 /**	 * Adds a publisher with the same content as the original.	 *	 * @throws PublisherExistsException if publisher already exists.	 * @throws EJBException if a communication or other error occurs.	 */	public void clonePublisher(Admin admin, String oldname, String newname) throws PublisherExistsException{	   debug(">clonePublisher(name: " + oldname + ")");	   BasePublisher publisherdata = null;	   boolean success = false;	   	   try{	   	 PublisherDataLocal htp = publisherhome.findByName(oldname);		 publisherdata = (BasePublisher) htp.getPublisher().clone();         try{         		   addPublisher(admin, newname, publisherdata);		   getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_PUBLISHERDATA,"New publisher " + newname +  ", used publisher " + oldname + " as template.");         }catch(PublisherExistsException f){		   getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(),null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA,"Error adding publisher " + newname +  " using publisher " + oldname + " as template.");		   throw f;           }		 		   	   }catch(Exception e){		  		  throw new EJBException(e);	   }	   debug("<clonePublisher()");	   	} // clonePublisher	 /**	 * Removes a publisher from the database.	 *	 * @throws EJBException if a communication or other error occurs.	 */	public void removePublisher(Admin admin, String name){	  debug(">removePublisher(name: " + name + ")");	  	  try{	  	PublisherDataLocal htp = publisherhome.findByName(name);				htp.remove();		getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_PUBLISHERDATA,"Publisher " + name + " removed.");	  }catch(Exception e){		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA,"Error removing publisher " + name + ".",e);	  }	  debug("<removePublisher()");	} // removePublisher	 /**	 * Renames a publisher	 *	 * @throws PublisherExistsException if publisher already exists.	 * @throws EJBException if a communication or other error occurs.	 */	public void renamePublisher(Admin admin, String oldname, String newname) throws PublisherExistsException{										 	   debug(">renamePublisher(from " + oldname + " to " + newname + ")");	   boolean success = false;	   	   try{		  publisherhome.findByName(newname);	   }catch(FinderException e){		  try{			 PublisherDataLocal htp = publisherhome.findByName(oldname);			 htp.setName(newname);			 			 			 success = true;		  }catch(FinderException g){}		 	   }       	   if(success)		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_INFO_PUBLISHERDATA,"Publisher " + oldname + " renamed to " + newname +  "." );	   else		 getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA," Error renaming publisher  " + oldname +  " to " + newname + "." );       if(!success)	     throw new PublisherExistsException();	   debug("<renamePublisher()");	} // renameHardTokenProfile	/**	 * Retrives a Collection of id:s (Integer) to authorized publishers.	 *	 * @return Collection of id:s (Integer)	 */	public Collection getAuthorizedPublisherIds(Admin admin){	  HashSet returnval = new HashSet();	  Collection result = null;      boolean superadmin = false;	 	  	  try {	  	superadmin = getAuthorizationSession(admin).isAuthorized(admin,AvailableAccessRules.ROLE_SUPERADMINISTRATOR);		result = this.publisherhome.findAll();		Iterator i = result.iterator();		while(i.hasNext()){		  PublisherDataLocal next = (PublisherDataLocal) i.next();		  BasePublisher publisher = next.getPublisher();		  		  		  		  returnval.add(next.getId());			}		  		  } catch (AuthorizationDeniedException e1) {} 	  	catch (FinderException fe){}	  	  if(!superadmin){	  	  	  	          Iterator authorizedcas = this.getAuthorizationSession(admin).getAuthorizedCAIds(admin).iterator();        while(authorizedcas.hasNext()){          returnval.addAll(this.getCAAdminSession(admin).getCAInfo(admin,((Integer) authorizedcas.next()).intValue()).getCRLPublishers());	        }       	  }  	  return returnval;	} // getAuthorizedPublisherIds 	/**	 * Method creating a hashmap mapping publisher id (Integer) to publisher name (String).	 */    	public HashMap getPublisherIdToNameMap(Admin admin){	  HashMap returnval = new HashMap();	  Collection result = null;	  try{		result = publisherhome.findAll();		Iterator i = result.iterator();		while(i.hasNext()){		  PublisherDataLocal next = (PublisherDataLocal) i.next();    		  returnval.put(next.getId(),next.getName());		}	  }catch(FinderException e){}	  return returnval;	} // getPublisherIdToNameMap	/**	 * Retrives a named publisher.	 */	public BasePublisher getPublisher(Admin admin, String name){	   BasePublisher returnval=null;              	   try{		 returnval = (publisherhome.findByName(name)).getPublisher();	   } catch(FinderException e){		   // return null if we cant find it	   }	   return returnval;	} //  getPublisher	 /**      * Finds a publisher by id.	  *	  *	  */	public BasePublisher getPublisher(Admin admin, int id){	   BasePublisher returnval=null;         	   try{		   returnval = (publisherhome.findByPrimaryKey(new Integer(id))).getPublisher();	   } catch(FinderException e){			 // return null if we cant find it	   }	     	   return returnval;	} // getPublisher	/**	 * Help method used by publisher proxys to indicate if it is time to	 * update it's data.	 *	 	 */		public int getPublisherUpdateCount(Admin admin, int publisherid){	  int returnval = 0;	  	  try{	  	returnval = (publisherhome.findByPrimaryKey(new Integer(publisherid))).getUpdateCounter();  	  		  }catch(FinderException e){}			  	  return returnval;	}	 /**	 * Returns a publisher id, given it's publishers name	 *	 	 *	 * @return the id or 0 if the publisher cannot be found.	 */	public int getPublisherId(Admin admin, String name){	  int returnval = 0;            	  try{		Integer id = (publisherhome.findByName(name)).getId();		returnval = id.intValue();	  }catch(FinderException e){}           	  return returnval;	} // getPublisherId     /**      * Returns a publishers name given its id. 	  *	  * @return the name or null if id doesnt exists	  * @throws EJBException if a communication or other error occurs.	  */	public String getPublisherName(Admin admin, int id){	  debug(">getPublisherName(id: " + id + ")");	  String returnval = null;	  PublisherDataLocal htp = null;	  try{		htp = publisherhome.findByPrimaryKey(new Integer(id));		if(htp != null){		  returnval = htp.getName();		}	  }catch(FinderException e){}	  debug("<getPublisherName()");	  return returnval;	} // getPublisherName                private Integer findFreePublisherId(){      Random ran = (new Random((new Date()).getTime()));      int id = ran.nextInt();      boolean foundfree = false;      while(!foundfree){        try{          if(id > 1)            publisherhome.findByPrimaryKey(new Integer(id));            id = ran.nextInt();        }catch(FinderException e){           foundfree = true;        }      }      return new Integer(id);    } // findFreeHardTokenIssuerId} // LocalPublisherSessionBean

⌨️ 快捷键说明

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