1 13 14 package org.ejbca.core.ejb.ra.raadmin; 15 16 import java.util.ArrayList ; 17 import java.util.Collection ; 18 import java.util.Date ; 19 import java.util.HashMap ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.Random ; 23 24 import javax.ejb.CreateException ; 25 import javax.ejb.EJBException ; 26 import javax.ejb.FinderException ; 27 28 import org.ejbca.core.ejb.BaseSessionBean; 29 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal; 30 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocalHome; 31 import org.ejbca.core.ejb.log.ILogSessionLocal; 32 import org.ejbca.core.ejb.log.ILogSessionLocalHome; 33 import org.ejbca.core.model.InternalResources; 34 import org.ejbca.core.model.SecConst; 35 import org.ejbca.core.model.authorization.AuthorizationDeniedException; 36 import org.ejbca.core.model.log.Admin; 37 import org.ejbca.core.model.log.LogEntry; 38 import org.ejbca.core.model.ra.raadmin.AdminPreference; 39 import org.ejbca.core.model.ra.raadmin.EndEntityProfile; 40 import org.ejbca.core.model.ra.raadmin.EndEntityProfileExistsException; 41 import org.ejbca.core.model.ra.raadmin.GlobalConfiguration; 42 43 44 116 public class LocalRaAdminSessionBean extends BaseSessionBean { 117 118 119 private static final InternalResources intres = InternalResources.getInstance(); 120 121 122 private AdminPreferencesDataLocalHome adminpreferenceshome=null; 123 124 125 private EndEntityProfileDataLocalHome profiledatahome=null; 126 127 128 private GlobalConfigurationDataLocalHome globalconfigurationhome = null; 129 130 131 private GlobalConfiguration globalconfiguration; 132 133 134 private ILogSessionLocal logsession = null; 135 136 137 private IAuthorizationSessionLocal authorizationsession = null; 138 139 140 public static final String EMPTY_ENDENTITYPROFILENAME = "EMPTY"; 141 142 private static final String DEFAULTUSERPREFERENCE = "default"; 143 144 public static final String EMPTY_ENDENTITYPROFILE = LocalRaAdminSessionBean.EMPTY_ENDENTITYPROFILENAME; 145 public static final int EMPTY_ENDENTITYPROFILEID = SecConst.EMPTY_ENDENTITYPROFILE; 146 147 152 public void ejbCreate() throws CreateException { 153 try{ 154 adminpreferenceshome = (AdminPreferencesDataLocalHome)getLocator().getLocalHome(AdminPreferencesDataLocalHome.COMP_NAME); 155 profiledatahome = (EndEntityProfileDataLocalHome)getLocator().getLocalHome(EndEntityProfileDataLocalHome.COMP_NAME); 156 globalconfigurationhome = (GlobalConfigurationDataLocalHome)getLocator().getLocalHome(GlobalConfigurationDataLocalHome.COMP_NAME); 157 158 }catch(Exception e){ 159 throw new EJBException (e); 160 } 161 162 } 163 164 165 167 private ILogSessionLocal getLogSession() { 168 if(logsession == null){ 169 try{ 170 ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME); 171 logsession = logsessionhome.create(); 172 }catch(Exception e){ 173 throw new EJBException (e); 174 } 175 } 176 return logsession; 177 } 179 180 183 private IAuthorizationSessionLocal getAuthorizationSession() { 184 if(authorizationsession == null){ 185 try{ 186 IAuthorizationSessionLocalHome authorizationsessionhome = (IAuthorizationSessionLocalHome) getLocator().getLocalHome(IAuthorizationSessionLocalHome.COMP_NAME); 187 authorizationsession = authorizationsessionhome.create(); 188 }catch(Exception e){ 189 throw new EJBException (e); 190 } 191 } 192 return authorizationsession; 193 } 195 196 197 198 202 public AdminPreference getAdminPreference(Admin admin, String certificatefingerprint){ 203 debug(">getAdminPreference()"); 204 AdminPreference ret =null; 205 try { 206 AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(certificatefingerprint); 207 ret = apdata.getAdminPreference(); 208 } catch (javax.ejb.FinderException fe) { 209 ret=null; 211 } catch(Exception e){ 212 throw new EJBException (e); 213 } 214 debug("<getAdminPreference()"); 215 return ret; 216 } 218 222 public boolean addAdminPreference(Admin admin, String certificatefingerprint, AdminPreference adminpreference){ 223 debug(">addAdminPreference(fingerprint : " + certificatefingerprint + ")"); 224 boolean ret = false; 225 boolean exists = false; 226 try { 227 AdminPreferencesDataLocal data = adminpreferenceshome.findByPrimaryKey(certificatefingerprint); 229 if (data != null) { 230 exists = true; 231 } 232 } catch (FinderException e) { 233 } 235 if (!exists) { 236 try { 237 AdminPreferencesDataLocal apdata= adminpreferenceshome.create(certificatefingerprint, adminpreference); 238 String msg = intres.getLocalizedMessage("ra.adminprefadded", apdata.getId()); 239 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg); 240 ret = true; 241 } catch (Exception e) { 242 ret = false; 243 String msg = intres.getLocalizedMessage("ra.adminprefexists"); 244 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg); 245 } 246 } else { 247 ret = false; 248 String msg = intres.getLocalizedMessage("ra.adminprefexists"); 249 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg); 250 } 251 debug("<addAdminPreference()"); 252 return ret; 253 } 255 259 public boolean changeAdminPreference(Admin admin, String certificatefingerprint, AdminPreference adminpreference){ 260 debug(">changeAdminPreference(fingerprint : " + certificatefingerprint + ")"); 261 return updateAdminPreference(admin, certificatefingerprint, adminpreference, true); 262 } 264 268 public boolean changeAdminPreferenceNoLog(Admin admin, String certificatefingerprint, AdminPreference adminpreference){ 269 debug(">changeAdminPreferenceNoLog(fingerprint : " + certificatefingerprint + ")"); 270 return updateAdminPreference(admin, certificatefingerprint, adminpreference, false); 271 } 273 278 public boolean existsAdminPreference(Admin admin, String certificatefingerprint){ 279 debug(">existsAdminPreference(fingerprint : " + certificatefingerprint + ")"); 280 boolean ret = false; 281 try { 282 AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(certificatefingerprint); 283 debug("Found admin preferences with id "+apdata.getId()); 284 ret = true; 285 } catch (javax.ejb.FinderException fe) { 286 ret=false; 287 } catch(Exception e){ 288 throw new EJBException (e); 289 } 290 debug("<existsAdminPreference()"); 291 return ret; 292 } 294 301 public AdminPreference getDefaultAdminPreference(Admin admin){ 302 debug(">getDefaultAdminPreference()"); 303 AdminPreference ret =null; 304 try { 305 AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(DEFAULTUSERPREFERENCE); 306 ret = apdata.getAdminPreference(); 307 } catch (javax.ejb.FinderException fe) { 308 try{ 309 AdminPreferencesDataLocal apdata = adminpreferenceshome.create(DEFAULTUSERPREFERENCE,new AdminPreference()); 311 ret = apdata.getAdminPreference(); 312 }catch(Exception e){ 313 throw new EJBException (e); 314 } 315 } catch(Exception e){ 316 throw new EJBException (e); 317 } 318 debug("<getDefaultAdminPreference()"); 319 return ret; 320 } 322 328 public void saveDefaultAdminPreference(Admin admin, AdminPreference defaultadminpreference){ 329 debug(">saveDefaultAdminPreference()"); 330 try { 331 AdminPreferencesDataLocal apdata = adminpreferenceshome.findByPrimaryKey(DEFAULTUSERPREFERENCE); 332 apdata.setAdminPreference(defaultadminpreference); 333 String msg = intres.getLocalizedMessage("ra.defaultadminprefsaved"); 334 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg); 335 } catch (Exception e) { 336 String msg = intres.getLocalizedMessage("ra.errorsavedefaultadminpref"); 337 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ADMINISTRATORPREFERENCECHANGED,msg); 338 throw new EJBException (e); 339 } 340 debug("<saveDefaultAdminPreference()"); 341 } 343 352 public void addEndEntityProfile(Admin admin, String profilename, EndEntityProfile profile) throws EndEntityProfileExistsException { 353 addEndEntityProfile(admin,findFreeEndEntityProfileId(),profilename,profile); 354 } 356 366 public void addEndEntityProfile(Admin admin, int profileid, String profilename, EndEntityProfile profile) throws EndEntityProfileExistsException{ 367 if(profilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME)){ 368 String msg = intres.getLocalizedMessage("ra.erroraddprofile", profilename); 369 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 370 throw new EndEntityProfileExistsException(); 371 } 372 if (isFreeEndEntityProfileId(profileid) == false) { 373 String msg = intres.getLocalizedMessage("ra.erroraddprofile", profilename); 374 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 375 throw new EndEntityProfileExistsException(); 376 } 377 try { 378 profiledatahome.findByProfileName(profilename); 379 String msg = intres.getLocalizedMessage("ra.erroraddprofile", profilename); 380 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 381 throw new EndEntityProfileExistsException(); 382 } catch (FinderException e) { 383 try { 384 profiledatahome.create(new Integer (profileid), profilename, profile); 385 String msg = intres.getLocalizedMessage("ra.addedprofile", profilename); 386 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (), null, null, 387 LogEntry.EVENT_INFO_ENDENTITYPROFILE,msg); 388 } catch (Exception f) { 389 String msg = intres.getLocalizedMessage("ra.erroraddprofile", profilename); 390 error(msg, e); 391 logsession.log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (), null, null, 392 LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 393 } 394 } 395 } 397 401 public void cloneEndEntityProfile(Admin admin, String originalprofilename, String newprofilename) throws EndEntityProfileExistsException{ 402 EndEntityProfile profile = null; 403 404 if(newprofilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME)){ 405 String msg = intres.getLocalizedMessage("ra.errorcloneprofile", newprofilename, originalprofilename); 406 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 407 throw new EndEntityProfileExistsException(); 408 } 409 try{ 410 EndEntityProfileDataLocal pdl = profiledatahome.findByProfileName(originalprofilename); 411 profile = (EndEntityProfile) pdl.getProfile().clone(); 412 try{ 413 profiledatahome.findByProfileName(newprofilename); 414 String msg = intres.getLocalizedMessage("ra.errorcloneprofile", newprofilename, originalprofilename); 415 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 416 throw new EndEntityProfileExistsException(); 417 }catch(FinderException e){ 418 profiledatahome.create(new Integer (findFreeEndEntityProfileId()),newprofilename,profile); 419 String msg = intres.getLocalizedMessage("ra.clonedprofile", newprofilename, originalprofilename); 420 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE,msg); 421 } 422 }catch(Exception e){ 423 String msg = intres.getLocalizedMessage("ra.errorcloneprofile", newprofilename, originalprofilename); 424 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 425 } 426 427 } 429 434 public void removeEndEntityProfile(Admin admin, String profilename) { 435 try{ 436 EndEntityProfileDataLocal pdl = profiledatahome.findByProfileName(profilename); 437 pdl.remove(); 438 String msg = intres.getLocalizedMessage("ra.removedprofile", profilename); 439 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE,msg); 440 }catch(Exception e){ 441 String msg = intres.getLocalizedMessage("ra.errorremoveprofile", profilename); 442 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 443 } 444 } 446 450 public void renameEndEntityProfile(Admin admin, String oldprofilename, String newprofilename) throws EndEntityProfileExistsException{ 451 if(newprofilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME) || oldprofilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME)){ 452 String msg = intres.getLocalizedMessage("ra.errorrenameprofile", oldprofilename, newprofilename); 453 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 454 throw new EndEntityProfileExistsException(); 455 } 456 try{ 457 profiledatahome.findByProfileName(newprofilename); 458 String msg = intres.getLocalizedMessage("ra.errorrenameprofile", oldprofilename, newprofilename); 459 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 460 throw new EndEntityProfileExistsException(); 461 }catch(FinderException e){ 462 try{ 463 EndEntityProfileDataLocal pdl = profiledatahome.findByProfileName(oldprofilename); 464 pdl.setProfileName(newprofilename); 465 String msg = intres.getLocalizedMessage("ra.renamedprofile", oldprofilename, newprofilename); 466 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE,msg ); 467 }catch(FinderException f){ 468 String msg = intres.getLocalizedMessage("ra.errorrenameprofile", oldprofilename, newprofilename); 469 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg ); 470 } 471 } 472 } 474 478 public void changeEndEntityProfile(Admin admin, String profilename, EndEntityProfile profile){ 479 try{ 480 EndEntityProfileDataLocal pdl = profiledatahome.findByProfileName(profilename); 481 pdl.setProfile(profile); 482 String msg = intres.getLocalizedMessage("ra.changedprofile", profilename); 483 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ENDENTITYPROFILE,msg); 484 }catch(FinderException e){ 485 String msg = intres.getLocalizedMessage("ra.errorchangeprofile", profilename); 486 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ENDENTITYPROFILE,msg); 487 } 488 } 490 495 public Collection getAuthorizedEndEntityProfileIds(Admin admin){ 496 ArrayList returnval = new ArrayList (); 497 Collection result = null; 498 499 HashSet authorizedcaids = new HashSet (getAuthorizationSession().getAuthorizedCAIds(admin)); 500 try{ 502 if(getAuthorizationSession().isAuthorizedNoLog(admin, "/super_administrator")) 503 returnval.add(new Integer (SecConst.EMPTY_ENDENTITYPROFILE)); 504 }catch(AuthorizationDeniedException e){} 505 506 try{ 507 result = profiledatahome.findAll(); 508 Iterator i = result.iterator(); 509 while(i.hasNext()){ 510 EndEntityProfileDataLocal next = (EndEntityProfileDataLocal) i.next(); 511 String value = next.getProfile().getValue(EndEntityProfile.AVAILCAS, 0); 513 if (value != null) { 515 String [] availablecas = value.split(EndEntityProfile.SPLITCHAR); 516 boolean allexists = true; 518 for(int j=0; j < availablecas.length; j++){ 519 if(!authorizedcaids.contains( new Integer (availablecas[j]))){ 521 allexists = false; 522 break; 524 } 525 } 526 if(allexists) { 527 returnval.add(next.getId()); 529 } 530 } 531 } 532 }catch(Exception e){ 533 String msg = intres.getLocalizedMessage("ra.errorgetids"); 534 error(msg, e); 535 } 536 return returnval; 537 } 539 544 public HashMap getEndEntityProfileIdToNameMap(Admin admin){ 545 debug(">getEndEntityProfileIdToNameMap"); 546 HashMap returnval = new HashMap (); 547 Collection result = null; 548 returnval.put(new Integer (SecConst.EMPTY_ENDENTITYPROFILE),EMPTY_ENDENTITYPROFILENAME); 549 try{ 550 result = profiledatahome.findAll(); 551 Iterator i = result.iterator(); 553 while(i.hasNext()){ 554 EndEntityProfileDataLocal next = (EndEntityProfileDataLocal) i.next(); 555 returnval.put(next.getId(),next.getProfileName()); 557 } 558 }catch(Exception e) { 559 String msg = intres.getLocalizedMessage("ra.errorreadprofiles"); 560 error(msg, e); 561 } 562 debug(">getEndEntityProfileIdToNameMap"); 563 return returnval; 564 } 566 571 public EndEntityProfile getEndEntityProfile(Admin admin, int id){ 572 if (log.isDebugEnabled()) { 573 debug(">getEndEntityProfile("+id+")"); 574 } 575 EndEntityProfile returnval=null; 576 try{ 577 if(id==SecConst.EMPTY_ENDENTITYPROFILE) { 578 returnval = new EndEntityProfile(true); 579 } 580 if(id!=0 && id != SecConst.EMPTY_ENDENTITYPROFILE) { 581 returnval = (profiledatahome.findByPrimaryKey(new Integer (id))).getProfile(); 582 } 583 }catch(FinderException e){ 584 } 586 if (log.isDebugEnabled()) { 587 debug("<getEndEntityProfile(id): "+(returnval == null ? "null":"not null")); 588 } 589 return returnval; 590 } 592 597 public EndEntityProfile getEndEntityProfile(Admin admin, String profilename){ 598 if (log.isDebugEnabled()) { 599 debug(">getEndEntityProfile("+profilename+")"); 600 } 601 EndEntityProfile returnval=null; 602 try{ 603 if(profilename.equals(EMPTY_ENDENTITYPROFILENAME)) { 604 returnval = new EndEntityProfile(true); 605 } else { 606 returnval = (profiledatahome.findByProfileName(profilename)).getProfile(); 607 } 608 }catch(FinderException e){ 609 } 611 debug("<getEndEntityProfile(profilename)"); 612 return returnval; 613 } 615 622 public int getEndEntityProfileId(Admin admin, String profilename){ 623 if (log.isDebugEnabled()) { 624 debug(">getEndEntityProfileId("+profilename+")"); 625 } 626 int returnval = 0; 627 if(profilename.trim().equalsIgnoreCase(EMPTY_ENDENTITYPROFILENAME)) 628 return SecConst.EMPTY_ENDENTITYPROFILE; 629 try{ 630 Integer id = (profiledatahome.findByProfileName(profilename)).getId(); 631 returnval = id.intValue(); 632 }catch(FinderException e){ 633 } 635 debug(">getEndEntityProfileId(profilename)"); 636 return returnval; 637 } 639 646 public String getEndEntityProfileName(Admin admin, int id){ 647 String returnval = null; 648 if(id == SecConst.EMPTY_ENDENTITYPROFILE) 649 return EMPTY_ENDENTITYPROFILENAME; 650 try{ 651 returnval = (profiledatahome.findByPrimaryKey(new Integer (id))).getProfileName(); 652 }catch(FinderException e){} 653 654 return returnval; 655 } 657 658 659 667 public boolean existsCertificateProfileInEndEntityProfiles(Admin admin, int certificateprofileid){ 668 String [] availablecertprofiles=null; 669 boolean exists = false; 670 try{ 671 Collection result = profiledatahome.findAll(); 672 Iterator i = result.iterator(); 673 while(i.hasNext() && !exists){ 674 availablecertprofiles = ((EndEntityProfileDataLocal) i.next()).getProfile().getValue(EndEntityProfile.AVAILCERTPROFILES, 0).split(EndEntityProfile.SPLITCHAR); 675 for(int j=0; j < availablecertprofiles.length; j++){ 676 if(Integer.parseInt(availablecertprofiles[j]) == certificateprofileid){ 677 exists=true; 678 break; 679 } 680 } 681 } 682 }catch(FinderException e){} 683 684 return exists; 685 } 686 687 695 public boolean existsCAInEndEntityProfiles(Admin admin, int caid){ 696 String [] availablecas=null; 697 boolean exists = false; 698 try{ 699 Collection result = profiledatahome.findAll(); 700 Iterator i = result.iterator(); 701 while(i.hasNext() && !exists){ 702 availablecas = ((EndEntityProfileDataLocal) i.next()).getProfile().getValue(EndEntityProfile.AVAILCAS, 0).split(EndEntityProfile.SPLITCHAR); 703 for(int j=0; j < availablecas.length; j++){ 704 if(Integer.parseInt(availablecas[j]) == caid){ 705 exists=true; 706 break; 707 } 708 } 709 } 710 }catch(FinderException e){} 711 712 return exists; 713 } 715 722 public GlobalConfiguration loadGlobalConfiguration(Admin admin) { 723 debug(">loadGlobalConfiguration()"); 724 if(globalconfiguration != null) 725 return globalconfiguration ; 726 727 GlobalConfiguration ret=null; 728 try{ 729 GlobalConfigurationDataLocal gcdata = globalconfigurationhome.findByPrimaryKey("0"); 730 if(gcdata!=null){ 731 ret = gcdata.getGlobalConfiguration(); 732 } 733 }catch (javax.ejb.FinderException fe) { 734 ret = new GlobalConfiguration(); 736 } 737 debug("<loadGlobalConfiguration()"); 738 return ret; 739 } 741 747 public void initGlobalConfigurationBaseURL(Admin admin, String computername, String applicationpath) { 748 debug(">initGlobalConfigurationBaseURL()"); 749 GlobalConfiguration gc = this.loadGlobalConfiguration(admin); 750 gc.setComputerName(computername); 751 gc.setApplicationPath(applicationpath); 752 this.saveGlobalConfiguration(admin, gc); 753 debug("<initGlobalConfigurationBaseURL()"); 754 } 756 762 763 public void saveGlobalConfiguration(Admin admin, GlobalConfiguration globalconfiguration) { 764 debug(">saveGlobalConfiguration()"); 765 String pk = "0"; 766 try { 767 GlobalConfigurationDataLocal gcdata = globalconfigurationhome.findByPrimaryKey(pk); 768 gcdata.setGlobalConfiguration(globalconfiguration); 769 String msg = intres.getLocalizedMessage("ra.savedconf", gcdata.getConfigurationId()); 770 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_EDITSYSTEMCONFIGURATION,msg); 771 }catch (javax.ejb.FinderException fe) { 772 try{ 774 GlobalConfigurationDataLocal data1 = globalconfigurationhome.create(pk,globalconfiguration); 775 String msg = intres.getLocalizedMessage("ra.createdconf", data1.getConfigurationId()); 776 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_EDITSYSTEMCONFIGURATION, msg); 777 } catch(CreateException e){ 778 String msg = intres.getLocalizedMessage("ra.errorcreateconf"); 779 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_EDITSYSTEMCONFIGURATION,msg); 780 } 781 } 782 this.globalconfiguration=globalconfiguration; 783 debug("<saveGlobalConfiguration()"); 784 } 786 787 788 790 private int findFreeEndEntityProfileId(){ 791 int id = (new Random ((new Date ()).getTime())).nextInt(); 792 boolean foundfree = false; 793 794 while(!foundfree){ 795 try{ 796 if(id > 1) 797 profiledatahome.findByPrimaryKey(new Integer (id)); 798 id++; 799 }catch(FinderException e){ 800 foundfree = true; 801 } 802 } 803 return id; 804 } 806 private boolean isFreeEndEntityProfileId(int id) { 807 boolean foundfree = false; 808 try { 809 if (id > 1) { 810 profiledatahome.findByPrimaryKey(new Integer (id)); 811 } 812 } catch (FinderException e) { 813 foundfree = true; 814 } 815 return foundfree; 816 } 818 821 private boolean updateAdminPreference(Admin admin, String certificatefingerprint, AdminPreference adminpreference, boolean dolog){ 822 debug(">updateAdminPreference(fingerprint : " + certificatefingerprint + ")"); 823 boolean ret = false; 824 try { 825 adminpreferenceshome.findByPrimaryKey(certificatefingerprint); 826 adminpreferenceshome.remove(certificatefingerprint); 827 try{ 828 AdminPreferencesDataLocal apdata2 = adminpreferenceshome.findByPrimaryKey(certificatefingerprint); 829 debug("Found admin preferences with id "+apdata2.getId()); 830 } catch (javax.ejb.FinderException fe) { 831 } 832 adminpreferenceshome.create(certificatefingerprint,adminpreference); 833 try{ 834 AdminPreferencesDataLocal apdata3 = adminpreferenceshome.findByPrimaryKey(certificatefingerprint); 835 debug("Found admin preferences with id "+apdata3.getId()); 836 } catch (javax.ejb.FinderException fe) { 837 } 838 if (dolog) { 839 String msg = intres.getLocalizedMessage("ra.changedadminpref", certificatefingerprint); 840 getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_INFO_ADMINISTRATORPREFERENCECHANGED,msg); 841 } 842 ret = true; 843 } catch (javax.ejb.FinderException fe) { 844 ret=false; 845 if (dolog) { 846 String msg = intres.getLocalizedMessage("ra.adminprefnotfound", certificatefingerprint); 847 getLogSession().log(admin,admin.getCaId(), LogEntry.MODULE_RA, new java.util.Date (),null, null, LogEntry.EVENT_ERROR_ADMINISTRATORPREFERENCECHANGED,msg); 848 } 849 } catch(Exception e){ 850 throw new EJBException (e); 851 } 852 debug("<updateAdminPreference()"); 853 return ret; 854 } 856 857 } 859 | Popular Tags |