1 13 14 package org.ejbca.core.ejb.hardtoken; 15 16 import java.math.BigInteger ; 17 import java.security.cert.Certificate ; 18 import java.security.cert.X509Certificate ; 19 import java.sql.Connection ; 20 import java.sql.PreparedStatement ; 21 import java.sql.ResultSet ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import java.util.Date ; 26 import java.util.HashMap ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.Random ; 30 import java.util.TreeMap ; 31 32 import javax.ejb.CreateException ; 33 import javax.ejb.EJBException ; 34 import javax.ejb.FinderException ; 35 36 import org.ejbca.core.ejb.BaseSessionBean; 37 import org.ejbca.core.ejb.JNDINames; 38 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal; 39 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocalHome; 40 import org.ejbca.core.ejb.ca.store.CertificateDataBean; 41 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal; 42 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocalHome; 43 import org.ejbca.core.ejb.log.ILogSessionLocal; 44 import org.ejbca.core.ejb.log.ILogSessionLocalHome; 45 import org.ejbca.core.model.InternalResources; 46 import org.ejbca.core.model.SecConst; 47 import org.ejbca.core.model.authorization.AuthorizationDeniedException; 48 import org.ejbca.core.model.hardtoken.HardTokenData; 49 import org.ejbca.core.model.hardtoken.HardTokenDoesntExistsException; 50 import org.ejbca.core.model.hardtoken.HardTokenExistsException; 51 import org.ejbca.core.model.hardtoken.HardTokenIssuer; 52 import org.ejbca.core.model.hardtoken.HardTokenIssuerData; 53 import org.ejbca.core.model.hardtoken.HardTokenProfileExistsException; 54 import org.ejbca.core.model.hardtoken.UnavailableTokenException; 55 import org.ejbca.core.model.hardtoken.profiles.EIDProfile; 56 import org.ejbca.core.model.hardtoken.profiles.HardTokenProfile; 57 import org.ejbca.core.model.hardtoken.types.HardToken; 58 import org.ejbca.core.model.log.Admin; 59 import org.ejbca.core.model.log.LogConstants; 60 import org.ejbca.core.model.log.LogEntry; 61 import org.ejbca.core.model.ra.UserAdminConstants; 62 import org.ejbca.core.model.ra.UserDataVO; 63 import org.ejbca.util.CertTools; 64 import org.ejbca.util.JDBCUtil; 65 66 67 68 180 public class LocalHardTokenSessionBean extends BaseSessionBean { 181 182 public static final int NO_ISSUER = 0; 183 184 185 private static final InternalResources intres = InternalResources.getInstance(); 186 187 188 private HardTokenIssuerDataLocalHome hardtokenissuerhome = null; 189 190 191 private HardTokenDataLocalHome hardtokendatahome = null; 192 193 194 private HardTokenProfileDataLocalHome hardtokenprofilehome = null; 195 196 197 private HardTokenCertificateMapLocalHome hardtokencertificatemaphome = null; 198 199 200 private HardTokenPropertyLocalHome hardtokenpropertyhome = null; 201 202 203 private IAuthorizationSessionLocal authorizationsession = null; 204 205 206 private ICertificateStoreSessionLocal certificatestoresession = null; 207 208 209 private ILogSessionLocal logsession = null; 210 211 212 213 214 218 219 220 public void ejbCreate() throws CreateException { 221 try{ 222 hardtokenissuerhome = (HardTokenIssuerDataLocalHome) getLocator().getLocalHome(HardTokenIssuerDataLocalHome.COMP_NAME); 223 hardtokendatahome = (HardTokenDataLocalHome) getLocator().getLocalHome(HardTokenDataLocalHome.COMP_NAME); 224 hardtokencertificatemaphome = (HardTokenCertificateMapLocalHome) getLocator().getLocalHome(HardTokenCertificateMapLocalHome.COMP_NAME); 225 hardtokenprofilehome = (HardTokenProfileDataLocalHome) getLocator().getLocalHome(HardTokenProfileDataLocalHome.COMP_NAME); 226 hardtokenpropertyhome = (HardTokenPropertyLocalHome) getLocator().getLocalHome(HardTokenPropertyLocalHome.COMP_NAME); 227 }catch(Exception e){ 228 throw new EJBException (e); 229 } 230 } 231 232 233 236 private ILogSessionLocal getLogSession() { 237 if(logsession == null){ 238 try{ 239 ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME); 240 logsession = logsessionhome.create(); 241 }catch(Exception e){ 242 throw new EJBException (e); 243 } 244 } 245 return logsession; 246 } 248 251 private ICertificateStoreSessionLocal getCertificateStoreSession() { 252 if(certificatestoresession == null){ 253 try{ 254 ICertificateStoreSessionLocalHome certificatestoresessionhome = (ICertificateStoreSessionLocalHome) getLocator().getLocalHome(ICertificateStoreSessionLocalHome.COMP_NAME); 255 certificatestoresession = certificatestoresessionhome.create(); 256 }catch(Exception e){ 257 throw new EJBException (e); 258 } 259 } 260 return certificatestoresession; 261 } 263 266 private IAuthorizationSessionLocal getAuthorizationSession() { 267 if(authorizationsession == null){ 268 try{ 269 IAuthorizationSessionLocalHome authorizationsessionhome = (IAuthorizationSessionLocalHome) getLocator().getLocalHome(IAuthorizationSessionLocalHome.COMP_NAME); 270 authorizationsession = authorizationsessionhome.create(); 271 }catch(Exception e){ 272 throw new EJBException (e); 273 } 274 } 275 return authorizationsession; 276 } 278 279 280 281 282 289 public void addHardTokenProfile(Admin admin, String name, HardTokenProfile profile) throws HardTokenProfileExistsException{ 290 debug(">addHardTokenProfile(name: " + name + ")"); 291 addHardTokenProfile(admin,findFreeHardTokenProfileId().intValue(),name,profile); 292 debug("<addHardTokenProfile()"); 293 } 295 296 305 public void addHardTokenProfile(Admin admin, int profileid, String name, HardTokenProfile profile) throws HardTokenProfileExistsException{ 306 debug(">addHardTokenProfile(name: " + name + ", id: " + profileid +")"); 307 boolean success=false; 308 try{ 309 hardtokenprofilehome.findByName(name); 310 }catch(FinderException e){ 311 try{ 312 hardtokenprofilehome.findByPrimaryKey(new Integer (profileid)); 313 }catch(FinderException f){ 314 try{ 315 hardtokenprofilehome.create(new Integer (profileid), name, profile); 316 success = true; 317 }catch(CreateException g){ 318 error("Unexpected error creating new hard token profile: ", g); 319 } 320 } 321 } 322 323 if(success) { 324 String msg = intres.getLocalizedMessage("hardtoken.addedprofile", name); 325 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENPROFILEDATA, msg); 326 } else { 327 String msg = intres.getLocalizedMessage("hardtoken.erroraddprofile", name); 328 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENPROFILEDATA, msg); 329 } 330 331 if(!success) 332 throw new HardTokenProfileExistsException(); 333 debug("<addHardTokenProfile()"); 334 } 336 343 public void changeHardTokenProfile(Admin admin, String name, HardTokenProfile profile){ 344 debug(">changeHardTokenProfile(name: " + name + ")"); 345 boolean success = false; 346 try{ 347 HardTokenProfileDataLocal htp = hardtokenprofilehome.findByName(name); 348 htp.setHardTokenProfile(profile); 349 success = true; 350 }catch(FinderException e){} 351 352 if(success) { 353 String msg = intres.getLocalizedMessage("hardtoken.editedprofile", name); 354 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENPROFILEDATA, msg); 355 } else { 356 String msg = intres.getLocalizedMessage("hardtoken.erroreditprofile", name); 357 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENPROFILEDATA, msg); 358 } 359 360 debug("<changeHardTokenProfile()"); 361 } 363 371 public void cloneHardTokenProfile(Admin admin, String oldname, String newname) throws HardTokenProfileExistsException{ 372 debug(">cloneHardTokenProfile(name: " + oldname + ")"); 373 HardTokenProfile profiledata = null; 374 try{ 375 HardTokenProfileDataLocal htp = hardtokenprofilehome.findByName(oldname); 376 profiledata = (HardTokenProfile) htp.getHardTokenProfile().clone(); 377 378 try{ 379 addHardTokenProfile(admin, newname, profiledata); 380 String msg = intres.getLocalizedMessage("hardtoken.clonedprofile", newname, oldname); 381 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENPROFILEDATA, msg); 382 }catch(HardTokenProfileExistsException f){ 383 String msg = intres.getLocalizedMessage("hardtoken.errorcloneprofile", newname, oldname); 384 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENPROFILEDATA, msg); 385 throw f; 386 } 387 388 }catch(Exception e){ 389 throw new EJBException (e); 390 } 391 392 debug("<cloneHardTokenProfile()"); 393 } 395 402 public void removeHardTokenProfile(Admin admin, String name){ 403 debug(">removeHardTokenProfile(name: " + name + ")"); 404 try{ 405 HardTokenProfileDataLocal htp = hardtokenprofilehome.findByName(name); 406 htp.remove(); 407 String msg = intres.getLocalizedMessage("hardtoken.removedprofile", name); 408 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENPROFILEDATA,msg); 409 }catch(Exception e){ 410 String msg = intres.getLocalizedMessage("hardtoken.errorremoveprofile", name); 411 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENPROFILEDATA,msg,e); 412 } 413 debug("<removeHardTokenProfile()"); 414 } 416 424 public void renameHardTokenProfile(Admin admin, String oldname, String newname) throws HardTokenProfileExistsException{ 425 debug(">renameHardTokenProfile(from " + oldname + " to " + newname + ")"); 426 boolean success = false; 427 try{ 428 hardtokenprofilehome.findByName(newname); 429 }catch(FinderException e){ 430 try{ 431 HardTokenProfileDataLocal htp = hardtokenprofilehome.findByName(oldname); 432 htp.setName(newname); 433 success = true; 434 }catch(FinderException g){} 435 } 436 437 if(success) { 438 String msg = intres.getLocalizedMessage("hardtoken.renamedprofile", oldname, newname); 439 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENPROFILEDATA,msg); 440 } else { 441 String msg = intres.getLocalizedMessage("hardtoken.errorrenameprofile", oldname, newname); 442 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENPROFILEDATA, msg); 443 } 444 445 if(!success) 446 throw new HardTokenProfileExistsException(); 447 debug("<renameHardTokenProfile()"); 448 } 450 458 public Collection getAuthorizedHardTokenProfileIds(Admin admin){ 459 ArrayList returnval = new ArrayList (); 460 Collection result = null; 461 462 HashSet authorizedcertprofiles = new HashSet (getCertificateStoreSession().getAuthorizedCertificateProfileIds(admin, CertificateDataBean.CERTTYPE_HARDTOKEN)); 463 HashSet authorizedcaids = new HashSet (this.getAuthorizationSession().getAuthorizedCAIds(admin)); 464 465 try{ 466 result = this.hardtokenprofilehome.findAll(); 467 Iterator i = result.iterator(); 468 while(i.hasNext()){ 469 HardTokenProfileDataLocal next = (HardTokenProfileDataLocal) i.next(); 470 HardTokenProfile profile = next.getHardTokenProfile(); 471 472 if(profile instanceof EIDProfile){ 473 if(authorizedcertprofiles.containsAll(((EIDProfile) profile).getAllCertificateProfileIds()) && 474 authorizedcaids.containsAll(((EIDProfile) profile).getAllCAIds())){ 475 returnval.add(next.getId()); 476 } 477 }else{ 478 } 480 } 481 }catch(FinderException e){} 482 483 484 485 return returnval; 486 } 488 492 public HashMap getHardTokenProfileIdToNameMap(Admin admin){ 493 HashMap returnval = new HashMap (); 494 Collection result = null; 495 496 try{ 497 result = hardtokenprofilehome.findAll(); 498 Iterator i = result.iterator(); 499 while(i.hasNext()){ 500 HardTokenProfileDataLocal next = (HardTokenProfileDataLocal) i.next(); 501 returnval.put(next.getId(),next.getName()); 502 } 503 }catch(FinderException e){} 504 return returnval; 505 } 507 508 512 public HardTokenProfile getHardTokenProfile(Admin admin, String name){ 513 HardTokenProfile returnval=null; 514 515 try{ 516 returnval = (hardtokenprofilehome.findByName(name)).getHardTokenProfile(); 517 } catch(FinderException e){ 518 } 520 return returnval; 521 } 523 527 public HardTokenProfile getHardTokenProfile(Admin admin, int id){ 528 HardTokenProfile returnval=null; 529 530 try{ 531 returnval = (hardtokenprofilehome.findByPrimaryKey(new Integer (id))).getHardTokenProfile(); 532 } catch(FinderException e){ 533 } 535 return returnval; 536 } 538 543 public int getHardTokenProfileUpdateCount(Admin admin, int hardtokenprofileid){ 544 int returnval = 0; 545 546 try{ 547 returnval = (hardtokenprofilehome.findByPrimaryKey(new Integer (hardtokenprofileid))).getUpdateCounter(); 548 }catch(FinderException e){} 549 550 return returnval; 551 } 552 553 554 561 public int getHardTokenProfileId(Admin admin, String name){ 562 int returnval = 0; 563 564 try{ 565 Integer id = (hardtokenprofilehome.findByName(name)).getId(); 566 returnval = id.intValue(); 567 }catch(FinderException e){} 568 569 return returnval; 570 } 572 579 public String getHardTokenProfileName(Admin admin, int id){ 580 debug(">getHardTokenProfileName(id: " + id + ")"); 581 String returnval = null; 582 HardTokenProfileDataLocal htp = null; 583 try{ 584 htp = hardtokenprofilehome.findByPrimaryKey(new Integer (id)); 585 if(htp != null){ 586 returnval = htp.getName(); 587 } 588 }catch(FinderException e){} 589 590 debug("<getHardTokenProfileName()"); 591 return returnval; 592 } 594 595 603 604 public boolean addHardTokenIssuer(Admin admin, String alias, int admingroupid, HardTokenIssuer issuerdata){ 605 debug(">addHardTokenIssuer(alias: " + alias + ")"); 606 boolean returnval=false; 607 try{ 608 hardtokenissuerhome.findByAlias(alias); 609 }catch(FinderException e){ 610 try{ 611 hardtokenissuerhome.create(findFreeHardTokenIssuerId(), alias, admingroupid, issuerdata); 612 returnval = true; 613 }catch(CreateException g){} 614 } 615 616 if(returnval) { 617 String msg = intres.getLocalizedMessage("hardtoken.addedissuer", alias); 618 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENISSUERDATA,msg); 619 } else { 620 String msg = intres.getLocalizedMessage("hardtoken.erroraddissuer", alias); 621 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENISSUERDATA,msg); 622 } 623 624 debug("<addHardTokenIssuer()"); 625 return returnval; 626 } 628 636 637 public boolean changeHardTokenIssuer(Admin admin, String alias, HardTokenIssuer issuerdata){ 638 debug(">changeHardTokenIssuer(alias: " + alias + ")"); 639 boolean returnvalue = false; 640 try{ 641 HardTokenIssuerDataLocal htih = hardtokenissuerhome.findByAlias(alias); 642 htih.setHardTokenIssuer(issuerdata); 643 returnvalue = true; 644 }catch(FinderException e){} 645 646 if(returnvalue) { 647 String msg = intres.getLocalizedMessage("hardtoken.editedissuer", alias); 648 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENISSUERDATA,msg); 649 } else { 650 String msg = intres.getLocalizedMessage("hardtoken.erroreditissuer", alias); 651 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENISSUERDATA,msg); 652 } 653 654 debug("<changeHardTokenIssuer()"); 655 return returnvalue; 656 } 658 666 public boolean cloneHardTokenIssuer(Admin admin, String oldalias, String newalias, int admingroupid){ 667 debug(">cloneHardTokenIssuer(alias: " + oldalias + ")"); 668 HardTokenIssuer issuerdata = null; 669 boolean returnval = false; 670 try{ 671 HardTokenIssuerDataLocal htih = hardtokenissuerhome.findByAlias(oldalias); 672 issuerdata = (HardTokenIssuer) htih.getHardTokenIssuer().clone(); 673 674 returnval = addHardTokenIssuer(admin, newalias, admingroupid, issuerdata); 675 if(returnval) { 676 String msg = intres.getLocalizedMessage("hardtoken.clonedissuer", newalias, oldalias); 677 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENISSUERDATA,msg); 678 } else { 679 String msg = intres.getLocalizedMessage("hardtoken.errorcloneissuer", newalias, oldalias); 680 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENISSUERDATA,msg); 681 } 682 }catch(Exception e){ 683 throw new EJBException (e); 684 } 685 686 debug("<cloneHardTokenIssuer()"); 687 return returnval; 688 } 690 697 public void removeHardTokenIssuer(Admin admin, String alias){ 698 debug(">removeHardTokenIssuer(alias: " + alias + ")"); 699 try{ 700 HardTokenIssuerDataLocal htih = hardtokenissuerhome.findByAlias(alias); 701 htih.remove(); 702 String msg = intres.getLocalizedMessage("hardtoken.removedissuer", alias); 703 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENISSUERDATA,msg); 704 }catch(Exception e){ 705 String msg = intres.getLocalizedMessage("hardtoken.errorremoveissuer", alias); 706 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENISSUERDATA,msg,e); 707 } 708 debug("<removeHardTokenIssuer()"); 709 } 711 719 public boolean renameHardTokenIssuer(Admin admin, String oldalias, String newalias, 720 int newadmingroupid){ 721 debug(">renameHardTokenIssuer(from " + oldalias + " to " + newalias + ")"); 722 boolean returnvalue = false; 723 try{ 724 hardtokenissuerhome.findByAlias(newalias); 725 }catch(FinderException e){ 726 try{ 727 HardTokenIssuerDataLocal htih = hardtokenissuerhome.findByAlias(oldalias); 728 htih.setAlias(newalias); 729 htih.setAdminGroupId(newadmingroupid); 730 returnvalue = true; 731 }catch(FinderException g){} 732 } 733 734 if(returnvalue) { 735 String msg = intres.getLocalizedMessage("hardtoken.renameissuer", oldalias, newalias); 736 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENISSUERDATA,msg ); 737 } else { 738 String msg = intres.getLocalizedMessage("hardtoken.errorrenameissuer", oldalias, newalias); 739 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENISSUERDATA,msg); 740 } 741 742 debug("<renameHardTokenIssuer()"); 743 return returnvalue; 744 } 746 755 public boolean getAuthorizedToHardTokenIssuer(Admin admin, String alias){ 756 debug(">getAuthorizedToHardTokenIssuer(" + alias + ")"); 757 boolean returnval = false; 758 try{ 759 760 int admingroupid = hardtokenissuerhome.findByAlias(alias).getAdminGroupId(); 761 returnval = getAuthorizationSession().isAuthorizedNoLog(admin, "/hardtoken_functionality/issue_hardtokens"); 762 returnval = returnval && authorizationsession.existsAdministratorInGroup(admin, admingroupid); 763 }catch(FinderException fe){} 764 catch(AuthorizationDeniedException ade){} 765 debug("<getAuthorizedToHardTokenIssuer(" + returnval + ")"); 766 return returnval; 767 } 768 769 776 public Collection getHardTokenIssuerDatas(Admin admin){ 777 debug(">getHardTokenIssuerDatas()"); 778 ArrayList returnval = new ArrayList (); 779 Collection result = null; 780 HardTokenIssuerDataLocal htih = null; 781 Collection authorizedhardtokenprofiles = this.getAuthorizedHardTokenProfileIds(admin); 782 try{ 783 result = hardtokenissuerhome.findAll(); 784 if(result.size()>0){ 785 Iterator i = result.iterator(); 786 while(i.hasNext()){ 787 htih = (HardTokenIssuerDataLocal) i.next(); 788 if(authorizedhardtokenprofiles.containsAll(htih.getHardTokenIssuer().getAvailableHardTokenProfiles())) 789 returnval.add(new HardTokenIssuerData(htih.getId().intValue(), htih.getAlias(), htih.getAdminGroupId(), htih.getHardTokenIssuer())); 790 } 791 } 792 Collections.sort(returnval); 793 }catch(FinderException e){} 794 795 debug("<getHardTokenIssuerDatas()"); 796 return returnval; 797 } 799 806 public Collection getHardTokenIssuerAliases(Admin admin){ 807 debug(">getHardTokenIssuerAliases()"); 808 ArrayList returnval = new ArrayList (); 809 Collection result = null; 810 Collection authorizedhardtokenprofiles = this.getAuthorizedHardTokenProfileIds(admin); 811 HardTokenIssuerDataLocal htih = null; 812 try{ 813 result = hardtokenissuerhome.findAll(); 814 if(result.size()>0){ 815 Iterator i = result.iterator(); 816 while(i.hasNext()){ 817 htih = (HardTokenIssuerDataLocal) i.next(); 818 if(authorizedhardtokenprofiles.containsAll(htih.getHardTokenIssuer().getAvailableHardTokenProfiles())) 819 returnval.add(htih.getAlias()); 820 } 821 } 822 Collections.sort(returnval); 823 }catch(FinderException e){} 824 825 debug("<getHardTokenIssuerAliases()"); 826 return returnval; 827 } 829 836 public TreeMap getHardTokenIssuers(Admin admin){ 837 debug(">getHardTokenIssuers()"); 838 Collection authorizedhardtokenprofiles = this.getAuthorizedHardTokenProfileIds(admin); 839 TreeMap returnval = new TreeMap (); 840 Collection result = null; 841 try{ 842 result = hardtokenissuerhome.findAll(); 843 if(result.size()>0){ 844 Iterator i = result.iterator(); 845 while(i.hasNext()){ 846 HardTokenIssuerDataLocal htih = (HardTokenIssuerDataLocal) i.next(); 847 if(authorizedhardtokenprofiles.containsAll(htih.getHardTokenIssuer().getAvailableHardTokenProfiles())) 848 returnval.put(htih.getAlias(), new HardTokenIssuerData(htih.getId().intValue(), htih.getAlias(), htih.getAdminGroupId(), htih.getHardTokenIssuer())); 849 } 850 } 851 }catch(FinderException e){} 852 853 debug("<getHardTokenIssuers()"); 854 return returnval; 855 } 857 864 public HardTokenIssuerData getHardTokenIssuerData(Admin admin, String alias){ 865 debug(">getHardTokenIssuerData(alias: " + alias + ")"); 866 HardTokenIssuerData returnval = null; 867 HardTokenIssuerDataLocal htih = null; 868 try{ 869 htih = hardtokenissuerhome.findByAlias(alias); 870 if(htih != null){ 871 returnval = new HardTokenIssuerData(htih.getId().intValue(), htih.getAlias(), htih.getAdminGroupId(), htih.getHardTokenIssuer()); 872 } 873 }catch(FinderException e){} 874 875 debug("<getHardTokenIssuerData()"); 876 return returnval; 877 } 879 886 public HardTokenIssuerData getHardTokenIssuerData(Admin admin, int id){ 887 debug(">getHardTokenIssuerData(id: " + id +")" ); 888 HardTokenIssuerData returnval = null; 889 HardTokenIssuerDataLocal htih = null; 890 try{ 891 htih = hardtokenissuerhome.findByPrimaryKey(new Integer (id)); 892 if(htih != null){ 893 returnval = new HardTokenIssuerData(htih.getId().intValue(), htih.getAlias(), htih.getAdminGroupId(), htih.getHardTokenIssuer()); 894 } 895 }catch(FinderException e){} 896 897 debug("<getHardTokenIssuerData()"); 898 return returnval; 899 } 901 902 909 public int getNumberOfHardTokenIssuers(Admin admin){ 910 debug(">getNumberOfHardTokenIssuers()"); 911 int returnval =0; 912 try{ 913 returnval = (hardtokenissuerhome.findAll()).size(); 914 }catch(FinderException e){} 915 916 debug("<getNumberOfHardTokenIssuers()"); 917 return returnval; 918 } 920 927 public int getHardTokenIssuerId(Admin admin, String alias){ 928 debug(">getHardTokenIssuerId(alias: " + alias + ")"); 929 int returnval = NO_ISSUER; 930 HardTokenIssuerDataLocal htih = null; 931 try{ 932 htih = hardtokenissuerhome.findByAlias(alias); 933 if(htih != null){ 934 returnval = htih.getId().intValue(); 935 } 936 }catch(FinderException e){} 937 938 debug("<getHardTokenIssuerId()"); 939 return returnval; 940 } 942 949 public String getHardTokenIssuerAlias(Admin admin, int id){ 950 debug(">getHardTokenIssuerAlias(id: " + id + ")"); 951 String returnval = null; 952 HardTokenIssuerDataLocal htih = null; 953 try{ 954 htih = hardtokenissuerhome.findByPrimaryKey(new Integer (id)); 955 if(htih != null){ 956 returnval = htih.getAlias(); 957 } 958 }catch(FinderException e){} 959 960 debug("<getHardTokenIssuerAlias()"); 961 return returnval; 962 } 964 975 976 public void getIsHardTokenProfileAvailableToIssuer(Admin admin, int issuerid, UserDataVO userdata) throws UnavailableTokenException{ 977 debug(">getIsTokenTypeAvailableToIssuer(issuerid: " + issuerid + ", tokentype: " + userdata.getTokenType()+ ")"); 978 boolean returnval = false; 979 ArrayList availabletokentypes = getHardTokenIssuerData(admin, issuerid).getHardTokenIssuer().getAvailableHardTokenProfiles(); 980 981 for(int i=0; i < availabletokentypes.size(); i++){ 982 if(((Integer ) availabletokentypes.get(i)).intValue() == userdata.getTokenType()) 983 returnval = true; 984 } 985 986 if(!returnval) { 987 String msg = intres.getLocalizedMessage("hardtoken.unavailabletoken", userdata.getUsername()); 988 throw new UnavailableTokenException(msg); 989 } 990 debug("<getIsTokenTypeAvailableToIssuer()"); 991 } 993 1009 public void addHardToken(Admin admin, String tokensn, String username, String significantissuerdn, int tokentype, HardToken hardtokendata, Collection certificates, String copyof) throws HardTokenExistsException{ 1010 debug(">addHardToken(tokensn : " + tokensn + ")"); 1011 String bcdn = CertTools.stringToBCDNString(significantissuerdn); 1012 boolean exists = false; 1013 try { 1014 HardTokenDataLocal data = hardtokendatahome.findByPrimaryKey(tokensn); 1016 if (data != null) { 1017 exists = true; 1018 } 1019 } catch (FinderException e) { 1020 } 1022 if (!exists) { 1023 try { 1024 hardtokendatahome.create(tokensn, username,new java.util.Date (), new java.util.Date (), tokentype, bcdn, hardtokendata); 1025 if(certificates != null){ 1026 Iterator i = certificates.iterator(); 1027 while(i.hasNext()){ 1028 addHardTokenCertificateMapping(admin, tokensn, (X509Certificate ) i.next()); 1029 } 1030 } 1031 if(copyof != null){ 1032 hardtokenpropertyhome.create(tokensn, HardTokenPropertyEntityBean.PROPERTY_COPYOF,copyof); 1033 } 1034 String msg = intres.getLocalizedMessage("hardtoken.addedtoken", tokensn); 1035 getLogSession().log(admin, bcdn.hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),username, null, LogEntry.EVENT_INFO_HARDTOKENDATA,msg); 1036 } 1037 catch (Exception e) { 1038 String msg = intres.getLocalizedMessage("hardtoken.tokenexists", tokensn); 1039 getLogSession().log(admin, bcdn.hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),username, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,msg); 1040 throw new HardTokenExistsException("Tokensn : " + tokensn); 1041 } 1042 } else { 1043 String msg = intres.getLocalizedMessage("hardtoken.tokenexists", tokensn); 1044 getLogSession().log(admin, bcdn.hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),username, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,msg); 1045 throw new HardTokenExistsException("Tokensn : " + tokensn); 1046 } 1047 debug("<addHardToken()"); 1048 } 1050 1062 public void changeHardToken(Admin admin, String tokensn, int tokentype, HardToken hardtokendata) throws HardTokenDoesntExistsException{ 1063 debug(">changeHardToken(tokensn : " + tokensn + ")"); 1064 int caid = LogConstants.INTERNALCAID; 1065 try { 1066 HardTokenDataLocal htd = hardtokendatahome.findByPrimaryKey(tokensn); 1067 htd.setTokenType(tokentype); 1068 htd.setHardToken(hardtokendata); 1069 htd.setModifyTime(new java.util.Date ()); 1070 caid = htd.getSignificantIssuerDN().hashCode(); 1071 String msg = intres.getLocalizedMessage("hardtoken.changedtoken", tokensn); 1072 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),htd.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKENDATA,msg); 1073 } 1074 catch (Exception e) { 1075 String msg = intres.getLocalizedMessage("hardtoken.errorchangetoken", tokensn); 1076 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,msg); 1077 throw new HardTokenDoesntExistsException("Tokensn : " + tokensn); 1078 } 1079 debug("<changeHardToken()"); 1080 } 1082 1093 public void removeHardToken(Admin admin, String tokensn) throws HardTokenDoesntExistsException{ 1094 debug(">removeHardToken(tokensn : " + tokensn + ")"); 1095 int caid = LogConstants.INTERNALCAID; 1096 try{ 1097 HardTokenDataLocal htd = hardtokendatahome.findByPrimaryKey(tokensn); 1098 caid = htd.getSignificantIssuerDN().hashCode(); 1099 htd.remove(); 1100 1101 removeHardTokenCertificateMappings(admin, tokensn); 1103 1104 1105 try{ 1107 hardtokenpropertyhome.findByProperty(tokensn, HardTokenPropertyEntityBean.PROPERTY_COPYOF).remove(); 1108 }catch(FinderException fe){} 1109 try{ 1110 Collection copieslocal = hardtokenpropertyhome.findIdsByPropertyAndValue(HardTokenPropertyEntityBean.PROPERTY_COPYOF , tokensn); 1111 Iterator iter = copieslocal.iterator(); 1112 while(iter.hasNext()){ 1113 ((HardTokenPropertyLocal) iter.next()).remove(); 1114 } 1115 }catch(FinderException fe){} 1116 String msg = intres.getLocalizedMessage("hardtoken.removedtoken", tokensn); 1117 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENDATA,msg); 1118 }catch(Exception e){ 1119 String msg = intres.getLocalizedMessage("hardtoken.errorremovetoken", tokensn); 1120 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENDATA,msg); 1121 throw new HardTokenDoesntExistsException("Tokensn : " + tokensn); 1122 } 1123 debug("<removeHardToken()"); 1124 } 1126 1136 public boolean existsHardToken(Admin admin, String tokensn){ 1137 debug(">existsHardToken(tokensn : " + tokensn + ")"); 1138 boolean ret = false; 1139 try { 1140 hardtokendatahome.findByPrimaryKey(tokensn); 1141 ret = true; 1142 } catch (javax.ejb.FinderException fe) { 1143 ret=false; 1144 } catch(Exception e){ 1145 throw new EJBException (e); 1146 } 1147 debug("<existsHardToken()"); 1148 return ret; 1149 } 1151 1161 public HardTokenData getHardToken(Admin admin, String tokensn){ 1162 debug("<getHardToken(tokensn :" + tokensn +")"); 1163 1164 1165 1167 HardTokenData returnval = null; 1168 HardTokenDataLocal htd = null; 1169 try{ 1170 htd = hardtokendatahome.findByPrimaryKey(tokensn); 1171 1172 String copyof = null; 1174 try{ 1175 copyof = hardtokenpropertyhome.findByProperty(tokensn, HardTokenPropertyEntityBean.PROPERTY_COPYOF).getValue(); 1176 }catch(FinderException fe){} 1177 1178 ArrayList copies = null; 1179 if(copyof == null){ 1180 try{ 1182 Collection copieslocal = hardtokenpropertyhome.findIdsByPropertyAndValue(HardTokenPropertyEntityBean.PROPERTY_COPYOF , tokensn); 1183 if(copieslocal.size() >0 ){ 1184 copies = new ArrayList (); 1185 Iterator iter = copieslocal.iterator(); 1186 while(iter.hasNext()){ 1187 copies.add(((HardTokenPropertyLocal) iter.next()).getId()); 1188 } 1189 } 1190 }catch(FinderException fe){} 1191 } 1192 1193 if(htd != null){ 1194 returnval = new HardTokenData(htd.getTokenSN(),htd.getUsername(), htd.getCreateTime(),htd.getModifyTime(),htd.getTokenType(),htd.getHardToken(), copyof, copies); 1195 String msg = intres.getLocalizedMessage("hardtoken.viewedtoken", tokensn); 1196 getLogSession().log(admin, htd.getSignificantIssuerDN().hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),htd.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKENVIEWED,msg); 1197 } 1198 }catch(FinderException e){} 1199 1200 debug("<getHardToken()"); 1201 return returnval; 1202 } 1204 1214 public Collection getHardTokens(Admin admin, String username){ 1215 debug("<getHardToken(username :" + username +")"); 1216 ArrayList returnval = new ArrayList (); 1217 HardTokenDataLocal htd = null; 1218 try{ 1219 Collection result = hardtokendatahome.findByUsername(username); 1220 Iterator i = result.iterator(); 1221 while(i.hasNext()){ 1222 htd = (HardTokenDataLocal) i.next(); 1223 String copyof = null; 1225 try{ 1226 copyof = hardtokenpropertyhome.findByProperty(htd.getTokenSN(), HardTokenPropertyEntityBean.PROPERTY_COPYOF).getValue(); 1227 }catch(FinderException fe){} 1228 1229 1230 ArrayList copies = null; 1231 if(copyof == null){ 1232 try{ 1234 Collection copieslocal = hardtokenpropertyhome.findIdsByPropertyAndValue(HardTokenPropertyEntityBean.PROPERTY_COPYOF , htd.getTokenSN()); 1235 if(copieslocal.size() >0 ){ 1236 copies = new ArrayList (); 1237 Iterator iter = copieslocal.iterator(); 1238 while(iter.hasNext()){ 1239 copies.add(((HardTokenPropertyLocal) iter.next()).getId()); 1240 } 1241 } 1242 }catch(FinderException fe){} 1243 } 1244 1245 returnval.add(new HardTokenData(htd.getTokenSN(),htd.getUsername(), htd.getCreateTime(),htd.getModifyTime(),htd.getTokenType(),htd.getHardToken(),copyof, copies)); 1246 String msg = intres.getLocalizedMessage("hardtoken.viewedtoken", htd.getTokenSN()); 1247 getLogSession().log(admin, htd.getSignificantIssuerDN().hashCode(), LogEntry.MODULE_HARDTOKEN, new java.util.Date (),htd.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKENVIEWED,msg); 1248 } 1249 }catch(FinderException e){} 1250 1251 debug("<getHardToken()"); 1252 return returnval; 1253 } 1255 1264 1265 public Collection findHardTokenByTokenSerialNumber(Admin admin, String searchpattern){ 1266 debug(">findHardTokenByTokenSerialNumber()"); 1267 ArrayList returnval = new ArrayList (); 1268 Connection con = null; 1269 PreparedStatement ps = null; 1270 ResultSet rs = null; 1271 try{ 1272 con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE); 1274 ps = con.prepareStatement("select distinct username from HardTokenData where tokenSN LIKE '%" + searchpattern + "%'"); 1275 rs = ps.executeQuery(); 1277 while(rs.next() && returnval.size() <= UserAdminConstants.MAXIMUM_QUERY_ROWCOUNT){ 1279 returnval.add(rs.getString(1)); 1280 } 1281 debug("<findHardTokenByTokenSerialNumber()"); 1282 return returnval; 1283 1284 }catch(Exception e){ 1285 throw new EJBException (e); 1286 }finally{ 1287 JDBCUtil.close(con, ps, rs); 1288 } 1289 1290 } 1291 1292 1303 public void addHardTokenCertificateMapping(Admin admin, String tokensn, X509Certificate certificate){ 1304 String certificatesn = certificate.getSerialNumber().toString(16); 1305 debug(">addHardTokenCertificateMapping(certificatesn : "+ certificatesn +", tokensn : " + tokensn + ")"); 1306 int caid = CertTools.getIssuerDN(certificate).hashCode(); 1307 String fp = CertTools.getFingerprintAsString(certificate); 1308 boolean exists = false; 1309 try { 1310 HardTokenCertificateMapLocal data = hardtokencertificatemaphome.findByPrimaryKey(fp); 1312 if (data != null) { 1313 exists = true; 1314 } 1315 } catch (FinderException e) { 1316 } 1318 if (!exists) { 1319 try { 1320 hardtokencertificatemaphome.create(fp,tokensn); 1321 String msg = intres.getLocalizedMessage("hardtoken.addedtokencertmapping", certificatesn, tokensn); 1322 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENCERTIFICATEMAP,msg); 1323 } catch (Exception e) { 1324 String msg = intres.getLocalizedMessage("hardtoken.erroraddtokencertmapping", certificatesn, tokensn); 1325 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENCERTIFICATEMAP,msg); 1326 } 1327 } else { 1328 String msg = intres.getLocalizedMessage("hardtoken.erroraddtokencertmapping", certificatesn, tokensn); 1329 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENCERTIFICATEMAP,msg); 1330 } 1331 debug("<addHardTokenCertificateMapping()"); 1332 } 1334 1345 public void removeHardTokenCertificateMapping(Admin admin, X509Certificate certificate){ 1346 String certificatesn = certificate.getSerialNumber().toString(16); 1347 debug(">removeHardTokenCertificateMapping(Certificatesn: " + certificatesn + ")"); 1348 int caid = CertTools.getIssuerDN(certificate).hashCode(); 1349 try{ 1350 HardTokenCertificateMapLocal htcm =hardtokencertificatemaphome.findByPrimaryKey(CertTools.getFingerprintAsString(certificate)); 1351 htcm.remove(); 1352 String msg = intres.getLocalizedMessage("hardtoken.removedtokencertmappingcert", certificatesn); 1353 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENCERTIFICATEMAP, msg); 1354 }catch(Exception e){ 1355 try{ 1356 String msg = intres.getLocalizedMessage("hardtoken.errorremovetokencertmappingcert", certificatesn); 1357 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENCERTIFICATEMAP, msg); 1358 }catch(Exception re){ 1359 throw new EJBException (e); 1360 } 1361 } 1362 debug("<removeHardTokenCertificateMapping()"); 1363 } 1365 1366 1375 private void removeHardTokenCertificateMappings(Admin admin, String tokensn){ 1376 debug(">removeHardTokenCertificateMappings(tokensn: " + tokensn + ")"); 1377 int caid = admin.getCaId(); 1378 try{ 1379 Iterator result = hardtokencertificatemaphome.findByTokenSN(tokensn).iterator(); 1380 while(result.hasNext()){ 1381 HardTokenCertificateMapLocal htcm = (HardTokenCertificateMapLocal) result.next(); 1382 htcm.remove(); 1383 1384 } 1385 String msg = intres.getLocalizedMessage("hardtoken.removedtokencertmappingtoken", tokensn); 1386 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_INFO_HARDTOKENCERTIFICATEMAP, msg); 1387 }catch(Exception e){ 1388 try{ 1389 String msg = intres.getLocalizedMessage("hardtoken.errorremovetokencertmappingtoken", tokensn); 1390 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_HARDTOKENCERTIFICATEMAP, msg); 1391 }catch(Exception re){ 1392 throw new EJBException (e); 1393 } 1394 } 1395 debug("<removeHardTokenCertificateMappings()"); 1396 } 1398 1408 public Collection findCertificatesInHardToken(Admin admin, String tokensn){ 1409 debug("<findCertificatesInHardToken(username :" + tokensn +")"); 1410 ArrayList returnval = new ArrayList (); 1411 HardTokenCertificateMapLocal htcm = null; 1412 try{ 1413 Collection result = hardtokencertificatemaphome.findByTokenSN(tokensn); 1414 Iterator i = result.iterator(); 1415 while(i.hasNext()){ 1416 htcm = (HardTokenCertificateMapLocal) i.next(); 1417 Certificate cert = getCertificateStoreSession().findCertificateByFingerprint(admin, htcm.getCertificateFingerprint()); 1418 if (cert != null) { 1419 returnval.add(cert); 1420 } 1421 } 1422 }catch(Exception e){ 1423 throw new EJBException (e); 1424 } 1425 1426 debug("<findCertificatesInHardToken()"); 1427 return returnval; 1428 } 1430 1441 public String findHardTokenByCertificateSNIssuerDN(Admin admin, BigInteger certificatesn, String issuerdn){ 1442 debug("<findHardTokenByCertificateSNIssuerDN(certificatesn :" + certificatesn + ", issuerdn :" + issuerdn+ ")"); 1443 String returnval = null; 1444 HardTokenCertificateMapLocal htcm = null; 1445 try{ 1446 X509Certificate cert = (X509Certificate ) getCertificateStoreSession().findCertificateByIssuerAndSerno(admin,issuerdn,certificatesn); 1447 if(cert != null){ 1448 htcm = hardtokencertificatemaphome.findByPrimaryKey(CertTools.getFingerprintAsString(cert)); 1449 if(htcm != null){ 1450 returnval = htcm.getTokenSN(); 1451 } 1452 } 1453 }catch(Exception e){ 1454 throw new EJBException (e); 1455 } 1456 1457 debug("<findHardTokenByCertificateSNIssuerDN()"); 1458 return returnval; 1459 } 1461 1462 1472 public void tokenGenerated(Admin admin, String tokensn, String username, String significantissuerdn){ 1473 int caid = CertTools.stringToBCDNString(significantissuerdn).hashCode(); 1474 try{ 1475 String msg = intres.getLocalizedMessage("hardtoken.generatedtoken", tokensn); 1476 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),username, null, LogEntry.EVENT_INFO_HARDTOKENGENERATED, msg); 1477 }catch(Exception e){ 1478 throw new EJBException (e); 1479 } 1480 } 1482 1492 public void errorWhenGeneratingToken(Admin admin, String tokensn, String username, String significantissuerdn){ 1493 int caid = CertTools.stringToBCDNString(significantissuerdn).hashCode(); 1494 try{ 1495 String msg = intres.getLocalizedMessage("hardtoken.errorgeneratetoken", tokensn); 1496 getLogSession().log(admin, caid, LogEntry.MODULE_HARDTOKEN, new java.util.Date (),username, null, LogEntry.EVENT_ERROR_HARDTOKENGENERATED, msg); 1497 }catch(Exception e){ 1498 throw new EJBException (e); 1499 } 1500 } 1502 1503 1511 public boolean existsCertificateProfileInHardTokenProfiles(Admin admin, int id){ 1512 HardTokenProfile profile = null; 1513 Collection certprofiles=null; 1514 boolean exists = false; 1515 try{ 1516 Collection result = hardtokenprofilehome.findAll(); 1517 Iterator i = result.iterator(); 1518 while(i.hasNext() && !exists){ 1519 profile = ((HardTokenProfileDataLocal) i.next()).getHardTokenProfile(); 1520 if(profile instanceof EIDProfile){ 1521 certprofiles = ((EIDProfile) profile).getAllCertificateProfileIds(); 1522 if(certprofiles.contains(new Integer (id))) 1523 exists = true; 1524 } 1525 } 1526 }catch(FinderException e){} 1527 1528 return exists; 1529 } 1531 1539 public boolean existsHardTokenProfileInHardTokenIssuer(Admin admin, int id){ 1540 HardTokenIssuer issuer = null; 1541 Collection hardtokenissuers=null; 1542 boolean exists = false; 1543 try{ 1544 Collection result = this.hardtokenissuerhome.findAll(); 1545 Iterator i = result.iterator(); 1546 while(i.hasNext() && !exists){ 1547 issuer = ((HardTokenIssuerDataLocal) i.next()).getHardTokenIssuer(); 1548 hardtokenissuers = issuer.getAvailableHardTokenProfiles(); 1549 if(hardtokenissuers.contains(new Integer (id))) 1550 exists = true; 1551 } 1552 }catch(FinderException e){} 1553 return exists; 1554 } 1556 private Integer findFreeHardTokenProfileId(){ 1557 Random ran = (new Random ((new Date ()).getTime())); 1558 int id = ran.nextInt(); 1559 boolean foundfree = false; 1560 1561 while(!foundfree){ 1562 try{ 1563 if(id > SecConst.TOKEN_SOFT) 1564 hardtokenprofilehome.findByPrimaryKey(new Integer (id)); 1565 id = ran.nextInt(); 1566 }catch(FinderException e){ 1567 foundfree = true; 1568 } 1569 } 1570 return new Integer (id); 1571 } 1573 private Integer findFreeHardTokenIssuerId(){ 1574 Random ran = (new Random ((new Date ()).getTime())); 1575 int id = ran.nextInt(); 1576 boolean foundfree = false; 1577 1578 while(!foundfree){ 1579 try{ 1580 if(id > 1) 1581 hardtokenissuerhome.findByPrimaryKey(new Integer (id)); 1582 id = ran.nextInt(); 1583 }catch(FinderException e){ 1584 foundfree = true; 1585 } 1586 } 1587 return new Integer (id); 1588 } 1590 1591} | Popular Tags |