Skip to content

Commit

Permalink
Add basic T3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
qtc-de committed Dec 10, 2024
1 parent 8365b04 commit b247043
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
32 changes: 29 additions & 3 deletions beanshooter/src/eu/tneitzel/beanshooter/plugin/PluginSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import eu.tneitzel.beanshooter.plugin.providers.RMIProvider;
import eu.tneitzel.beanshooter.plugin.providers.ResponseHandlerProvider;
import eu.tneitzel.beanshooter.plugin.providers.SocketFactoryProvider;
import eu.tneitzel.beanshooter.plugin.providers.T3AuthenticationProvider;
import eu.tneitzel.beanshooter.plugin.providers.YsoSerialProvider;
import eu.tneitzel.beanshooter.utils.Utils;

Expand Down Expand Up @@ -60,15 +61,17 @@ public class PluginSystem {
*/
public static void init(String pluginPath)
{
mBeanServerProvider = selectProvider();
mBeanServerProvider = selectMBeanProvider();
socketFactoryProvider = new SocketFactoryProvider();
payloadProvider = new YsoSerialProvider();
argumentProvider = new ArgumentProvider();
responseHandler = new ResponseHandlerProvider();
authenticationProvider = new AuthenticationProvider();
authenticationProvider = selectAuthProvider();

if(pluginPath != null)
{
loadPlugin(pluginPath);
}
}

/**
Expand Down Expand Up @@ -105,7 +108,9 @@ private static void loadPlugin(String pluginPath)
jarStream.close();

if(pluginClassName == null)
{
throw new MalformedPluginException();
}

}

Expand Down Expand Up @@ -179,20 +184,41 @@ private static void loadPlugin(String pluginPath)
*
* @return IMBeanServerProvider according to the specified command lien arguments.
*/
private static IMBeanServerProvider selectProvider()
private static IMBeanServerProvider selectMBeanProvider()
{
if (BeanshooterOption.CONN_JMXMP.getBool())
{
return new JMXMPProvider();
}

if (BeanshooterOption.CONN_JNDI.notNull())
{
return new JNDIProvider();
}

if (BeanshooterOption.CONN_JOLOKIA.getBool())
{
return new JolokiaProvider();
}

return new RMIProvider();
}

/**
* Returns the IAuthenticationProvider according to the specified command line arguments.
*
* @return IAuthenticationProvider according to the specified command lien arguments.
*/
private static IAuthenticationProvider selectAuthProvider()
{
if (BeanshooterOption.CONN_JNDI.getValue("").startsWith("service:jmx:t3"))
{
return new T3AuthenticationProvider();
}

return new AuthenticationProvider();
}

/**
* Attempt to obtain an MBeanServerConnection to the specified remote MBeanServer. Authentication related
* exceptions are handled automatically. If this is not desired, the getMBeanServerConnectionUnmanaged function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ else if (connString.startsWith("service:jmx:remote"))
connString += String.format("://%s:%d", host, port);
}

else if (connString.startsWith("service:jmx:t3"))
{
connString += String.format("://%s:%d/jndi/weblogic.management.mbeanservers.runtime", host, port);
}

else
{
Logger.eprintlnMixedYellow("The specified", "connection string", "seems to be invalid.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package eu.tneitzel.beanshooter.plugin.providers;

import java.util.HashMap;
import java.util.Map;

import javax.naming.Context;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.rmi.ssl.SslRMIClientSocketFactory;

import eu.tneitzel.beanshooter.operation.BeanshooterOption;
import eu.tneitzel.beanshooter.plugin.IAuthenticationProvider;

/**
* T3 compatible authentication provider. Has only some small deviations from the default
* authentication provider.
*
* @author Tobias Neitzel (@qtc_de)
*/
public class T3AuthenticationProvider implements IAuthenticationProvider
{
/**
* Authentication to T3 endpoints requires the credentials to be passed in a different
* format than for the usual JMX auth. Moreover, an additional provider package needs
* to be defined.
*
* @param username the desired username for T3 authentication
* @param password the desired password for T3 authentication
* @return environment that should be used during the newClient call
*/
public Map<String,Object> getEnv(String username, String password)
{
HashMap<String,Object> env = new HashMap<String,Object>();

env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");

if(username != null && password != null)
{
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
}

return env;
}
}

0 comments on commit b247043

Please sign in to comment.