[Mc4j-cvs] SF.net SVN: mc4j:[622] trunk/mc4j/modules/ems
Brought to you by:
ghinkl
From: <ian...@us...> - 2010-08-17 22:41:11
|
Revision: 622 http://mc4j.svn.sourceforge.net/mc4j/?rev=622&view=rev Author: ianpspringer Date: 2010-08-17 22:41:04 +0000 (Tue, 17 Aug 2010) Log Message: ----------- wrap a couple calls in doPrivileged blocks so EMS will work when Java security is enabled, as long as the callers have the appropriate permissions; bump up EMS version to 1.2.15 Modified Paths: -------------- trunk/mc4j/modules/ems/build.xml trunk/mc4j/modules/ems/ems.iml trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/ConnectionFactory.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/AbstractConnectionProvider.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/InternalVMProvider.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/JMXRemotingConnectionProvider.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/WeblogicConnectionProvider.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/WebsphereConnectionProvider.java Modified: trunk/mc4j/modules/ems/build.xml =================================================================== --- trunk/mc4j/modules/ems/build.xml 2010-08-02 19:04:59 UTC (rev 621) +++ trunk/mc4j/modules/ems/build.xml 2010-08-17 22:41:04 UTC (rev 622) @@ -29,12 +29,10 @@ <property name="module.jar" value="org-mc4j-ems.jar"/> - <property name="release.version" value="1.2.14"/> + <property name="release.version" value="1.2.15"/> - <target - name="init" - description="Initializes the mc4j-ems build system."> + <target name="init" description="Initializes the MC4J-EMS build system."> <echo message="MC4J-EMS Build Environment - Try [ant -projecthelp] for more info."/> @@ -236,18 +234,20 @@ </java> </target> + <target name="test-OTHER"> <java classname="org.mc4j.ems.test.ConnectionTest" fork="yes"> <classpath> <pathelement location="dist/org-mc4j-ems.jar"/> <pathelement location="lib/commons-logging.jar"/> <pathelement location="classes/test"/> - <pathelement location="C:\projects\jboss\JON_DEV_1_4\hyperic_hq\thirdparty\lib\log4j.jard"/> + <pathelement location="C:\projects\jboss\JON_DEV_1_4\hyperic_hq\thirdparty\lib\log4j.jar"/> <!--<path location="/Users/ghinkle/development/tools/jboss-4.0.2/server/default/lib/jboss-jsr77.jar"/>--> </classpath> </java> </target> + <target name="run" description="Directly starts MC4J with the settings as the installer would use."> <echo>Starting MC4J-EMS Test</echo> <java @@ -282,8 +282,8 @@ </java> </target> - <target name="all-test" depends="compile, jars, run" description="Compile and run the tests."> - </target> + <target name="all-test" depends="compile, jars, run" description="Compile and run the tests."/> </project> + Modified: trunk/mc4j/modules/ems/ems.iml =================================================================== --- trunk/mc4j/modules/ems/ems.iml 2010-08-02 19:04:59 UTC (rev 621) +++ trunk/mc4j/modules/ems/ems.iml 2010-08-17 22:41:04 UTC (rev 622) @@ -36,7 +36,7 @@ <orderEntry type="module-library"> <library> <CLASSES> - <root url="jar://$MODULE_DIR$/../../../../opt/jdk-1.6.0_07/lib/tools.jar!/" /> + <root url="jar://$USER_HOME$/opt/jdk-1.6.0_07/lib/tools.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> @@ -45,7 +45,7 @@ <orderEntry type="module-library"> <library> <CLASSES> - <root url="jar://$MODULE_DIR$/../../../../opt/jdk-1.6.0_14/lib/tools.jar!/" /> + <root url="jar://$USER_HOME$/opt/jdk-1.6.0_14/lib/tools.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> Modified: trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/ConnectionFactory.java =================================================================== --- trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/ConnectionFactory.java 2010-08-02 19:04:59 UTC (rev 621) +++ trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/ConnectionFactory.java 2010-08-17 22:41:04 UTC (rev 622) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2004 Greg Hinkle + * Copyright 2002-2010 Greg Hinkle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.mc4j.ems.connection; import java.io.File; import java.io.FileFilter; import java.io.FilenameFilter; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -111,34 +112,35 @@ * @param connectionSettings the connection settings for the connection * @return a ConnectionProvider that you can get live connection from. */ - public ConnectionProvider getConnectionProvider(ConnectionSettings connectionSettings) + public ConnectionProvider getConnectionProvider(final ConnectionSettings connectionSettings) { String className = connectionSettings.getConnectionType().getConnectionNodeClassName(); try { - // TODO GH: Does this need to be configurable per connection? - ClassLoader loader = ClassLoaderFactory.getInstance().buildClassLoader(connectionSettings); + ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { + return ClassLoaderFactory.getInstance().buildClassLoader(connectionSettings); + } + }); - log.debug("Loading connection class from ClassLoader [" + loader + "] ConnectionProvider class [" + className + "]"); + log.debug("Loading connection class [" + className + "] from ClassLoader [" + loader + "]..."); // TODO GH: Add intelligent classloader layer here that can either work // directly against current classloader or build a non-delegating child // to override with connection specific classes Class clazz = Class.forName(className, false, loader); + ConnectionProvider connectionProvider = (ConnectionProvider) clazz.newInstance(); - ConnectionProvider connectionProvider = - (ConnectionProvider) clazz.newInstance(); - connectionProvider.initialize(connectionSettings); return connectionProvider; } catch (IllegalAccessException e) { - throw new ConnectionException("Could not access ConnectionClass", e); + throw new ConnectionException("Could not access ConnectionClass " + className, e); } catch (InstantiationException e) { - throw new ConnectionException("Could not instantiate ConnectionClass", e); + throw new ConnectionException("Could not instantiate ConnectionClass " + className, e); } catch (ClassNotFoundException e) { throw new ConnectionException("Could not find ConnectionClass " + className, e); } @@ -152,7 +154,7 @@ */ public EmsConnection connect(ConnectionSettings connectionSettings) { - log.info("Connecting to " + connectionSettings.toString()); + log.info("Connecting to " + connectionSettings + "..."); return getConnectionProvider(connectionSettings).connect(); } @@ -167,7 +169,7 @@ * first clear the settings' classpath entries. This method appends class path entries * to the existing list. * - * @param connectionSettings the ConnectionSettings to update with recommeneded class + * @param connectionSettings the ConnectionSettings to update with recommended class * path entries */ public void discoverServerClasses(ConnectionSettings connectionSettings) { @@ -316,7 +318,7 @@ if (children.length == 1) { return children[0]; } else { - //log.info("Connection library dependancy [" + childName + "] not found in directory: " + directory.getAbsolutePath()); + //log.info("Connection library dependency [" + childName + "] not found in directory: " + directory.getAbsolutePath()); return null; } } Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/AbstractConnectionProvider.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/AbstractConnectionProvider.java 2010-08-02 19:04:59 UTC (rev 621) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/AbstractConnectionProvider.java 2010-08-17 22:41:04 UTC (rev 622) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2004 Greg Hinkle + * Copyright 2002-2010 Greg Hinkle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.mc4j.ems.impl.jmx.connection.support.providers; import org.mc4j.ems.connection.EmsConnection; @@ -92,15 +91,15 @@ } - public final EmsConnection connect() { try { - doConnect(); + doConnect(); + this.connected = true; this.connectionFailure = false; } catch (Exception e) { - throw new EmsConnectException("Could not connect [" + connectionSettings.getServerUrl() + "] " + e.toString(), e); + throw new EmsConnectException("Could not connect [" + connectionSettings.getServerUrl() + "] " + e, e); } if (existingConnection == null) { Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/InternalVMProvider.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/InternalVMProvider.java 2010-08-02 19:04:59 UTC (rev 621) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/InternalVMProvider.java 2010-08-17 22:41:04 UTC (rev 622) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 Greg Hinkle + * Copyright 2002-2010 Greg Hinkle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.mc4j.ems.impl.jmx.connection.support.providers; import org.mc4j.ems.connection.support.metadata.InternalVMTypeDescriptor; @@ -21,6 +20,9 @@ import javax.management.MBeanServer; import javax.management.MBeanServerFactory; import java.lang.management.ManagementFactory; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; /** * Connect to the platform mbean server in the VM that EMS is running in. @@ -45,12 +47,20 @@ MBeanServer foundServer = null; if (mbeanSearch != null) { - for (Object mbs : MBeanServerFactory.findMBeanServer(null)) + ArrayList mbeanServers = AccessController.doPrivileged(new PrivilegedAction<ArrayList>() { - if (mbeanSearch.equals(((MBeanServer)mbs).getDefaultDomain())) + public ArrayList run() { - foundServer = (MBeanServer) mbs; + return MBeanServerFactory.findMBeanServer(null); } + }); + for (Object mbeanServerObj : mbeanServers) + { + MBeanServer mbeanServer = (MBeanServer) mbeanServerObj; + if (mbeanSearch.equals(mbeanServer.getDefaultDomain())) + { + foundServer = mbeanServer; + } } } Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/JMXRemotingConnectionProvider.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/JMXRemotingConnectionProvider.java 2010-08-02 19:04:59 UTC (rev 621) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/JMXRemotingConnectionProvider.java 2010-08-17 22:41:04 UTC (rev 622) @@ -16,7 +16,6 @@ package org.mc4j.ems.impl.jmx.connection.support.providers; - import org.mc4j.ems.connection.EmsConnectException; import org.mc4j.ems.connection.EmsException; import org.mc4j.ems.impl.jmx.connection.support.providers.proxy.JMXRemotingMBeanServerProxy; @@ -47,7 +46,6 @@ import java.util.Map; import java.util.Set; - /** * Represents a Connection to a JSR 160 compliant RMI server * Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/WeblogicConnectionProvider.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/WeblogicConnectionProvider.java 2010-08-02 19:04:59 UTC (rev 621) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/WeblogicConnectionProvider.java 2010-08-17 22:41:04 UTC (rev 622) @@ -16,7 +16,6 @@ package org.mc4j.ems.impl.jmx.connection.support.providers; - import org.mc4j.ems.impl.jmx.connection.support.providers.proxy.GenericMBeanServerProxy; import javax.management.MBeanServer; @@ -25,7 +24,6 @@ import java.lang.reflect.Method; import java.util.Hashtable; - /** * This Node acts as a connection to a WebLogic(tm) MBean Server. * Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/WebsphereConnectionProvider.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/WebsphereConnectionProvider.java 2010-08-02 19:04:59 UTC (rev 621) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/WebsphereConnectionProvider.java 2010-08-17 22:41:04 UTC (rev 622) @@ -27,7 +27,6 @@ import java.net.URI; import java.util.Properties; - /** * This Node acts as a connection to a WebSphere(tm) MBean Server (TMX4J based). * @@ -209,5 +208,4 @@ return statsProxy.getFailures(); } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |