Skip to content

Commit b247043

Browse files
committed
Add basic T3 support
1 parent 8365b04 commit b247043

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

beanshooter/src/eu/tneitzel/beanshooter/plugin/PluginSystem.java

+29-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import eu.tneitzel.beanshooter.plugin.providers.RMIProvider;
3131
import eu.tneitzel.beanshooter.plugin.providers.ResponseHandlerProvider;
3232
import eu.tneitzel.beanshooter.plugin.providers.SocketFactoryProvider;
33+
import eu.tneitzel.beanshooter.plugin.providers.T3AuthenticationProvider;
3334
import eu.tneitzel.beanshooter.plugin.providers.YsoSerialProvider;
3435
import eu.tneitzel.beanshooter.utils.Utils;
3536

@@ -60,15 +61,17 @@ public class PluginSystem {
6061
*/
6162
public static void init(String pluginPath)
6263
{
63-
mBeanServerProvider = selectProvider();
64+
mBeanServerProvider = selectMBeanProvider();
6465
socketFactoryProvider = new SocketFactoryProvider();
6566
payloadProvider = new YsoSerialProvider();
6667
argumentProvider = new ArgumentProvider();
6768
responseHandler = new ResponseHandlerProvider();
68-
authenticationProvider = new AuthenticationProvider();
69+
authenticationProvider = selectAuthProvider();
6970

7071
if(pluginPath != null)
72+
{
7173
loadPlugin(pluginPath);
74+
}
7275
}
7376

7477
/**
@@ -105,7 +108,9 @@ private static void loadPlugin(String pluginPath)
105108
jarStream.close();
106109

107110
if(pluginClassName == null)
111+
{
108112
throw new MalformedPluginException();
113+
}
109114

110115
}
111116

@@ -179,20 +184,41 @@ private static void loadPlugin(String pluginPath)
179184
*
180185
* @return IMBeanServerProvider according to the specified command lien arguments.
181186
*/
182-
private static IMBeanServerProvider selectProvider()
187+
private static IMBeanServerProvider selectMBeanProvider()
183188
{
184189
if (BeanshooterOption.CONN_JMXMP.getBool())
190+
{
185191
return new JMXMPProvider();
192+
}
186193

187194
if (BeanshooterOption.CONN_JNDI.notNull())
195+
{
188196
return new JNDIProvider();
197+
}
189198

190199
if (BeanshooterOption.CONN_JOLOKIA.getBool())
200+
{
191201
return new JolokiaProvider();
202+
}
192203

193204
return new RMIProvider();
194205
}
195206

207+
/**
208+
* Returns the IAuthenticationProvider according to the specified command line arguments.
209+
*
210+
* @return IAuthenticationProvider according to the specified command lien arguments.
211+
*/
212+
private static IAuthenticationProvider selectAuthProvider()
213+
{
214+
if (BeanshooterOption.CONN_JNDI.getValue("").startsWith("service:jmx:t3"))
215+
{
216+
return new T3AuthenticationProvider();
217+
}
218+
219+
return new AuthenticationProvider();
220+
}
221+
196222
/**
197223
* Attempt to obtain an MBeanServerConnection to the specified remote MBeanServer. Authentication related
198224
* exceptions are handled automatically. If this is not desired, the getMBeanServerConnectionUnmanaged function

beanshooter/src/eu/tneitzel/beanshooter/plugin/providers/JNDIProvider.java

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ else if (connString.startsWith("service:jmx:remote"))
7373
connString += String.format("://%s:%d", host, port);
7474
}
7575

76+
else if (connString.startsWith("service:jmx:t3"))
77+
{
78+
connString += String.format("://%s:%d/jndi/weblogic.management.mbeanservers.runtime", host, port);
79+
}
80+
7681
else
7782
{
7883
Logger.eprintlnMixedYellow("The specified", "connection string", "seems to be invalid.");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package eu.tneitzel.beanshooter.plugin.providers;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import javax.naming.Context;
7+
import javax.management.remote.JMXConnector;
8+
import javax.management.remote.JMXConnectorFactory;
9+
import javax.rmi.ssl.SslRMIClientSocketFactory;
10+
11+
import eu.tneitzel.beanshooter.operation.BeanshooterOption;
12+
import eu.tneitzel.beanshooter.plugin.IAuthenticationProvider;
13+
14+
/**
15+
* T3 compatible authentication provider. Has only some small deviations from the default
16+
* authentication provider.
17+
*
18+
* @author Tobias Neitzel (@qtc_de)
19+
*/
20+
public class T3AuthenticationProvider implements IAuthenticationProvider
21+
{
22+
/**
23+
* Authentication to T3 endpoints requires the credentials to be passed in a different
24+
* format than for the usual JMX auth. Moreover, an additional provider package needs
25+
* to be defined.
26+
*
27+
* @param username the desired username for T3 authentication
28+
* @param password the desired password for T3 authentication
29+
* @return environment that should be used during the newClient call
30+
*/
31+
public Map<String,Object> getEnv(String username, String password)
32+
{
33+
HashMap<String,Object> env = new HashMap<String,Object>();
34+
35+
env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
36+
37+
if(username != null && password != null)
38+
{
39+
env.put(Context.SECURITY_PRINCIPAL, username);
40+
env.put(Context.SECURITY_CREDENTIALS, password);
41+
}
42+
43+
return env;
44+
}
45+
}

0 commit comments

Comments
 (0)