1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import java.util.ArrayList ; 32 import java.util.Properties ; 33 import java.util.Set ; 34 import java.util.HashSet ; 35 import java.util.Enumeration ; 36 import java.util.Iterator ; 37 import java.util.Collection ; 38 import java.io.File ; 39 import java.util.logging.Level ; 40 import java.util.logging.Logger ; 41 42 43 import javax.management.AttributeList ; 45 import javax.management.Attribute ; 46 import javax.management.ObjectName ; 47 import javax.management.MBeanException ; 48 import javax.management.InstanceNotFoundException ; 49 import javax.management.MBeanServer ; 50 51 import com.sun.enterprise.config.ConfigContext; 53 import com.sun.enterprise.config.ConfigException; 54 import com.sun.enterprise.config.ConfigBean; 55 import com.sun.enterprise.config.ConfigBeansFactory; 56 import com.sun.enterprise.config.serverbeans.ServerTags; 57 import com.sun.enterprise.util.SystemPropertyConstants; 58 59 import com.sun.enterprise.config.serverbeans.Config; 60 import com.sun.enterprise.config.serverbeans.SecurityService; 61 import com.sun.enterprise.config.serverbeans.MessageSecurityConfig; 62 import com.sun.enterprise.config.serverbeans.ProviderConfig; 63 import com.sun.enterprise.config.serverbeans.RequestPolicy; 64 import com.sun.enterprise.config.serverbeans.ResponsePolicy; 65 import com.sun.enterprise.config.serverbeans.ElementProperty; 66 import com.sun.enterprise.config.serverbeans.IiopService; 67 import com.sun.enterprise.config.serverbeans.Ssl; 68 import com.sun.enterprise.config.serverbeans.SslClientConfig; 69 import com.sun.enterprise.config.serverbeans.AuthRealm; 70 71 72 73 import com.sun.enterprise.util.i18n.StringManager; 74 import com.sun.enterprise.admin.config.BaseConfigMBean; 75 import com.sun.enterprise.admin.config.ManagedConfigBean; 76 import com.sun.enterprise.admin.config.MBeanConfigException; 77 import com.sun.enterprise.admin.config.ConfigMBeanHelper; 78 import com.sun.enterprise.admin.meta.MBeanRegistry; 79 import com.sun.enterprise.admin.meta.MBeanRegistryEntry; 80 import com.sun.enterprise.admin.meta.naming.MBeanNamingInfo; 81 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 82 import com.sun.enterprise.admin.util.jmx.AttributeListUtils; 83 84 import com.sun.enterprise.config.serverbeans.ServerHelper; 85 import com.sun.enterprise.config.serverbeans.ClusterHelper; 86 import com.sun.enterprise.config.serverbeans.ConfigAPIHelper; 87 import com.sun.enterprise.config.serverbeans.PropertyResolver; 88 89 import com.sun.enterprise.admin.mbeanapi.IConfigsMBean; 90 91 import com.sun.enterprise.admin.target.Target; 92 import com.sun.enterprise.admin.target.ConfigTarget; 93 import com.sun.enterprise.admin.target.TargetType; 94 import com.sun.enterprise.admin.target.TargetBuilder; 95 96 import com.sun.enterprise.admin.meta.MBeanRegistry; 97 98 import com.sun.enterprise.admin.util.JvmOptionsHelper; 99 import com.sun.enterprise.admin.util.InvalidJvmOptionException; 100 101 public class ConfigsMBean extends BaseConfigMBean 102 implements IConfigsMBean 103 { 104 105 109 public static final String DEFAULT_HTTP_LISTENER_ACCEPTOR_THREADS = "1"; 110 111 112 118 private static final TargetType[] VALID_CREATE_DELETE_TYPES = new TargetType[] { 119 TargetType.CLUSTER, TargetType.CONFIG, TargetType.UNCLUSTERED_SERVER, TargetType.DAS}; 120 121 private static final TargetType[] VALID_LIST_TYPES = new TargetType[] { 122 TargetType.CLUSTER, TargetType.CONFIG, TargetType.SERVER, TargetType.DAS}; 123 124 127 private static final StringManager localStrings = 128 StringManager.getManager(ConfigsMBean.class); 129 130 132 public ConfigsMBean() 133 { 134 super(); 135 } 136 137 144 public String getConfigNameForTarget(String targetName) 145 throws Exception 146 { 147 final Target target = getTarget(targetName); 148 final ConfigTarget configTarget = target.getConfigTarget(); 149 return configTarget.getName(); 150 } 151 153 public ObjectName createHttpListener( AttributeList attrList, 154 Properties props, 155 String targetName) 156 throws MBeanException 157 { 158 final Target target = getTarget(targetName); 159 check1ToN(target); 160 161 if(!ConfigMBeanUtil.attributeDefinedInList(attrList, 163 ServerTags.ACCEPTOR_THREADS)) { 164 attrList.add(new Attribute (ServerTags.ACCEPTOR_THREADS, 165 getDefaultHTTPListenerAcceptorThreads())); 166 } 167 168 169 ObjectName httpService = getHttpServiceMBean(target); 170 ObjectName mbean = (ObjectName )invoke1(httpService, 171 "createHttpListener", attrList, AttributeList .class.getName()); 172 setProperties(mbean, props); 173 try 175 { 176 HttpListenerVirtualServerAssociationMgr mgr = 177 new HttpListenerVirtualServerAssociationMgr(getConfigContext(), 178 target.getConfigRef()); 179 mgr.addHttpListenerRef(mbean.getKeyProperty("id")); 180 } 181 catch (ConfigException ce) 182 { 183 throw MBeanExceptionFormatter.toMBeanException(ce, null); 184 } 185 return mbean; 187 } 188 189 public boolean deleteHttpListener(String listenerId, String targetName) 190 throws MBeanException 191 { 192 final Target target = getTarget(targetName); 193 try 195 { 196 HttpListenerVirtualServerAssociationMgr mgr = 197 new HttpListenerVirtualServerAssociationMgr(getConfigContext(), 198 target.getConfigRef()); 199 mgr.deleteHttpListenerRef(listenerId); 200 } 201 catch (ConfigException ce) 202 { 203 throw MBeanExceptionFormatter.toMBeanException(ce, null); 204 } 205 check1ToN(target); 207 final ObjectName httpService = getHttpServiceMBean(target); 208 invoke1(httpService, "removeHttpListenerById", listenerId, 209 String .class.getName()); 210 return true; 211 } 212 213 public ObjectName [] listHttpListeners(String targetName) 214 throws MBeanException 215 { 216 final Target target = getListTarget(targetName); 217 ObjectName httpService = getHttpServiceMBean(target); 218 ObjectName [] ret = (ObjectName [])invoke0(httpService, 219 "getHttpListener"); 220 return ret; 221 } 222 223 public ObjectName createIiopListener( AttributeList attrList, 225 Properties props, 226 String targetName) 227 throws MBeanException 228 { 229 final Target target = getTarget(targetName); 230 check1ToN(target); 231 ObjectName iiopService = getIiopServiceMBean(target); 232 ObjectName mbean = (ObjectName )invoke1(iiopService, 233 "createIiopListener", attrList, AttributeList .class.getName()); 234 setProperties(mbean, props); 235 return mbean; 236 } 237 238 public boolean deleteIiopListener(String listenerId, String targetName) 239 throws MBeanException 240 { 241 final Target target = getTarget(targetName); 242 check1ToN(target); 243 final ObjectName iiopService = getIiopServiceMBean(target); 244 invoke1(iiopService, "removeIiopListenerById", listenerId, 245 String .class.getName()); 246 return true; 247 } 248 249 public ObjectName [] listIiopListeners(String targetName) 250 throws MBeanException 251 { 252 final Target target = getListTarget(targetName); 253 ObjectName iiopService = getIiopServiceMBean(target); 254 ObjectName [] ret = (ObjectName [])invoke0(iiopService, 255 "getIiopListener"); 256 return ret; 257 } 258 259 public ObjectName createSsl(AttributeList al, 261 String id, 262 String type, 263 String targetName) 264 throws Exception 265 { 266 final Target target = getTarget(targetName); 267 check1ToN(target); 268 ObjectName targetON = getSslTargetObjectName(target, id, type); 269 if ("iiop-service".equals(type)) 270 { 271 Config config = getConfigBeanForTarget(target); 272 IiopService iiopService = config.getIiopService(); 273 SslClientConfig sslCfg = new SslClientConfig(); 274 sslCfg.setXPath(sslCfg.getAbsoluteXPath(iiopService.getXPath())); 275 ManagedConfigBean mb = new ManagedConfigBean( 276 (ConfigBean)sslCfg, m_registry, getDomainName()); 277 mb.createChildByType("ssl", al, null, true); 278 iiopService.setSslClientConfig(sslCfg); 279 return (ObjectName )ConfigMBeanHelper.getConfigBeanObjectName( 280 m_registry, 281 getDomainName(), sslCfg.getSsl()); 282 } 283 checkElementDoesnotExist(targetON, "getSsl", 284 localStrings.getString("configsMBean.ssl_exists")); 285 ObjectName ret = (ObjectName )invoke1(targetON, "createSsl", al, 286 AttributeList .class.getName()); 287 return ret; 288 } 289 290 public boolean deleteSsl(String id, String type, String targetName) 291 throws MBeanException 292 { 293 final Target target = getTarget(targetName); 294 check1ToN(target); 295 final ObjectName targetON = getSslTargetObjectName(target, id, type); 296 final String opName = "iiop-service".equals(type) ? 297 "removeSslClientConfig" : "removeSsl"; 298 invoke0(targetON, opName); 299 return true; 300 } 301 302 public ObjectName createVirtualServer( AttributeList al, 304 Properties props, 305 String targetName) 306 throws MBeanException 307 { 308 final Target target = getTarget(targetName); 309 check1ToN(target); 310 ObjectName httpService = getHttpServiceMBean(target); 311 ObjectName mbean = (ObjectName )invoke1(httpService, 312 "createVirtualServer", al, AttributeList .class.getName()); 313 final Properties nProps = copyProperties(props); 314 addMandatoryVirtualServerProperties(al, nProps); setProperties(mbean, nProps); 316 return mbean; 317 } 318 319 public boolean deleteVirtualServer(String id, String targetName) 320 throws MBeanException 321 { 322 final Target target = getTarget(targetName); 323 check1ToN(target); 324 final ObjectName httpService = (ObjectName )getHttpServiceMBean(target); 325 invoke1(httpService, "removeVirtualServerById", id, 326 String .class.getName()); 327 return true; 328 } 329 330 public ObjectName [] listVirtualServers(String targetName) 331 throws MBeanException 332 { 333 final Target target = getListTarget(targetName); 334 ObjectName httpService = getHttpServiceMBean(target); 335 ObjectName [] ret = (ObjectName [])invoke0(httpService, 336 "getVirtualServer"); 337 return ret; 338 } 339 340 public ObjectName createAuthRealm(AttributeList attrs, 342 Properties props, 343 String targetName) 344 throws Exception 345 { 346 final Target target = getTarget(targetName); 347 check1ToN(target); 348 349 Config config = getConfigBeanForTarget(target); 351 SecurityService secService = config.getSecurityService(); 352 ManagedConfigBean mcbSecService = getManagedConfigBean(secService); 353 AuthRealm authRealm = (AuthRealm)mcbSecService.createChildByType( 354 ServerTags.AUTH_REALM, attrs, props); 355 356 checkAndCreateAuthRealmKeyFile(authRealm); 360 361 362 mcbSecService.addChildBean(ServerTags.AUTH_REALM, authRealm, false); 364 return getConfigBeanObjectName(authRealm); 365 } 366 367 368 static final String FILE_REALM_CLASSNAME = "com.sun.enterprise.security.auth.realm.file.FileRealm"; 369 static final String KEYFILE_PATH_PROPERTY_NAME = "file"; 370 371 private void checkAndCreateAuthRealmKeyFile(AuthRealm authRealm) 373 throws MBeanConfigException 374 { 375 if(!FILE_REALM_CLASSNAME.equals(authRealm.getClassname())) 376 return; ElementProperty prop = authRealm.getElementPropertyByName(KEYFILE_PATH_PROPERTY_NAME); 378 if(prop==null) 379 { 380 return; } 385 String path=null; 386 try 387 { 388 path = resolveTokensForDas(prop.getValue()); 389 File file; 392 if((file = new File (path))!=null && !file.exists()) 393 file.createNewFile(); 394 } 395 catch (Exception e) 396 { 397 String msg = localStrings.getString("configsMBean.can_not_create_keyfile", new Object []{path}); 398 _sLogger.log(Level.WARNING, msg); 399 throw new MBeanConfigException(msg); 400 } 401 } 402 private String resolveTokensForDas(String value) throws ConfigException 403 { 404 String instanceName=MBeanRegistryFactory.getAdminContext().getServerName(); 405 PropertyResolver resolver = new PropertyResolver(getConfigContext(), instanceName); 406 return resolver.resolve(value, true); 407 } 408 409 410 public boolean deleteAuthRealm(String name, String targetName) 411 throws MBeanException 412 { 413 final Target target = getTarget(targetName); 414 check1ToN(target); 415 final ObjectName securityService = getSecurityServiceMBean(target); 416 invoke1(securityService, "removeAuthRealmByName", name, 417 String .class.getName()); 418 return true; 419 } 420 421 public ObjectName [] listAuthRealms(String targetName) 422 throws MBeanException 423 { 424 final Target target = getListTarget(targetName); 425 ObjectName securityService = getSecurityServiceMBean(target); 426 ObjectName [] ret = (ObjectName [])invoke0(securityService, 427 "getAuthRealm"); 428 return ret; 429 } 430 431 public void addUser(String user, 432 String password, 433 String [] grps, 434 String realmName, 435 String targetName) 436 throws MBeanException 437 { 438 final Target target = getTarget(targetName); 439 check1ToN(target); 440 realmName = (realmName != null) ? 441 realmName : getDefaultAuthRealm(target); 442 final ObjectName authRealm = getAuthRealmMBean(target, realmName); 443 invokeN(authRealm, "addUser", new Object [] {user, password, grps}, 444 new String [] {String .class.getName(), String .class.getName(), 445 new String [0].getClass().getName()}); 446 } 447 448 public void updateUser( String user, 449 String password, 450 String [] grps, 451 String realmName, 452 String targetName) 453 throws MBeanException 454 { 455 final Target target = getTarget(targetName); 456 check1ToN(target); 457 realmName = (realmName != null) ? 458 realmName : getDefaultAuthRealm(target); 459 final ObjectName authRealm = getAuthRealmMBean(target, realmName); 460 invokeN(authRealm, "updateUser", new Object [] {user, password, grps}, 461 new String [] {String .class.getName(), String .class.getName(), 462 new String [0].getClass().getName()}); 463 } 464 465 public void removeUser( String user, 466 String realmName, 467 String targetName) 468 throws MBeanException 469 { 470 final Target target = getTarget(targetName); 471 check1ToN(target); 472 realmName = (realmName != null) ? 473 realmName : getDefaultAuthRealm(target); 474 final ObjectName authRealm = getAuthRealmMBean(target, realmName); 475 invoke1(authRealm, "removeUser", user, String .class.getName()); 476 } 477 478 public String [] getUserNames(String realmName, String targetName) 479 throws MBeanException 480 { 481 final Target target = getListTarget(targetName); 482 realmName = (realmName != null) ? 483 realmName : getDefaultAuthRealm(target); 484 final ObjectName authRealm = getAuthRealmMBean(target, realmName); 485 return (String [])invoke0(authRealm, "getUserNames"); 486 } 487 488 public String [] getGroupNames( String user, 489 String realmName, 490 String targetName) 491 throws MBeanException 492 { 493 final Target target = getListTarget(targetName); 494 realmName = (realmName != null) ? 495 realmName : getDefaultAuthRealm(target); 496 final ObjectName authRealm = getAuthRealmMBean(target, realmName); 497 return (String [])invoke1(authRealm, "getUserGroupNames", 498 user, String .class.getName()); 499 } 500 501 public ObjectName createProfiler(AttributeList al, 503 Properties props, 504 String targetName) 505 throws MBeanException 506 { 507 final Target target = getTarget(targetName); 508 check1ToN(target); 509 final ObjectName javaConfig = getJavaConfigMBean(target); 510 checkElementDoesnotExist(javaConfig, "getProfiler", 511 localStrings.getString("configsMBean.profiler_exists")); 512 final ObjectName on = (ObjectName )invoke1(javaConfig, 513 "createProfiler", al, AttributeList .class.getName()); 514 setProperties(on, props); 515 return on; 516 } 517 518 public boolean deleteProfiler(String targetName) throws MBeanException 519 { 520 final Target target = getTarget(targetName); 521 check1ToN(target); 522 final ObjectName javaConfig = getJavaConfigMBean(target); 523 invoke0(javaConfig, "removeProfiler"); 524 return true; 525 } 526 527 public String [] getJvmOptions(boolean isProfiler, String targetName) 529 throws MBeanException 530 { 531 return getJvmOptions(isProfiler, getListTarget(targetName)); 532 } 533 534 549 public String [] createJvmOptions(String [] options, 550 boolean isProfiler, 551 String targetName) 552 throws MBeanException , InvalidJvmOptionException 553 { 554 if (null == options) 555 { 556 throw new IllegalArgumentException ( 557 localStrings.getString("configsMBean.null_jvm_options")); 558 } 559 final Target target = getTarget(targetName); 560 quoteOptionsWithSpaces(options); 561 check1ToN(target); 562 final String [] oldOptions = getJvmOptions(isProfiler, target); 563 final JvmOptionsHelper jvmOptions = new JvmOptionsHelper(oldOptions); 564 final String [] invalid = jvmOptions.addJvmOptions(options); 565 final ObjectName targetON = getJvmOptionsTargetObjectName( 566 target, isProfiler); 567 setAttribute0(targetON, "jvm_options", jvmOptions.getJvmOptionsAsStoredInXml()); 568 postInvoke("createJvmOptions", null); 569 570 return invalid; 571 } 572 573 private void quoteOptionsWithSpaces(String [] options) 574 { 575 for(int i=0; i<options.length; i++) 576 { 577 if(options[i].indexOf(' ')>=0 && 578 (!options[i].startsWith("\"") || !options[i].endsWith("\""))) 579 { 580 options[i] = "\"" + options[i] + "\""; 581 } 582 } 583 } 584 585 598 public String [] deleteJvmOptions(String [] options, 599 boolean isProfiler, 600 String targetName) 601 throws MBeanException , InvalidJvmOptionException 602 { 603 if (null == options) 604 { 605 throw new IllegalArgumentException ( 606 localStrings.getString("configsMBean.null_jvm_options")); 607 } 608 quoteOptionsWithSpaces(options); 609 final Target target = getTarget(targetName); 610 check1ToN(target); 611 final String [] oldOptions = getJvmOptions(isProfiler, target); 612 final JvmOptionsHelper jvmOptions = new JvmOptionsHelper(oldOptions); 613 final String [] invalid = jvmOptions.deleteJvmOptions(options); 614 final ObjectName targetON = getJvmOptionsTargetObjectName( 615 target, isProfiler); 616 setAttribute0(targetON, "jvm_options", jvmOptions.getJvmOptionsAsStoredInXml()); 617 postInvoke("deleteJvmOptions", null); 618 619 return invalid; 620 } 621 622 public ObjectName createAuditModule(AttributeList attrs, 624 Properties props, 625 String targetName) 626 throws MBeanException 627 { 628 final Target target = getTarget(targetName); 629 check1ToN(target); 630 final ObjectName securityService = getSecurityServiceMBean(target); 631 final ObjectName on = (ObjectName )invoke1(securityService, 632 "createAuditModule", attrs, AttributeList .class.getName()); 633 setProperties(on, props); 634 return on; 635 } 636 637 public ObjectName [] listAuditModules(String targetName) 638 throws MBeanException 639 { 640 final Target target = getListTarget(targetName); 641 final ObjectName securityService = getSecurityServiceMBean(target); 642 return (ObjectName [])invoke0(securityService, "getAuditModule"); 643 } 644 645 public boolean deleteAuditModule(String name, String targetName) 646 throws MBeanException 647 { 648 final Target target = getTarget(targetName); 649 check1ToN(target); 650 final ObjectName securityService = getSecurityServiceMBean(target); 651 invoke1(securityService, "removeAuditModuleByName", name, 652 String .class.getName()); 653 return true; 654 } 655 656 public ObjectName createJmsHost(AttributeList attrs, 658 Properties props, 659 String targetName) 660 throws MBeanException 661 { 662 final Target target = getTarget(targetName); 663 check1ToN(target); 664 final ObjectName jmsService = getJmsServiceMBean(target, true); 665 final ObjectName jmsHost = (ObjectName )invoke1(jmsService, 666 "createJmsHost", attrs, AttributeList .class.getName()); 667 setProperties(jmsHost, props); 668 return jmsHost; 669 } 670 671 public boolean deleteJmsHost(String name, String targetName) 672 throws MBeanException 673 { 674 final Target target = getTarget(targetName); 675 check1ToN(target); 676 final ObjectName jmsService = getJmsServiceMBean(target, false); 677 assertIt((jmsService != null), 678 localStrings.getString("configsMBean.no_jms_service")); 679 680 if(name.equals(getAttribute0(jmsService, "default_jms_host"))) { 682 setAttribute0(jmsService, "default_jms_host", null); 685 _sLogger.log(Level.FINE, 686 "default-jms-host attribute of jms-service for target " 687 + targetName 688 + " has been set to null"); 689 } 690 692 invoke1(jmsService, "removeJmsHostByName", name, 693 String .class.getName()); 694 return true; 695 } 696 697 public ObjectName [] listJmsHosts(String targetName) throws MBeanException 698 { 699 final Target target = getListTarget(targetName); 700 final ObjectName jmsService = getJmsServiceMBean(target, false); 701 assertIt((jmsService != null), 702 localStrings.getString("configsMBean.no_jms_service")); 703 return (ObjectName [])invoke0(jmsService, "getJmsHost"); 704 } 705 706 private ElementProperty[] convertPropertiesToElementProperties(Properties props) 708 { 709 ArrayList list = new ArrayList (); 710 Enumeration keys = props.keys(); 711 while (keys.hasMoreElements()) 712 { 713 final String key = (String )keys.nextElement(); 714 ElementProperty property = new ElementProperty(); 715 property.setName(key); 716 property.setValue((String )props.get(key)); 717 list.add(property); 718 } 719 return (ElementProperty[])list.toArray(new ElementProperty[list.size()]); 720 } 721 722 static final String PROVIDER_TYPE_SERVER = "server"; 723 static final String PROVIDER_TYPE_CLIENT = "client"; 724 725 733 public ObjectName createMessageSecurityProvider( 734 String messageLayer, 736 String providerId, String providerType, String providerClassName, 740 String requestAuthSource, String requestAuthRecipient, 743 String responseAuthSource, String responseAuthRecipient, 746 boolean isDefaultProvider, Properties props, String targetName ) 750 throws Exception 751 { 752 final Target target = getTarget(targetName); 753 check1ToN(target); 754 final ConfigTarget configTarget = target.getConfigTarget(); 755 boolean bMessageConfigJustCreated = false; 756 Config config = ConfigAPIHelper.getConfigByName(getConfigContext(), configTarget.getName()); 757 SecurityService securityService = config.getSecurityService(); 758 759 MessageSecurityConfig messageSecurity = securityService.getMessageSecurityConfigByAuthLayer(messageLayer); 761 if(messageSecurity==null) 762 { 763 messageSecurity = new MessageSecurityConfig(); 765 messageSecurity.setAuthLayer(messageLayer); 766 bMessageConfigJustCreated = true; 767 } 768 769 ProviderConfig provider = new ProviderConfig(); 771 provider.setClassName(providerClassName); 772 provider.setProviderId(providerId); 773 provider.setProviderType(providerType); 774 775 if (null != props) 777 { 778 provider.setElementProperty(convertPropertiesToElementProperties(props)); 779 } 780 781 if(requestAuthSource!=null || requestAuthRecipient!=null ) 783 { 784 RequestPolicy requestPolicy = new RequestPolicy(); 785 if(requestAuthSource!=null) 786 requestPolicy.setAuthSource(requestAuthSource); 787 if(requestAuthRecipient!=null) 788 requestPolicy.setAuthRecipient(requestAuthRecipient); 789 provider.setRequestPolicy(requestPolicy); 790 } 791 792 if(responseAuthSource!=null || responseAuthRecipient!=null ) 794 { 795 ResponsePolicy responsePolicy = new ResponsePolicy(); 796 if(responseAuthSource!=null) 797 responsePolicy.setAuthSource(responseAuthSource); 798 if(responseAuthRecipient!=null) 799 responsePolicy.setAuthRecipient(responseAuthRecipient); 800 provider.setResponsePolicy(responsePolicy); 801 } 802 803 messageSecurity.addProviderConfig(provider); 804 if(isDefaultProvider) 806 { 807 if(PROVIDER_TYPE_SERVER.equals(providerType)) 808 messageSecurity.setDefaultProvider(providerId); 809 else if(PROVIDER_TYPE_CLIENT.equals(providerType)) 810 messageSecurity.setDefaultClientProvider(providerId); 811 else 812 { 813 messageSecurity.setDefaultProvider(providerId); 814 messageSecurity.setDefaultClientProvider(providerId); 815 } 816 } 817 if(bMessageConfigJustCreated) 818 { 819 securityService.addMessageSecurityConfig(messageSecurity); 820 } 821 822 return getMBeanRegistry().getMbeanObjectName("provider-config", 823 new String []{getDomainName(), configTarget.getName(), messageLayer, providerId}); 824 } 825 826 832 public boolean deleteMessageSecurityProvider( 833 String messageLayer, String providerId, String targetName ) throws Exception 837 { 838 final Target target = getTarget(targetName); 839 check1ToN(target); 840 Config config = ConfigAPIHelper.getConfigByName(getConfigContext(), 841 target.getConfigTarget().getName()); 842 SecurityService securityService = config.getSecurityService(); 843 MessageSecurityConfig messageSecurity = 844 securityService.getMessageSecurityConfigByAuthLayer(messageLayer); 845 if(messageSecurity==null) 846 { 847 String msg = localStrings.getString( "admin.mbeans.configs.message_security_config_not_found", 848 new Object []{messageLayer, targetName}); 849 throw new MBeanConfigException(msg); 850 } 851 ProviderConfig[] providers = messageSecurity.getProviderConfig(); 852 if(providers.length==1 && providerId.equals(providers[0].getProviderId())) 853 { 854 securityService.removeMessageSecurityConfig(messageSecurity); 855 return true; 856 } 857 ProviderConfig provider = messageSecurity.getProviderConfigByProviderId(providerId); 858 if(provider==null) 859 { 860 String msg = localStrings.getString( "admin.mbeans.configs.security_provider_not_found", new Object []{providerId, messageLayer, targetName}); 861 throw new MBeanConfigException(msg); 862 } 863 messageSecurity.removeProviderConfig(provider); 864 865 return true; 866 } 867 868 public ObjectName [] listMessageSecurityProviders( 871 String messageLayer, String targetName ) throws Exception 874 { 875 final Target target = getListTarget(targetName); 876 Config config = ConfigAPIHelper.getConfigByName(getConfigContext(), 877 target.getConfigTarget().getName()); 878 SecurityService securityService = config.getSecurityService(); 879 if(securityService==null) 880 return null; 881 if(messageLayer!=null) 882 { 883 MessageSecurityConfig messageSecurity = 884 securityService.getMessageSecurityConfigByAuthLayer(messageLayer); 885 if(messageSecurity==null) 886 { 887 String msg = localStrings.getString( "admin.mbeans.configs.message_security_config_not_found", 888 new Object []{messageLayer, targetName}); 889 throw new MBeanConfigException(msg); 890 } 891 return getMessageSecurityProviders(messageSecurity); 892 } 893 MessageSecurityConfig[] messageSecurities = 895 securityService.getMessageSecurityConfig(); 896 ArrayList arr = new ArrayList (); 897 if(messageSecurities!=null) 898 for(int i=0; i<messageSecurities.length; i++) 899 { 900 ObjectName [] names = getMessageSecurityProviders(messageSecurities[i]); 901 if(names!=null) 902 for(int j=0; j<names.length; j++) 903 arr.add(names[j]); 904 } 905 return (ObjectName [])arr.toArray(new ObjectName [arr.size()]); 906 } 907 908 private ObjectName [] getMessageSecurityProviders( 911 MessageSecurityConfig messageSecurity 912 ) throws Exception 913 { 914 ProviderConfig[] providers = messageSecurity.getProviderConfig(); 915 return ConfigMBeanHelper.getConfigBeansObjectNames( 916 this.getMBeanRegistry(), this.getDomainName(), providers); 917 } 918 920 public ObjectName createJaccProvider( AttributeList attrs, 922 Properties props, 923 String targetName) 924 throws MBeanException 925 { 926 final Target target = getTarget(targetName); 927 check1ToN(target); 928 final ObjectName securityService = getSecurityServiceMBean(target); 929 final ObjectName jaccProvider = (ObjectName )invoke1(securityService, 930 "createJaccProvider", attrs, AttributeList .class.getName()); 931 setProperties(jaccProvider, props); 932 return jaccProvider; 933 } 934 935 public boolean deleteJaccProvider(String name, String targetName) 936 throws MBeanException 937 { 938 final Target target = getTarget(targetName); 939 check1ToN(target); 940 final ObjectName securityService = getSecurityServiceMBean(target); 941 invoke1(securityService, "removeJaccProviderByName", name, 942 String .class.getName()); 943 return true; 944 } 945 946 public ObjectName [] listJaccProviders(String targetName) 947 throws MBeanException 948 { 949 final Target target = getListTarget(targetName); 950 final ObjectName securityService = getSecurityServiceMBean(target); 951 return (ObjectName [])invoke0(securityService, "getJaccProvider"); 952 } 953 954 public ObjectName createThreadPool(AttributeList attrs, 956 Properties props, 957 String targetName) 958 throws MBeanException 959 { 960 final Target target = getTarget(targetName); 961 check1ToN(target); 962 final ObjectName threadPools = getThreadPoolsMBean(target); 963 final ObjectName threadPool = (ObjectName )invoke1(threadPools, 964 "createThreadPool", attrs, AttributeList .class.getName()); 965 setProperties(threadPool, props); 966 return threadPool; 967 } 968 969 public boolean deleteThreadPool(String threadPoolId, String targetName) 970 throws MBeanException 971 { 972 final Target target = getTarget(targetName); 973 check1ToN(target); 974 final ObjectName threadPools = getThreadPoolsMBean(target); 975 invoke1(threadPools, "removeThreadPoolByThreadPoolId", 976 threadPoolId, String .class.getName()); 977 return true; 978 } 979 980 public ObjectName [] listThreadPools(String targetName) 981 throws MBeanException 982 { 983 final Target target = getListTarget(targetName); 984 final ObjectName threadPools = getThreadPoolsMBean(target); 985 return (ObjectName [])invoke0(threadPools, "getThreadPool"); 986 } 987 988 public ObjectName createEjbTimerService(AttributeList al, 990 Properties props, 991 String targetName) 992 throws MBeanException 993 { 994 final ObjectName ejbContainer = getEjbContainer(targetName); 995 final ObjectName on = (ObjectName )invoke1(ejbContainer, 996 "createEjbTimerService", al, AttributeList .class.getName()); 997 setProperties(on, props); 998 return on; 999 } 1000 1001 public boolean deleteEjbTimerService(String targetName) 1002 throws MBeanException 1003 { 1004 final ObjectName ejbContainer = getEjbContainer(targetName); 1005 invoke0(ejbContainer, "removeEjbTimerService"); 1006 return true; 1007 } 1008 1009 public ObjectName createSessionProperties( AttributeList al, 1011 Properties props, 1012 String targetName) 1013 throws MBeanException 1014 { 1015 final Target target = getTarget(targetName); 1016 check1ToN(target); 1017 final ObjectName sessionConfig = getSessionConfigMBean(target, true); 1018 final ObjectName on = (ObjectName )invoke1(sessionConfig, 1019 "createSessionProperties", al, AttributeList .class.getName()); 1020 setProperties(on, props); 1021 return on; 1022 } 1023 1024 public boolean deleteSessionProperties(String targetName) 1025 throws MBeanException 1026 { 1027 final Target target = getTarget(targetName); 1028 check1ToN(target); 1029 final ObjectName sessionConfig = getSessionConfigMBean(target, false); 1030 invoke0(sessionConfig, "removeSessionProperties"); 1031 return true; 1032 } 1033 1034 public ObjectName createManagerProperties( AttributeList al, 1036 Properties props, 1037 String targetName) 1038 throws MBeanException 1039 { 1040 final Target target = getTarget(targetName); 1041 check1ToN(target); 1042 final ObjectName sessionManager = getSessionManagerMBean(target, true); 1043 final ObjectName on = (ObjectName )invoke1(sessionManager, 1044 "createManagerProperties", al, AttributeList .class.getName()); 1045 setProperties(on, props); 1046 return on; 1047 } 1048 1049 public boolean deleteManagerProperties(String targetName) 1050 throws MBeanException 1051 { 1052 final Target target = getTarget(targetName); 1053 check1ToN(target); 1054 final ObjectName sessionManager = getSessionManagerMBean(target, false); 1055 invoke0(sessionManager, "removeManagerProperties"); 1056 return true; 1057 } 1058 1059 public ObjectName createStoreProperties(AttributeList al, 1061 Properties props, 1062 String targetName) 1063 throws MBeanException 1064 { 1065 final Target target = getTarget(targetName); 1066 check1ToN(target); 1067 final ObjectName sessionManager = getSessionManagerMBean(target, true); 1068 final ObjectName on = (ObjectName )invoke1(sessionManager, 1069 "createStoreProperties", al, AttributeList .class.getName()); 1070 setProperties(on, props); 1071 return on; 1072 } 1073 1074 public boolean deleteStoreProperties(String targetName) 1075 throws MBeanException 1076 { 1077 final Target target = getTarget(targetName); 1078 check1ToN(target); 1079 final ObjectName sessionManager = getSessionManagerMBean(target, false); 1080 invoke0(sessionManager, "removeStoreProperties"); 1081 return true; 1082 } 1083 1084 public boolean deleteSessionConfig(String targetName) 1086 throws MBeanException 1087 { 1088 final Target target = getTarget(targetName); 1089 check1ToN(target); 1090 final ObjectName webContainer = getChild("web-container", null, target); 1091 invoke0(webContainer, "removeSessionConfig"); 1092 return true; 1093 } 1094 1095 public ObjectName getHttpService(String targetName) throws MBeanException 1097 { 1098 return getChild("http-service", null, targetName); 1099 } 1100 1101 public ObjectName getIiopService(String targetName) throws MBeanException 1102 { 1103 return getChild("iiop-service", null, targetName); 1104 } 1105 1106 public ObjectName getEjbContainer(String targetName) throws MBeanException 1107 { 1108 return getChild("ejb-container", null, targetName); 1109 } 1110 1111 public ObjectName getWebContainer(String targetName) throws MBeanException 1112 { 1113 return getChild("web-container", null, targetName); 1114 } 1115 1116 public ObjectName getMdbContainer(String targetName) throws MBeanException 1117 { 1118 return getChild("mdb-container", null, targetName); 1119 } 1120 1121 public ObjectName getJmsService(String targetName) throws MBeanException 1122 { 1123 return getChild("jms-service", null, targetName); 1124 } 1125 1126 public ObjectName getLogService(String targetName) throws MBeanException 1127 { 1128 return getChild("log-service", null, targetName); 1129 } 1130 1131 public ObjectName getSecurityService(String targetName) throws MBeanException 1132 { 1133 return getChild("security-service", null, targetName); 1134 } 1135 1136 public ObjectName getTransactionService(String targetName) 1137 throws MBeanException 1138 { 1139 return getChild("transaction-service", null, targetName); 1140 } 1141 1142 public ObjectName getMonitoringService(String targetName) 1143 throws MBeanException 1144 { 1145 return getChild("monitoring-service", null, targetName); 1146 } 1147 1148 public ObjectName getJavaConfig(String targetName) throws MBeanException 1149 { 1150 return getChild("java-config", null, targetName); 1151 } 1152 1153 public ObjectName getHttpListener(String id, String targetName) 1154 throws MBeanException 1155 { 1156 return getChild("http-listener", new String []{id}, targetName); 1157 } 1158 1159 public ObjectName getVirtualServer(String id, String targetName) 1160 throws MBeanException 1161 { 1162 return getChild("virtual-server", new String []{id}, targetName); 1163 } 1164 1165 public ObjectName getIiopListener(String id, String targetName) 1166 throws MBeanException 1167 { 1168 return getChild("iiop-listener", new String []{id}, targetName); 1169 } 1170 1171 public ObjectName getOrb(String targetName) throws MBeanException 1172 { 1173 return getChild("orb", null, targetName); 1174 } 1175 1176 public ObjectName getJmsHost(String name, String targetName) 1177 throws MBeanException 1178 { 1179 return getChild("jms-host", new String []{name}, targetName); 1180 } 1181 1182 public ObjectName getAuthRealm(String name, String targetName) 1183 throws MBeanException 1184 { 1185 return getChild("auth-realm", new String []{name}, targetName); 1186 } 1187 1188 public ObjectName getAuditModule(String name, String targetName) 1189 throws MBeanException 1190 { 1191 return getChild("audit-module", new String []{name}, targetName); 1192 } 1193 1194 public ObjectName getJaccProvider(String name, String targetName) 1195 throws MBeanException 1196 { 1197 return getChild("jacc-provider", new String []{name}, targetName); 1198 } 1199 1200 public ObjectName getModuleLogLevels(String targetName) 1201 throws MBeanException 1202 { 1203 return getChild("module-log-levels", null, targetName); 1204 } 1205 1206 public ObjectName getModuleMonitoringLevels(String targetName) 1207 throws MBeanException 1208 { 1209 return getChild("module-monitoring-levels", null, targetName); 1210 } 1211 1212 public ObjectName getThreadPool(String threadPoolId, String targetName) 1213 throws MBeanException 1214 { 1215 return getChild("thread-pool", new String [] {threadPoolId}, targetName); 1216 } 1217 1218 public ObjectName getEjbTimerService(String targetName) 1219 throws MBeanException 1220 { 1221 return getChild("ejb-timer-service", null, targetName); 1222 } 1223 1224 public ObjectName getProfiler(String targetName) throws MBeanException 1225 { 1226 return getChild("profiler", null, targetName); 1227 } 1228 1229 public ObjectName getSsl(String type, String id, String targetName) 1230 throws MBeanException 1231 { 1232 final Target target = getListTarget(targetName); 1233 ObjectName sslTarget = getSslTargetObjectName(target, id, type); 1234 if ("iiop-service".equals(type)) 1235 { 1236 sslTarget = (ObjectName )invoke0(sslTarget, "getSslClientConfig"); 1237 } 1238 return (ObjectName )invoke0(sslTarget, "getSsl"); 1239 } 1240 1241 public ObjectName getSessionProperties(String targetName) 1242 throws MBeanException 1243 { 1244 return getChild("session-properties", null, targetName); 1245 } 1246 1247 public ObjectName getManagerProperties(String targetName) 1248 throws MBeanException 1249 { 1250 return getChild("manager-properties", null, targetName); 1251 } 1252 1253 public ObjectName getStoreProperties(String targetName) 1254 throws MBeanException 1255 { 1256 return getChild("store-properties", null, targetName); 1257 } 1258 1259 1275 public ObjectName getChild( String type, 1276 String [] location, 1277 String targetName) throws MBeanException 1278 { 1279 return getChild(type, location, getListTarget(targetName)); 1280 } 1281 1282 protected ObjectName getChild(String type, 1283 String [] location, 1284 Target target) throws MBeanException 1285 { 1286 final MBeanRegistryEntry entry = getMBeanRegistryEntry(type); 1287 final MBeanNamingInfo namingInfo = getMBeanNamingInfo(entry, type, 1288 getObjectNameTokens(target, location)); 1289 doPersistenceCheck(namingInfo, getConfigContext()); 1290 final ObjectName on = getObjectName(namingInfo); 1291 postInvoke("getChild", on); 1292 return on; 1293 } 1294 1295 protected MBeanRegistry getMBeanRegistry() throws MBeanException 1296 { 1297 assertIt((super.m_registry != null), 1298 localStrings.getString("configsMBean.null_registry")); 1299 return super.m_registry; 1300 } 1301 1302 Target getListTarget(String targetName) throws MBeanException 1303 { 1304 try 1305 { 1306 return TargetBuilder.INSTANCE.createTarget(VALID_LIST_TYPES, targetName, 1307 getConfigContext()); 1308 } 1309 catch (Exception e) 1310 { 1311 throw MBeanExceptionFormatter.toMBeanException(e, null); 1312 } 1313 } 1314 1315 Target getTarget(String targetName) throws MBeanException 1316 { 1317 try 1318 { 1319 Target target = TargetBuilder.INSTANCE.createTarget(VALID_CREATE_DELETE_TYPES, targetName, 1320 getConfigContext()); 1321 if (target.getType() == TargetType.SERVER || 1322 target.getType() == TargetType.DAS) { 1323 String configName = ServerHelper.getConfigForServer(getConfigContext(), 1326 target.getName()).getName(); 1327 if (!ConfigAPIHelper.isConfigurationReferencedByServerOnly(getConfigContext(), 1328 configName, target.getName())) { 1329 throw new ConfigException(localStrings.getString( 1330 "configurationHasMultipleRefs", target.getName(), configName, 1331 ConfigAPIHelper.getConfigurationReferenceesAsString( 1332 getConfigContext(), configName))); 1333 } 1334 } else if (target.getType() == TargetType.CLUSTER) { 1335 String configName = ClusterHelper.getConfigForCluster(getConfigContext(), 1338 target.getName()).getName(); 1339 if (!ConfigAPIHelper.isConfigurationReferencedByClusterOnly(getConfigContext(), 1340 configName, target.getName())) { 1341 throw new ConfigException(localStrings.getString( 1342 "configurationHasMultipleRefs", target.getName(), configName, 1343 ConfigAPIHelper.getConfigurationReferenceesAsString( 1344 getConfigContext(), configName))); 1345 } 1346 } 1347 return target; 1348 } 1349 catch (Exception e) 1350 { 1351 throw MBeanExceptionFormatter.toMBeanException(e, null); 1352 } 1353 } 1354 1355 1356 void check1ToN(Target target) throws MBeanException 1357 { 1358 1363 1380 } 1381 1382 protected ObjectName getConfigMBean(Target target) throws MBeanException 1383 { 1384 ObjectName configMBean = null; 1385 try 1386 { 1387 final ConfigTarget ct = target.getConfigTarget(); 1388 configMBean = new ObjectName (ct.getTargetObjectName( 1389 new String [] {getDomainName()})); 1390 1391 postInvoke("getConfigMBean", configMBean); 1392 } 1393 catch (Exception e) 1394 { 1395 throw MBeanExceptionFormatter.toMBeanException(e, null); 1396 } 1397 return configMBean; 1398 } 1399 1400 protected ObjectName getHttpServiceMBean(Target target) 1401 throws MBeanException 1402 { 1403 final ObjectName configMBean = getConfigMBean(target); 1404 ObjectName ret = (ObjectName )invoke0(configMBean, "getHttpService"); 1405 return ret; 1406 } 1407 1408 protected ObjectName getIiopServiceMBean(Target target) 1409 throws MBeanException 1410 { 1411 final ObjectName configMBean = getConfigMBean(target); 1412 ObjectName ret = (ObjectName )invoke0(configMBean, "getIiopService"); 1413 return ret; 1414 } 1415 1416 protected ObjectName getSecurityServiceMBean(Target target) 1417 throws MBeanException 1418 { 1419 final ObjectName configMBean = getConfigMBean(target); 1420 ObjectName ret = (ObjectName )invoke0(configMBean, "getSecurityService"); 1421 return ret; 1422 } 1423 1424 protected ObjectName getJavaConfigMBean(Target target) 1425 throws MBeanException 1426 { 1427 final ObjectName configMBean = getConfigMBean(target); 1428 final ObjectName ret = (ObjectName )invoke0( 1429 configMBean, "getJavaConfig"); 1430 assertIt((ret != null), 1431 localStrings.getString("configsMBean.no_java_config")); 1432 return ret; 1433 } 1434 1435 protected ObjectName getHttpListenerMBean(Target target, String id) 1436 throws MBeanException 1437 { 1438 return (ObjectName )invoke1(getHttpServiceMBean(target), 1439 "getHttpListenerById", id, String .class.getName()); 1440 } 1441 1442 protected ObjectName getIiopListenerMBean(Target target, String id) 1443 throws MBeanException 1444 { 1445 return (ObjectName )invoke1(getIiopServiceMBean(target), 1446 "getIiopListenerById", id, String .class.getName()); 1447 } 1448 1449 protected ObjectName getSslTargetObjectName(Target target, 1450 String id, 1451 String type) 1452 throws MBeanException 1453 { 1454 ObjectName on = null; 1455 if ("http-listener".equals(type)) 1456 { 1457 on = getHttpListenerMBean(target, id); 1458 } 1459 else if ("iiop-listener".equals(type)) 1460 { 1461 on = getIiopListenerMBean(target, id); 1462 } 1463 else if ("iiop-service".equals(type)) 1464 { 1465 on = getIiopServiceMBean(target); 1466 } 1467 else 1468 { 1469 throw MBeanExceptionFormatter.toMBeanException(null, 1470 localStrings.getString("configsMBean.invalid_ssl_target_type", 1471 type)); 1472 } 1473 assertIt((on != null), 1474 localStrings.getString("configsMBean.target_for_ssl_not_found")); 1475 return on; 1476 } 1477 1478 protected ObjectName getAuthRealmMBean(Target target, String name) 1479 throws MBeanException 1480 { 1481 final ObjectName securityService = getSecurityServiceMBean(target); 1482 final ObjectName authRealm = (ObjectName )invoke1(securityService, 1483 "getAuthRealmByName", name, String .class.getName()); 1484 assertIt((authRealm != null), localStrings.getString( 1485 "configsMBean.auth_realm_not_found", name)); 1486 return authRealm; 1487 } 1488 1489 protected ObjectName getJmsServiceMBean(Target target, boolean create) 1490 throws MBeanException 1491 { 1492 final ObjectName configMBean = getConfigMBean(target); 1493 ObjectName on = null; 1494 try 1495 { 1496 on = (ObjectName )invoke0(configMBean, "getJmsService"); 1497 } 1498 catch (Exception e) 1499 { 1500 } 1502 if ((null == on) && create) 1503 { 1504 on = (ObjectName )invoke1(configMBean, 1505 "createJmsService", null, AttributeList .class.getName()); 1506 } 1507 return on; 1508 } 1509 1510 protected ObjectName getThreadPoolsMBean(Target target) 1511 throws MBeanException 1512 { 1513 final ObjectName configMBean = getConfigMBean(target); 1514 ObjectName ret = (ObjectName )invoke0(configMBean, "getThreadPools"); 1515 return ret; 1516 } 1517 1518 protected ObjectName getSessionConfigMBean(Target target, boolean create) 1519 throws MBeanException 1520 { 1521 ObjectName sessionConfig = null; 1522 try 1523 { 1524 sessionConfig = getChild("session-config", null, target); 1525 } 1526 catch (MBeanException mbe) 1527 { 1528 if (create) 1529 { 1530 final ObjectName webContainer = 1532 getChild("web-container", null, target); 1533 sessionConfig = (ObjectName )invoke1(webContainer, 1534 "createSessionConfig", null, AttributeList .class.getName()); 1535 } 1536 else 1537 { 1538 throw mbe; 1539 } 1540 } 1541 return sessionConfig; 1542 } 1543 1544 protected ObjectName getSessionManagerMBean(Target target, boolean create) 1545 throws MBeanException 1546 { 1547 final ObjectName sessionConfig = getSessionConfigMBean(target, create); 1548 ObjectName sessionManager = null; 1549 try 1550 { 1551 sessionManager = getChild("session-manager", null, target); 1552 } 1553 catch (MBeanException mbe) 1554 { 1555 if (create) 1556 { 1557 sessionManager = (ObjectName )invoke1(sessionConfig, 1559 "createSessionManager", null, AttributeList .class.getName()); 1560 } 1561 else 1562 { 1563 throw mbe; 1564 } 1565 } 1566 return sessionManager; 1567 } 1568 1569 protected MBeanServer getMBeanServer() throws MBeanException 1570 { 1571 return com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer(); 1572 } 1573 1574 protected void preInvoke(String opName, Object [] params, String [] signature) 1575 throws MBeanException 1576 { 1577 } 1578 1579 protected void postInvoke(String opName, Object ret) throws MBeanException 1580 { 1581 } 1582 1583 protected String getDefaultAuthRealm(Target target) throws MBeanException 1584 { 1585 final ObjectName on = getSecurityServiceMBean(target); 1586 return (String )getAttribute0(on, "default_realm"); 1587 } 1588 1589 protected String [] getObjectNameTokens(Target target, String [] location) 1590 throws MBeanException 1591 { 1592 if (null == location) { location = new String [0]; } 1593 final String [] onTokens = new String [location.length + 2]; 1594 onTokens[0] = getDomainName(); 1595 onTokens[1] = getConfigRef(target); 1596 for (int i = 0; i < location.length; i++) 1597 { 1598 onTokens[i+2] = location[i]; 1599 } 1600 return onTokens; 1601 } 1602 1603 protected String getConfigRef(Target target) throws MBeanException 1604 { 1605 String configRef = null; 1606 try 1607 { 1608 configRef = target.getConfigRef(); 1609 } 1610 catch (Exception e) 1611 { 1612 throw MBeanExceptionFormatter.toMBeanException(e, null); 1613 } 1614 return configRef; 1615 } 1616 1617 protected String [] getJvmOptions(boolean isProfiler, Target target) 1618 throws MBeanException 1619 { 1620 final ObjectName targetON = getJvmOptionsTargetObjectName( 1621 target, isProfiler); 1622 String [] jvmOptions = (String [])getAttribute0(targetON, "jvm_options"); 1623 if (null == jvmOptions) { jvmOptions = new String [0]; } 1624 return jvmOptions; 1625 } 1626 1627 private ObjectName createSslClientConfig(ObjectName iiopService) 1628 throws MBeanException 1629 { 1630 ObjectName ret = (ObjectName )invoke1(iiopService, 1631 "createSslClientConfig", null, 1632 AttributeList .class.getName()); 1633 return ret; 1634 } 1635 1636 private Object invoke0(ObjectName on, String opName) throws MBeanException 1637 { 1638 return invokeN(on, opName, null, null); 1639 } 1640 1641 private Object invoke1(ObjectName on, String opName, Object o, String cls) 1642 throws MBeanException 1643 { 1644 return invokeN( on, opName, new Object [] {o}, new String [] {cls} ); 1645 } 1646 1647 private Object invokeN(ObjectName on, 1648 String opName, 1649 Object [] params, 1650 String [] signature) 1651 throws MBeanException 1652 { 1653 Object ret = null; 1654 try 1655 { 1656 ret = getMBeanServer().invoke(on, opName, params, signature); 1657 postInvoke(opName, ret); 1658 } 1659 catch (Exception e) 1660 { 1661 throw MBeanExceptionFormatter.toMBeanException(e, null); 1662 } 1663 return ret; 1664 } 1665 1666 private Object getPropertyValue0(ObjectName on, String propName) 1667 throws MBeanException 1668 { 1669 Object value = null; 1670 try 1671 { 1672 value = invoke1(on, "getPropertyValue", propName, "java.lang.String"); 1673 } 1674 catch (Exception e) 1675 { 1676 throw MBeanExceptionFormatter.toMBeanException(e, null); 1677 } 1678 return value; 1679 } 1680 1681 private Object getAttribute0(ObjectName on, String attrName) 1682 throws MBeanException 1683 { 1684 Object value = null; 1685 try 1686 { 1687 value = getMBeanServer().getAttribute(on, attrName); 1688 } 1689 catch (Exception e) 1690 { 1691 throw MBeanExceptionFormatter.toMBeanException(e, null); 1692 } 1693 return value; 1694 } 1695 1696 private void setAttribute0(ObjectName on, String attrName, Object value) 1697 throws MBeanException 1698 { 1699 try 1700 { 1701 final Attribute attr = new Attribute (attrName, value); 1702 getMBeanServer().setAttribute(on, attr); 1703 } 1704 catch (Exception e) 1705 { 1706 throw MBeanExceptionFormatter.toMBeanException(e, null); 1707 } 1708 } 1709 1710 private ObjectName getJvmOptionsTargetObjectName(Target target, 1711 boolean isProfiler) 1712 throws MBeanException 1713 { 1714 ObjectName on = getJavaConfigMBean(target); 1715 if (isProfiler) 1716 { 1717 on = (ObjectName )invoke0(on, "getProfiler"); 1718 } 1719 assertIt((on != null), localStrings.getString( 1720 "configsMBean.target_for_jvm_options_not_found")); 1721 return on; 1722 } 1723 1724 private void setProperties(ObjectName on, Properties props) 1725 throws MBeanException 1726 { 1727 if (null != props) 1728 { 1729 Enumeration keys = props.keys(); 1730 while (keys.hasMoreElements()) 1731 { 1732 final String key = (String )keys.nextElement(); 1733 final Attribute property = new Attribute (key, props.get(key)); 1734 invoke1(on, "setProperty", property, Attribute .class.getName()); 1735 } 1736 } 1737 } 1738 1739 private void assertIt(boolean b, Object msg) 1740 throws MBeanException 1741 { 1742 if (!b) 1743 { 1744 throw MBeanExceptionFormatter.toMBeanException( 1745 null, msg.toString()); 1746 } 1747 } 1748 1749 private MBeanRegistryEntry getMBeanRegistryEntry(String type) 1750 throws MBeanException 1751 { 1752 1753 MBeanRegistryEntry entry = null; 1754 try 1755 { 1756 entry = getMBeanRegistry().findMBeanRegistryEntryByType(type); 1757 } 1758 catch (Exception e) 1759 { 1760 throw MBeanExceptionFormatter.toMBeanException(e, null); 1761 } 1762 assertIt((entry != null), 1763 localStrings.getString("configsMBean.no_registry_entry", type)); 1764 return entry; 1765 } 1766 1767 private MBeanNamingInfo getMBeanNamingInfo(MBeanRegistryEntry entry, 1768 String type, 1769 String [] loc) 1770 throws MBeanException 1771 { 1772 1773 MBeanNamingInfo namingInfo = null; 1774 try 1775 { 1776 namingInfo = new MBeanNamingInfo(entry.getNamingDescriptor(), 1777 type, loc); 1778 } 1779 catch (Exception e) 1780 { 1781 throw MBeanExceptionFormatter.toMBeanException(e, null); 1782 } 1783 return namingInfo; 1784 } 1785 1786 private void doPersistenceCheck(MBeanNamingInfo info, ConfigContext ctx) 1787 throws MBeanException 1788 { 1789 ConfigBean cb = null; 1790 try 1791 { 1792 final String xpath = info.getXPath(); 1793 cb = ConfigBeansFactory.getConfigBeanByXPath(ctx, xpath); 1794 if (null == cb) 1795 { 1796 throw new InstanceNotFoundException ( 1797 localStrings.getString("configsMBean.mbean_not_found", 1798 info.getObjectName())); 1799 } 1800 } 1801 catch (Exception e) 1802 { 1803 throw MBeanExceptionFormatter.toMBeanException(e, null); 1804 } 1805 } 1806 1807 private ObjectName getObjectName(MBeanNamingInfo info) 1808 throws MBeanException 1809 { 1810 ObjectName on = null; 1811 try 1812 { 1813 on = info.getObjectName(); 1814 } 1815 catch (Exception e) 1816 { 1817 throw MBeanExceptionFormatter.toMBeanException(e, null); 1818 } 1819 return on; 1820 } 1821 1822 private void checkElementDoesnotExist(ObjectName targetON, 1823 String getter, 1824 Object msg) 1825 throws MBeanException 1826 { 1827 ObjectName on = null; 1828 try 1829 { 1830 on = (ObjectName )invoke0(targetON, getter); 1831 } 1832 catch (MBeanException mbe) 1833 { 1834 } 1836 if (on != null) 1837 { 1838 throw MBeanExceptionFormatter.toMBeanException( 1839 null, msg.toString()); 1840 } 1841 } 1842 1847 private void addMandatoryVirtualServerProperties(final AttributeList al, 1848 final Properties p) 1849 { 1850 setProperty(p, false, SystemPropertyConstants.ACCESSLOG_PROPERTY, 1851 SystemPropertyConstants.getAccessLogDefaultValue()); 1852 final String ca = 1853 AttributeListUtils.toJmx12Attribute(ServerTags.DEFAULT_WEB_MODULE); 1854 if (! AttributeListUtils. 1855 containsNamedAttribute(al, ca)) 1856 { 1857 setProperty(p, false, SystemPropertyConstants.DOCROOT_PROPERTY, 1858 SystemPropertyConstants.getDocRootDefaultValue()); 1859 } 1860 else 1861 { 1862 final Attribute defaultWb = 1863 (Attribute )AttributeListUtils.asNameMap(al).get(ca); 1864 final String val = (String )defaultWb.getValue(); 1865 if ((val == null) || "".equals(val)) 1866 { 1867 setProperty(p, false, SystemPropertyConstants.DOCROOT_PROPERTY, 1868 SystemPropertyConstants.getDocRootDefaultValue()); 1869 } 1870 } 1871 } 1872 1873 private void setProperty(final Properties table, final boolean force, 1874 final String name, final String value) 1875 { 1876 if (force) 1877 table.setProperty(name, value); 1878 else 1879 if (! table.containsKey(name)) 1880 table.setProperty(name, value); 1881 } 1882 1883 1894 private Properties copyProperties(final Properties p) 1895 { 1896 final Properties nn = new Properties (); 1897 if (p != null) 1898 { 1899 final Enumeration e = p.propertyNames(); 1900 while (e.hasMoreElements()) 1901 { 1902 final String key = (String )e.nextElement(); 1903 final String value = p.getProperty(key); 1904 nn.setProperty(key, value); 1905 } 1906 } 1907 return ( nn ); 1908 } 1909 1910 1911 1915 protected String getDefaultHTTPListenerAcceptorThreads() { 1916 return DEFAULT_HTTP_LISTENER_ACCEPTOR_THREADS; 1917 } 1918 1919 1923 protected Config getConfigBeanForTarget(Target target) throws Exception 1924 { 1925 final ConfigTarget configTarget = target.getConfigTarget(); 1926 return ConfigAPIHelper.getConfigByName(getConfigContext(), configTarget.getName()); 1927 } 1928} 1929 | Popular Tags |