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

📄 localhardtokensessionbean.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      debug(">getHardTokenIssuerId(alias: " + alias + ")");      int returnval = NO_ISSUER;      HardTokenIssuerDataLocal htih = null;      try{        htih = hardtokenissuerhome.findByAlias(alias);        if(htih != null){          returnval = htih.getId().intValue();        }      }catch(FinderException e){}      debug("<getHardTokenIssuerId()");      return returnval;    } // getNumberOfHardTokenIssuersId       /**       * Returns a hard token issuer alias given its id.       *       * @return the alias or null if id noesnt exists       * @throws EJBException if a communication or other error occurs.        * @ejb.interface-method view-type="both"       */    public String getHardTokenIssuerAlias(Admin admin, int id){      debug(">getHardTokenIssuerAlias(id: " + id + ")");      String returnval = null;      HardTokenIssuerDataLocal htih = null;      try{        htih = hardtokenissuerhome.findByPrimaryKey(new Integer(id));        if(htih != null){          returnval = htih.getAlias();        }      }catch(FinderException e){}      debug("<getHardTokenIssuerAlias()");      return returnval;    } // getHardTokenIssuerAlias        /**       * Checks if a hard token profile is among a hard tokens issuers available token types.       *       * @param admin the administrator calling the function       * @param issuerid the id of the issuer to check.       * @param userdata the data of user about to be generated       *       * @throws UnavailableTokenException if users tokentype isn't among hard token issuers available tokentypes.       * @throws EJBException if a communication or other error occurs.         * @ejb.interface-method view-type="both"       */    public void getIsHardTokenProfileAvailableToIssuer(Admin admin, int issuerid, UserDataVO userdata) throws UnavailableTokenException{        debug(">getIsTokenTypeAvailableToIssuer(issuerid: " + issuerid + ", tokentype: " + userdata.getTokenType()+ ")");        boolean returnval = false;        ArrayList availabletokentypes = getHardTokenIssuerData(admin, issuerid).getHardTokenIssuer().getAvailableHardTokenProfiles();        for(int i=0; i < availabletokentypes.size(); i++){          if(((Integer) availabletokentypes.get(i)).intValue() == userdata.getTokenType())            returnval = true;        }        if(!returnval) {        	String msg = intres.getLocalizedMessage("hardtoken.unavailabletoken", userdata.getUsername());            	        	throw new UnavailableTokenException(msg);        }        debug("<getIsTokenTypeAvailableToIssuer()");    } // getIsTokenTypeAvailableToIssuer       /**       * Adds a hard token to the database       *       * @param admin the administrator calling the function       * @param tokensn The serialnumber of token.       * @param username the user owning the token.       * @param significantissuerdn indicates which CA the hard token should belong to.       * @param hardtokendata the hard token data       * @param certificates  a collection of certificates places in the hard token       * @param copyof indicates if the newly created token is a copy of an existing token. Use null if token is an original       *       * @throws EJBException if a communication or other error occurs.       * @throws HardTokenExistsException if tokensn already exists in databas.        * @ejb.interface-method view-type="both"        * @ejb.transaction type="Required"       */    public void addHardToken(Admin admin, String tokensn, String username, String significantissuerdn, int tokentype,  HardToken hardtokendata, Collection certificates, String copyof) throws HardTokenExistsException{        debug(">addHardToken(tokensn : " + tokensn + ")");		String bcdn = CertTools.stringToBCDNString(significantissuerdn);    	boolean exists = false;    	try {        	// We must actually check if there is one before we try to add it, because wls does not allow us to catch any errors if creating fails, that sux        	HardTokenDataLocal data = hardtokendatahome.findByPrimaryKey(tokensn);        	if (data != null) {        		exists = true;        	}    	} catch (FinderException e) {    		// This is what we hope will happen    	}    	if (!exists) {    		try {    			hardtokendatahome.create(tokensn, username,new java.util.Date(), new java.util.Date(), tokentype, bcdn, hardtokendata);    			if(certificates != null){    				Iterator i = certificates.iterator();    				while(i.hasNext()){    					addHardTokenCertificateMapping(admin, tokensn, (X509Certificate) i.next());    				}    			}    			if(copyof != null){    				hardtokenpropertyhome.create(tokensn, HardTokenPropertyEntityBean.PROPERTY_COPYOF,copyof);    			}    			String msg = intres.getLocalizedMessage("hardtoken.addedtoken", tokensn);            	    			getLogSession().log(admin, bcdn.hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),username, null, LogEntry.EVENT_INFO_HARDTOKENDATA,msg);    		}    		catch (Exception e) {    			String msg = intres.getLocalizedMessage("hardtoken.tokenexists", tokensn);            	    			getLogSession().log(admin, bcdn.hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),username, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,msg);    			throw new HardTokenExistsException("Tokensn : " + tokensn);    		}    	} else {    		String msg = intres.getLocalizedMessage("hardtoken.tokenexists", tokensn);            	    		getLogSession().log(admin, bcdn.hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),username, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,msg);    		throw new HardTokenExistsException("Tokensn : " + tokensn);    		    	}        debug("<addHardToken()");    } // addHardToken       /**       * changes a hard token data in the database       *       * @param admin the administrator calling the function       * @param tokensn The serialnumber of token.       * @param hardtokendata the hard token data       *       * @throws EJBException if a communication or other error occurs.       * @throws HardTokenDoesntExistsException if tokensn doesn't exists in databas.        * @ejb.interface-method view-type="both"        * @ejb.transaction type="Required"       */    public void changeHardToken(Admin admin, String tokensn, int tokentype, HardToken hardtokendata) throws HardTokenDoesntExistsException{        debug(">changeHardToken(tokensn : " + tokensn + ")");        int caid = LogConstants.INTERNALCAID;        try {            HardTokenDataLocal htd = hardtokendatahome.findByPrimaryKey(tokensn);            htd.setTokenType(tokentype);            htd.setHardToken(hardtokendata);            htd.setModifyTime(new java.util.Date());            caid = htd.getSignificantIssuerDN().hashCode();        	String msg = intres.getLocalizedMessage("hardtoken.changedtoken", tokensn);            	            getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date(),htd.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKENDATA,msg);        }        catch (Exception e) {        	String msg = intres.getLocalizedMessage("hardtoken.errorchangetoken", tokensn);            	        	getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,msg);        	throw new HardTokenDoesntExistsException("Tokensn : " + tokensn);        }        debug("<changeHardToken()");    } // changeHardToken       /**       * removes a hard token data from the database       *       * @param admin the administrator calling the function       * @param tokensn The serialnumber of token.       *       * @throws EJBException if a communication or other error occurs.       * @throws HardTokenDoesntExistsException if tokensn doesn't exists in databas.        * @ejb.interface-method view-type="both"        * @ejb.transaction type="Required"       */    public void removeHardToken(Admin admin, String tokensn) throws HardTokenDoesntExistsException{      debug(">removeHardToken(tokensn : " + tokensn + ")");      int caid = LogConstants.INTERNALCAID;      try{        HardTokenDataLocal htd = hardtokendatahome.findByPrimaryKey(tokensn);        caid = htd.getSignificantIssuerDN().hashCode();        htd.remove();        // Remove all certificate mappings.        removeHardTokenCertificateMappings(admin, tokensn);        // Remove all copyof references id property database.       try{        	hardtokenpropertyhome.findByProperty(tokensn, HardTokenPropertyEntityBean.PROPERTY_COPYOF).remove();        }catch(FinderException fe){}        try{          Collection copieslocal = hardtokenpropertyhome.findIdsByPropertyAndValue(HardTokenPropertyEntityBean.PROPERTY_COPYOF , tokensn);          Iterator iter = copieslocal.iterator();          while(iter.hasNext()){        	 ((HardTokenPropertyLocal) iter.next()).remove();           }        }catch(FinderException fe){}    	String msg = intres.getLocalizedMessage("hardtoken.removedtoken", tokensn);            	        getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_INFO_HARDTOKENDATA,msg);      }catch(Exception e){    	  String msg = intres.getLocalizedMessage("hardtoken.errorremovetoken", tokensn);            	    	  getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,msg);    	  throw new HardTokenDoesntExistsException("Tokensn : " + tokensn);      }      debug("<removeHardToken()");    } // removeHardToken       /**       * Checks if a hard token serialnumber exists in the database       *       * @param admin the administrator calling the function       * @param tokensn The serialnumber of token.       *       * @return true if it exists or false otherwise.       * @throws EJBException if a communication or other error occurs.        * @ejb.interface-method view-type="both"       */    public boolean existsHardToken(Admin admin, String tokensn){       debug(">existsHardToken(tokensn : " + tokensn + ")");       boolean ret = false;        try {            hardtokendatahome.findByPrimaryKey(tokensn);            ret = true;        } catch (javax.ejb.FinderException fe) {             ret=false;        } catch(Exception e){          throw new EJBException(e);        }       debug("<existsHardToken()");       return ret;    } // existsHardToken      /**       * returns hard token data for the specified tokensn       *       * @param admin the administrator calling the function       * @param tokensn The serialnumber of token.       *       * @return the hard token data or NULL if tokensn doesnt exists in database.       * @throws EJBException if a communication or other error occurs.       * @ejb.interface-method view-type="both"       */    public HardTokenData getHardToken(Admin admin, String tokensn){       debug("<getHardToken(tokensn :" + tokensn +")");                     // Check Approvals                     HardTokenData returnval = null;       HardTokenDataLocal htd = null;       try{         htd = hardtokendatahome.findByPrimaryKey(tokensn);         // Find Copyof         String copyof = null;         try{         	copyof = hardtokenpropertyhome.findByProperty(tokensn, HardTokenPropertyEntityBean.PROPERTY_COPYOF).getValue();         }catch(FinderException fe){}         ArrayList copies = null;         if(copyof == null){           //  Find Copies	  	   try{             Collection copieslocal = hardtokenpropertyhome.findIdsByPropertyAndValue(HardTokenPropertyEntityBean.PROPERTY_COPYOF , tokensn);             if(copieslocal.size() >0 ){               copies = new ArrayList();		       Iterator iter = copieslocal.iterator();               while(iter.hasNext()){           	      copies.add(((HardTokenPropertyLocal) iter.next()).getId());               }             }		   }catch(FinderException fe){}         }         if(htd != null){           returnval = new HardTokenData(htd.getTokenSN(),htd.getUsername(), htd.getCreateTime(),htd.getModifyTime(),htd.getTokenType(),htd.getHardToken(), copyof, copies);           String msg = intres.getLocalizedMessage("hardtoken.viewedtoken", tokensn);            	           getLogSession().log(admin, htd.getSignificantIssuerDN().hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),htd.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKENVIEWED,msg);         }       }catch(FinderException e){}       debug("<getHardToken()");       return returnval;    } // getHardToken      /**       * returns hard token data for the specified user       *       * @param admin the administrator calling the function       * @param username The username owning the tokens.       *       * @return a Collection of all hard token user data.       * @throws EJBException if a communication or other error occurs.       * @ejb.interface-method view-type="both"       */    public Collection getHardTokens(Admin admin, String username){       debug("<getHardToken(username :" + username +")");       ArrayList returnval = new ArrayList();       HardTokenDataLocal htd = null;       try{         Collection result = hardtokendatahome.findByUsername(username);         Iterator i = result.iterator();         while(i.hasNext()){           htd = (HardTokenDataLocal) i.next();           // Find Copyof           String copyof = null;           try{           	copyof = hardtokenpropertyhome.findByProperty(htd.getTokenSN(), HardTokenPropertyEntityBean.PROPERTY_COPYOF).getValue();           }catch(FinderException fe){}           ArrayList copies = null;           if(copyof == null){           	//  Find Copies           	 try{           		Collection copieslocal = hardtokenpropertyhome.findIdsByPropertyAndValue(HardTokenPropertyEntityBean.PROPERTY_COPYOF , htd.getTokenSN());           		if(copieslocal.size() >0 ){           			copies = new ArrayList();

⌨️ 快捷键说明

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