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

📄 localhardtokensessionbean.java

📁 JAVA做的J2EE下CA认证系统 基于EJB开发
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
       /**       * 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)          throw new UnavailableTokenException("Error hard token issuer cannot issue specified tokentype for user " + userdata.getUsername() + ". Change tokentype or issuer for user");        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);        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);            }            getLogSession().log(admin, bcdn.hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),username, null, LogEntry.EVENT_INFO_HARDTOKENDATA,"Hard token with serial number : " + tokensn + " added.");        }        catch (Exception e) {          getLogSession().log(admin, bcdn.hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),username, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,"Trying to add hard tokensn that already exists.");          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();            getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date(),htd.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKENDATA,"Hard token with serial number : " + tokensn + " changed.");        }        catch (Exception e) {            getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,"Error when trying to update token with sn : " + tokensn + ".");          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){}        getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_INFO_HARDTOKENDATA,"Hard token with sn " + tokensn + " removed.");      }catch(Exception e){         getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,"Error removing hard token with sn " + tokensn + ".");         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 +")");       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);           getLogSession().log(admin, htd.getSignificantIssuerDN().hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),htd.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKENVIEWED,"Hard token with sn " + tokensn + " viewed.");         }       }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();           			Iterator iter = copieslocal.iterator();           			while(iter.hasNext()){           				copies.add(((HardTokenPropertyLocal) iter.next()).getId());           			}           		}           	 }catch(FinderException fe){}           }           returnval.add(new HardTokenData(htd.getTokenSN(),htd.getUsername(), htd.getCreateTime(),htd.getModifyTime(),htd.getTokenType(),htd.getHardToken(),copyof, copies));           getLogSession().log(admin, htd.getSignificantIssuerDN().hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),htd.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKENVIEWED,"Hard token with sn " + htd.getTokenSN() + " viewed.");         }       }catch(FinderException e){}       debug("<getHardToken()");       return returnval;    } // getHardTokens    /**     *  Method that searches the database for a tokensn. It returns all hardtokens     * with a serialnumber that begins with the given searchpattern.     *     *  @param admin the administrator calling the function     *  @param searchpattern of begining of hard token sn     *  @return a Collection of username(String) matching the search string     * @ejb.interface-method view-type="both"     */    public Collection findHardTokenByTokenSerialNumber(Admin admin, String searchpattern){    	debug(">findHardTokenByTokenSerialNumber()");    	ArrayList returnval = new ArrayList();    	Connection con = null;    	PreparedStatement ps = null;    	ResultSet rs = null;

⌨️ 快捷键说明

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