1 23 24 29 package com.sun.enterprise.management.config; 30 31 import java.util.Map ; 32 import java.util.HashMap ; 33 import java.util.Set ; 34 35 import javax.management.ObjectName ; 36 37 import com.sun.appserv.management.base.AMX; 38 import com.sun.appserv.management.base.Container; 39 import com.sun.appserv.management.base.XTypes; 40 import com.sun.appserv.management.config.AMXConfig; 41 import com.sun.appserv.management.config.AdminServiceConfig; 42 import com.sun.appserv.management.config.DomainConfig; 43 import com.sun.appserv.management.config.ConfigConfig; 44 import com.sun.appserv.management.config.JMXConnectorConfig; 45 import com.sun.appserv.management.config.SSLConfig; 46 import com.sun.appserv.management.config.JMXConnectorConfigKeys; 47 import com.sun.appserv.management.config.PropertiesAccess; 48 import com.sun.appserv.management.config.SecurityServiceConfig; 49 import com.sun.appserv.management.config.AuthRealmConfig; 50 51 import com.sun.appserv.management.util.misc.MapUtil; 52 53 54 import com.sun.enterprise.management.AMXTestBase; 55 import com.sun.enterprise.management.Capabilities; 56 57 59 public final class JMXConnectorConfigTest extends ConfigMgrTestBase 60 { 61 static final String ADDRESS = "0.0.0.0"; 62 static final String TEST_REALM_CLASS = "com.test.DUMMY"; 63 static final String DEFAULT_PORT = "17377"; 64 65 static final Map <String ,String > OPTIONAL = new HashMap <String ,String >(); 66 67 static 68 { 69 OPTIONAL.put( PropertiesAccess.PROPERTY_PREFIX + "xyz", "abc"); 70 OPTIONAL.put( JMXConnectorConfigKeys.SECURITY_ENABLED_KEY, "false"); 71 } 72 73 public 74 JMXConnectorConfigTest() 75 { 76 if ( checkNotOffline( "ensureDefaultInstance" ) ) 77 { 78 ensureDefaultInstance( getConfigConfig().getAdminServiceConfig() ); 79 } 80 } 81 82 public static String 83 getDefaultInstanceName() 84 { 85 return getDefaultInstanceName( "JMXConnectorConfig" ); 86 } 87 88 public static JMXConnectorConfig 89 ensureDefaultInstance( final AdminServiceConfig adminServiceConfig ) 90 { 91 JMXConnectorConfig result = 92 adminServiceConfig.getJMXConnectorConfigMap().get( getDefaultInstanceName() ); 93 94 if ( result == null ) 95 { 96 final SecurityServiceConfig securityServiceConfig = 97 getConfigConfig( adminServiceConfig ).getSecurityServiceConfig(); 98 99 final AuthRealmConfig defaultAuthRealm = 100 AuthRealmConfigTest.ensureDefaultInstance( securityServiceConfig ); 101 102 result = createInstance( getDefaultInstanceName(), 103 ADDRESS, DEFAULT_PORT, defaultAuthRealm, OPTIONAL ); 104 } 105 106 return result; 107 } 108 109 public static JMXConnectorConfig 110 createInstance( 111 final String name, 112 final String address, 113 final String port, 114 final AuthRealmConfig authRealm, 115 final Map <String ,String > optional ) 116 { 117 final AdminServiceConfig adminServiceConfig = 118 getConfigConfig( authRealm ).getAdminServiceConfig(); 119 120 return adminServiceConfig.createJMXConnectorConfig( name, 121 address, port, authRealm.getName(), optional ); 122 } 123 124 125 126 protected Container 127 getProgenyContainer() 128 { 129 return getAdminServiceConfig(); 130 } 131 132 protected String 133 getProgenyJ2EEType() 134 { 135 return XTypes.JMX_CONNECTOR_CONFIG; 136 } 137 138 final SecurityServiceConfig 139 getSecurityServiceConfig() 140 { 141 return getConfigConfig().getSecurityServiceConfig(); 142 } 143 144 final AuthRealmConfig 145 createAuthRealmConfig( final String name ) 146 { 147 removeAuthRealmConfig( name ); 148 149 return getSecurityServiceConfig().createAuthRealmConfig( 150 name, TEST_REALM_CLASS, null ); 151 } 152 153 private String 154 createAuthRealmName( final String progenyName ) 155 { 156 return progenyName + ".TestRealm"; 157 } 158 159 final void 160 removeAuthRealmConfig( final String name ) 161 { 162 try 163 { 164 getSecurityServiceConfig().removeAuthRealmConfig( name ); 165 } 166 catch( Exception e ) 167 { 168 } 169 } 170 171 protected void 172 removeProgeny( final String name ) 173 { 174 try 175 { 176 getAdminServiceConfig().removeJMXConnectorConfig( name ); 177 } 178 finally 179 { 180 try 181 { 182 removeAuthRealmConfig( createAuthRealmName( name ) ); 183 } 184 catch( Exception e ) 185 { 186 } 187 } 188 } 189 190 protected final AMXConfig 191 createProgeny( 192 final String name, 193 final Map <String ,String > options ) 194 { 195 final Map <String ,String > allOptions = MapUtil.newMap( options, OPTIONAL ); 196 197 final int port = (name.hashCode() % 16000) + 33111; 198 199 final String authRealmName = createAuthRealmName( name ); 200 final AuthRealmConfig authRealmConfig = createAuthRealmConfig( authRealmName ); 201 202 try 203 { 204 return getAdminServiceConfig().createJMXConnectorConfig(name, 205 ADDRESS, "" + port, authRealmName, allOptions); 206 } 207 catch( Exception e ) 208 { 209 removeAuthRealmConfig( authRealmName ); 210 throw new RuntimeException ( e ); 211 } 212 } 213 214 final AdminServiceConfig 215 getAdminServiceConfig() 216 { 217 return( getConfigConfig(). getAdminServiceConfig()); 218 } 219 220 public void 221 testCreateSSL() 222 throws Exception 223 { 224 if ( ! checkNotOffline( "testCreateSSL" ) ) 225 { 226 return; 227 } 228 229 final String NAME = "JMXConnectorConfigTest-testCreateSSL"; 230 try 231 { 232 removeEx(NAME); 233 final JMXConnectorConfig newConfig = 234 (JMXConnectorConfig)createProgeny( NAME, null); 235 236 final Map <String ,JMXConnectorConfig> jmxConnectors = 237 getAdminServiceConfig().getJMXConnectorConfigMap(); 238 239 final JMXConnectorConfig jmxConnector = (JMXConnectorConfig) 240 jmxConnectors.get(NAME); 241 assert jmxConnector != null; 242 assert jmxConnector == newConfig; 243 244 final String CERT_NICKNAME = NAME + "Cert"; 245 246 final SSLConfig ssl = jmxConnector.createSSLConfig( CERT_NICKNAME, null); 247 assert ssl != null; 248 assert ssl.getCertNickname().equals( CERT_NICKNAME ); 249 250 jmxConnector.removeSSLConfig(); 251 } 252 finally 253 { 254 remove(NAME); 255 } 256 } 257 } 258 259 260 | Popular Tags |