📄 localhardtokensessionbean.java
字号:
debug(">getHardTokenIssuerAliases()"); ArrayList returnval = new ArrayList(); Collection result = null; Collection authorizedhardtokenprofiles = this.getAuthorizedHardTokenProfileIds(admin); HardTokenIssuerDataLocal htih = null; try{ result = hardtokenissuerhome.findAll(); if(result.size()>0){ Iterator i = result.iterator(); while(i.hasNext()){ htih = (HardTokenIssuerDataLocal) i.next(); if(authorizedhardtokenprofiles.containsAll(htih.getHardTokenIssuer().getAvailableHardTokenProfiles())) returnval.add(htih.getAlias()); } } Collections.sort(returnval); }catch(FinderException e){} debug("<getHardTokenIssuerAliases()"); return returnval; }// getHardTokenIssuerAliases /** * Returns the available hard token issuers authorized to the administrator. * * @return A treemap of available hard token issuers. * @throws EJBException if a communication or other error occurs. */ public TreeMap getHardTokenIssuers(Admin admin){ debug(">getHardTokenIssuers()"); Collection authorizedhardtokenprofiles = this.getAuthorizedHardTokenProfileIds(admin); TreeMap returnval = new TreeMap(); Collection result = null; try{ result = hardtokenissuerhome.findAll(); if(result.size()>0){ Iterator i = result.iterator(); while(i.hasNext()){ HardTokenIssuerDataLocal htih = (HardTokenIssuerDataLocal) i.next(); if(authorizedhardtokenprofiles.containsAll(htih.getHardTokenIssuer().getAvailableHardTokenProfiles())) returnval.put(htih.getAlias(), new HardTokenIssuerData(htih.getId().intValue(), htih.getAlias(), htih.getAdminGroupId(), htih.getHardTokenIssuer())); } } }catch(FinderException e){} debug("<getHardTokenIssuers()"); return returnval; } // getHardTokenIssuers /** * Returns the specified hard token issuer. * * @return the hard token issuer data or null if hard token issuer doesn't exists. * @throws EJBException if a communication or other error occurs. */ public HardTokenIssuerData getHardTokenIssuerData(Admin admin, String alias){ debug(">getHardTokenIssuerData(alias: " + alias + ")"); HardTokenIssuerData returnval = null; HardTokenIssuerDataLocal htih = null; try{ htih = hardtokenissuerhome.findByAlias(alias); if(htih != null){ returnval = new HardTokenIssuerData(htih.getId().intValue(), htih.getAlias(), htih.getAdminGroupId(), htih.getHardTokenIssuer()); } }catch(FinderException e){} debug("<getHardTokenIssuerData()"); return returnval; } // getHardTokenIssuerData /** * Returns the specified hard token issuer. * * @return the hard token issuer data or null if hard token issuer doesn't exists. * @throws EJBException if a communication or other error occurs. */ public HardTokenIssuerData getHardTokenIssuerData(Admin admin, int id){ debug(">getHardTokenIssuerData(id: " + id +")" ); HardTokenIssuerData returnval = null; HardTokenIssuerDataLocal htih = null; try{ htih = hardtokenissuerhome.findByPrimaryKey(new Integer(id)); if(htih != null){ returnval = new HardTokenIssuerData(htih.getId().intValue(), htih.getAlias(), htih.getAdminGroupId(), htih.getHardTokenIssuer()); } }catch(FinderException e){} debug("<getHardTokenIssuerData()"); return returnval; } // getHardTokenIssuerData /** * Returns the number of available hard token issuer. * * @return the number of available hard token issuer. * @throws EJBException if a communication or other error occurs. */ public int getNumberOfHardTokenIssuers(Admin admin){ debug(">getNumberOfHardTokenIssuers()"); int returnval =0; try{ returnval = (hardtokenissuerhome.findAll()).size(); }catch(FinderException e){} debug("<getNumberOfHardTokenIssuers()"); return returnval; } // getNumberOfHardTokenIssuers /** * Returns a hard token issuer id given its alias. * * @return id number of hard token issuer. * @throws EJBException if a communication or other error occurs. */ public int getHardTokenIssuerId(Admin admin, String alias){ debug(">getHardTokenIssuerId(alias: " + alias + ")"); int returnval = IHardTokenSessionRemote.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. */ 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 isserid, the id of the issuer to check. * @param userdata, the data of user about to be generated * * @throws UnavalableTokenException if users tokentype isn't among hard token issuers available tokentypes. * @throws EJBException if a communication or other error occurs. */ public void getIsHardTokenProfileAvailableToIssuer(Admin admin, int issuerid, UserAdminData 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 hardtoken, 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. */ 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 hardtoken, the hard token data * * @throws EJBException if a communication or other error occurs. * @throws HardTokenDoesntExistsException if tokensn doesn't exists in databas. */ public void changeHardToken(Admin admin, String tokensn, int tokentype, HardToken hardtokendata) throws HardTokenDoesntExistsException{ debug(">changeHardToken(tokensn : " + tokensn + ")"); int caid = ILogSessionLocal.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. */ public void removeHardToken(Admin admin, String tokensn) throws HardTokenDoesntExistsException{ debug(">removeHardToken(tokensn : " + tokensn + ")"); int caid = ILogSessionLocal.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()){ ((BasePropertyDataLocal) 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. */ 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. */ 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{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -