use of javax.rmi.ssl.SslRMIClientSocketFactory in project jdk8u_jdk by JetBrains.
the class ScanDirClient method main.
/**
* Connects to a secured JMX <i>scandir</i> application.
* @param args The {@code main} method takes two parameters:
* <ul>
* <li>args[0] must be the server's host</li>
* <li>args[1] must be the rmi port number at which the
* JMX <i>scandir</i> daemon is listening for connections
* - that is, the port number of its JMX RMI Connector which
* was configured in {@code management.properties}
* </li>
* <ul>
**/
public static void main(String[] args) {
try {
//
if (args == null || args.length != 2) {
System.err.println("Bad number of arguments: usage is: \n\t" + USAGE);
System.exit(1);
}
try {
InetAddress.getByName(args[0]);
} catch (UnknownHostException x) {
System.err.println("No such host: " + args[0] + "\n usage is: \n\t" + USAGE);
System.exit(2);
} catch (Exception x) {
System.err.println("Bad address: " + args[0] + "\n usage is: \n\t" + USAGE);
System.exit(2);
}
try {
if (Integer.parseInt(args[1]) <= 0) {
System.err.println("Bad port value: " + args[1] + "\n usage is: \n\t" + USAGE);
System.exit(2);
}
} catch (Exception x) {
System.err.println("Bad argument: " + args[1] + "\n usage is: \n\t" + USAGE);
System.exit(2);
}
// Create an environment map to hold connection properties
// like credentials etc... We will later pass this map
// to the JMX Connector.
//
System.out.println("\nInitialize the environment map");
final Map<String, Object> env = new HashMap<String, Object>();
// Provide the credentials required by the server
// to successfully perform user authentication
//
final String[] credentials = new String[] { "guest", "guestpasswd" };
env.put("jmx.remote.credentials", credentials);
// Provide the SSL/TLS-based RMI Client Socket Factory required
// by the JNDI/RMI Registry Service Provider to communicate with
// the SSL/TLS-protected RMI Registry
//
env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
// Create the RMI connector client and
// connect it to the RMI connector server
// args[0] is the server's host - localhost
// args[1] is the secure server port - 4545
//
System.out.println("\nCreate the RMI connector client and " + "connect it to the RMI connector server");
final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + args[0] + ":" + args[1] + "/jmxrmi");
System.out.println("Connecting to: " + url);
final JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
// Get an MBeanServerConnection
//
System.out.println("\nGet the MBeanServerConnection");
final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
// Create a proxy for the ScanManager MXBean
//
final ScanManagerMXBean proxy = ScanManager.newSingletonProxy(mbsc);
// Get the ScanDirConfig MXBean from the scan manager
//
System.out.println("\nGet ScanDirConfigMXBean from ScanManagerMXBean");
final ScanDirConfigMXBean configMBean = proxy.getConfigurationMBean();
// Print the scan dir configuration
//
System.out.println("\nGet 'Configuration' attribute on ScanDirConfigMXBean");
System.out.println("\nConfiguration:\n" + configMBean.getConfiguration());
// Try to invoke the "close" method on the ScanManager MXBean.
//
// Should get a SecurityException as the user "guest" doesn't
// have readwrite access.
//
System.out.println("\nInvoke 'close' on ScanManagerMXBean");
try {
proxy.close();
} catch (SecurityException e) {
System.out.println("\nGot expected security exception: " + e);
}
// Close MBeanServer connection
//
System.out.println("\nClose the connection to the server");
jmxc.close();
System.out.println("\nBye! Bye!");
} catch (Exception e) {
System.out.println("\nGot unexpected exception: " + e);
e.printStackTrace();
System.exit(3);
}
}
use of javax.rmi.ssl.SslRMIClientSocketFactory in project jdk8u_jdk by JetBrains.
the class SocketFactoryTest method main.
public static void main(String[] args) {
try {
System.out.println("SocketFactoryTest START.");
final SSLContext context = SSLContext.getInstance("SSL");
context.init(null, null, null);
final SslRMIClientSocketFactory client1 = new SslRMIClientSocketFactory();
final SslRMIClientSocketFactory client2 = new SslRMIClientSocketFactory();
final SslRMIClientSocketFactory client11 = (SslRMIClientSocketFactory) serializeAndClone(client1);
final SslRMIClientSocketFactory client21 = (SslRMIClientSocketFactory) serializeAndClone(client2);
final SslRMIServerSocketFactory server1 = new SslRMIServerSocketFactory();
final SslRMIServerSocketFactory server2 = new SslRMIServerSocketFactory(null, null, false);
final SslRMIServerSocketFactory server3 = new SslRMIServerSocketFactory(ciphersuite, null, false);
final SslRMIServerSocketFactory server4 = new SslRMIServerSocketFactory(null, protocol, false);
final SslRMIServerSocketFactory server5 = new SslRMIServerSocketFactory(null, null, true);
final SslRMIServerSocketFactory server6 = new SslRMIServerSocketFactory(null, null, null, false);
final SslRMIServerSocketFactory server7 = new SslRMIServerSocketFactory(SSLContext.getDefault(), null, null, false);
final SslRMIServerSocketFactory server8 = new SslRMIServerSocketFactory(null, null, null, true);
final SslRMIServerSocketFactory server9 = new SslRMIServerSocketFactory(SSLContext.getDefault(), null, null, true);
final SslRMIServerSocketFactory server10 = new SslRMIServerSocketFactory(context, null, null, true);
final MySslRMIClientSocketFactory subclient1 = new MySslRMIClientSocketFactory();
final MySslRMIClientSocketFactory subclient2 = new MySslRMIClientSocketFactory();
final MySslRMIServerSocketFactory subserver1 = new MySslRMIServerSocketFactory();
final MySslRMIServerSocketFactory subserver2 = new MySslRMIServerSocketFactory(null, null, false);
final MySslRMIServerSocketFactory subserver3 = new MySslRMIServerSocketFactory(ciphersuite, null, false);
final MySslRMIServerSocketFactory subserver4 = new MySslRMIServerSocketFactory(null, protocol, false);
final MySslRMIServerSocketFactory subserver5 = new MySslRMIServerSocketFactory(null, null, true);
final MySslRMIServerSocketFactory subserver6 = new MySslRMIServerSocketFactory(null, ciphersuite, null, false);
final MySslRMIServerSocketFactory subserver7 = new MySslRMIServerSocketFactory(SSLContext.getDefault(), ciphersuite, null, false);
final MySslRMIServerSocketFactory subserver8 = new MySslRMIServerSocketFactory(context, null, null, true);
// clients
System.out.println("testEquals(client1,client1,true)");
testEquals(client1, client1, true);
System.out.println("testEquals(client1,client2,true)");
testEquals(client1, client2, true);
System.out.println("testEquals(client1,client11,true)");
testEquals(client1, client11, true);
System.out.println("testEquals(client1,client21,true)");
testEquals(client1, client21, true);
System.out.println("testEquals(client11,client21,true)");
testEquals(client11, client21, true);
System.out.println("testEquals(client1,null,false)");
testEquals(client1, null, false);
System.out.println("testEquals(client1,server1,false)");
testEquals(client1, server1, false);
System.out.println("testEquals(client21,server2,false)");
testEquals(client21, server2, false);
System.out.println("testEquals(client1,new Object(),false)");
testEquals(client1, new Object(), false);
// servers
System.out.println("testEquals(server1,server1,true)");
testEquals(server1, server1, true);
System.out.println("testEquals(server2,server2,true)");
testEquals(server2, server2, true);
System.out.println("testEquals(server3,server3,true)");
testEquals(server3, server3, true);
System.out.println("testEquals(server4,server4,true)");
testEquals(server4, server4, true);
System.out.println("testEquals(server5,server5,true)");
testEquals(server5, server5, true);
System.out.println("testEquals(server1,server2,true)");
testEquals(server1, server2, true);
System.out.println("testEquals(server1,server3,false)");
testEquals(server1, server3, false);
System.out.println("testEquals(server2,server3,false)");
testEquals(server2, server3, false);
System.out.println("testEquals(server3,server4,false)");
testEquals(server3, server4, false);
System.out.println("testEquals(server4,server5,false)");
testEquals(server4, server5, false);
System.out.println("testEquals(server6,server7,false)");
testEquals(server6, server7, false);
System.out.println("testEquals(server8,server9,false)");
testEquals(server8, server9, false);
System.out.println("testEquals(server9,server10,false)");
testEquals(server9, server10, false);
System.out.println("testEquals(server2,server6,true)");
testEquals(server2, server6, true);
System.out.println("testEquals(server2,server7,false)");
testEquals(server2, server7, false);
System.out.println("testEquals(server5,server8,true)");
testEquals(server5, server8, true);
System.out.println("testEquals(server5,server9,false)");
testEquals(server5, server9, false);
System.out.println("testEquals(server1,null,false)");
testEquals(server1, null, false);
System.out.println("testEquals(server2,null,false)");
testEquals(server2, null, false);
System.out.println("testEquals(server3,null,false)");
testEquals(server3, null, false);
System.out.println("testEquals(server1,client2,false)");
testEquals(server1, client2, false);
System.out.println("testEquals(server2,client11,false)");
testEquals(server2, client11, false);
System.out.println("testEquals(server1,new Object(),false)");
testEquals(server1, new Object(), false);
// client subclass
System.out.println("testEquals(subclient1,subclient1,true)");
testEquals(subclient1, subclient1, true);
System.out.println("testEquals(subclient1,subclient2,true)");
testEquals(subclient1, subclient2, true);
System.out.println("testEquals(subclient1,client1,false)");
testEquals(subclient1, client1, false);
System.out.println("testEquals(client1,subclient1,false)");
testEquals(client1, subclient1, false);
System.out.println("testEquals(subclient1,null,false)");
testEquals(subclient1, null, false);
System.out.println("testEquals(subclient1,server1,false)");
testEquals(subclient1, server1, false);
System.out.println("testEquals(server1,subclient1,false)");
testEquals(server1, subclient1, false);
System.out.println("testEquals(subclient2,subserver2,false)");
testEquals(subclient1, subserver2, false);
System.out.println("testEquals(subclient1,new Object(),false)");
testEquals(subclient1, new Object(), false);
// server subclass
System.out.println("testEquals(subserver1,subserver1,true)");
testEquals(subserver1, subserver1, true);
System.out.println("testEquals(subserver2,subserver2,true)");
testEquals(subserver2, subserver2, true);
System.out.println("testEquals(subserver3,subserver3,true)");
testEquals(subserver3, subserver3, true);
System.out.println("testEquals(subserver4,subserver4,true)");
testEquals(subserver4, subserver4, true);
System.out.println("testEquals(subserver5,subserver5,true)");
testEquals(subserver5, subserver5, true);
System.out.println("testEquals(subserver1,subserver2,true)");
testEquals(subserver1, subserver2, true);
System.out.println("testEquals(subserver1,subserver3,false)");
testEquals(subserver1, subserver3, false);
System.out.println("testEquals(subserver2,subserver3,false)");
testEquals(subserver2, subserver3, false);
System.out.println("testEquals(subserver3,subserver4,false)");
testEquals(subserver3, subserver4, false);
System.out.println("testEquals(subserver4,subserver5,false)");
testEquals(subserver4, subserver5, false);
System.out.println("testEquals(subserver3,subserver6,true)");
testEquals(subserver3, subserver6, true);
System.out.println("testEquals(subserver3,subserver7,false)");
testEquals(subserver3, subserver7, false);
System.out.println("testEquals(subserver1,server1,false)");
testEquals(subserver1, server1, false);
System.out.println("testEquals(server1,subserver1,false)");
testEquals(server1, subserver1, false);
System.out.println("testEquals(subserver2,server2,false)");
testEquals(subserver2, server2, false);
System.out.println("testEquals(server2,subserver2,false)");
testEquals(server2, subserver2, false);
System.out.println("testEquals(subserver3,server3,false)");
testEquals(subserver3, server3, false);
System.out.println("testEquals(server3,subserver3,false)");
testEquals(server3, subserver3, false);
System.out.println("testEquals(subserver4,server4,false)");
testEquals(subserver4, server4, false);
System.out.println("testEquals(server4,subserver4,false)");
testEquals(server4, subserver4, false);
System.out.println("testEquals(subserver5,server5,false)");
testEquals(subserver5, server5, false);
System.out.println("testEquals(server5,subserver5,false)");
testEquals(server5, subserver5, false);
System.out.println("testEquals(server10,subserver8,false)");
testEquals(server10, subserver8, false);
System.out.println("testEquals(subserver8,server10,false)");
testEquals(subserver8, server10, false);
System.out.println("testEquals(subserver1,null,false)");
testEquals(subserver1, null, false);
System.out.println("testEquals(subserver1,client2,false)");
testEquals(subserver1, client2, false);
System.out.println("testEquals(subserver1,subclient2,false)");
testEquals(subserver1, subclient2, false);
System.out.println("testEquals(client1,subserver2,false)");
testEquals(client1, subserver2, false);
System.out.println("testEquals(subserver1,new Object(),false)");
testEquals(subserver1, new Object(), false);
System.out.println("SocketFactoryTest PASSED.");
} catch (Exception x) {
System.out.println("SocketFactoryTest FAILED: " + x);
x.printStackTrace();
System.exit(1);
}
}
use of javax.rmi.ssl.SslRMIClientSocketFactory in project uPortal by Jasig.
the class JavaManagementServerBean method getJmxServerEnvironment.
/**
* Generates the environment Map for the JMX server based on system properties
*
* @return A non-null Map of environment settings for the JMX server.
*/
protected Map<String, Object> getJmxServerEnvironment() {
final Map<String, Object> jmxEnv = new HashMap<String, Object>();
// SSL Options
final String enableSSL = System.getProperty(JMX_SSL_PROPERTY);
if (Boolean.getBoolean(enableSSL)) {
SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
jmxEnv.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory();
jmxEnv.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
}
// Password file options
final String passwordFile = System.getProperty(JMX_PASSWORD_FILE_PROPERTY);
if (passwordFile != null) {
jmxEnv.put(JMX_REMOTE_X_PASSWORD_FILE, passwordFile);
}
// Access file options
final String accessFile = System.getProperty(JMX_ACCESS_FILE_PROPERTY);
if (accessFile != null) {
jmxEnv.put(JMX_REMOTE_X_ACCESS_FILE, accessFile);
}
if (this.logger.isDebugEnabled()) {
this.logger.debug("Configured JMX Server Environment = '" + jmxEnv + "'");
}
return jmxEnv;
}
use of javax.rmi.ssl.SslRMIClientSocketFactory in project Payara by payara.
the class RMIConnectorStarter method getClientSocketFactory.
/**
* This method sets up an environment based on passed in SSL configuration
*
* @param sslConfig
* @return SslRMIClientSocketFactory
*/
private SslRMIClientSocketFactory getClientSocketFactory(Ssl sslConfig) {
// create SSLParams
SSLParams sslParams = convertToSSLParams(sslConfig);
// configure the context using these params
SSLClientConfigurator sslCC = SSLClientConfigurator.getInstance();
sslCC.setSSLParams(sslParams);
SSLContext sslContext = sslCC.configure(sslParams);
// Now pass this context to the ClientSocketFactory
Security.setProperty("ssl.SocketFactory.provider", sslContext.getClass().getName());
String enabledProtocols = sslCC.getEnabledProtocolsAsString();
if (enabledProtocols != null) {
System.setProperty("javax.rmi.ssl.client.enabledProtocols", enabledProtocols);
}
String enabledCipherSuites = sslCC.getEnabledCipherSuitesAsString();
if (enabledCipherSuites != null) {
System.setProperty("javax.rmi.ssl.client.enabledCipherSuites", enabledCipherSuites);
}
// The keystore and truststore locations are already available as System properties
// Hence we just add the passwords
System.setProperty("javax.net.ssl.keyStorePassword", sslParams.getKeyStorePassword() == null ? "changeit" : sslParams.getKeyStorePassword());
System.setProperty("javax.net.ssl.trustStorePassword", sslParams.getTrustStorePassword() == null ? "changeit" : sslParams.getTrustStorePassword());
SslRMIClientSocketFactory sslRMICsf = new SslRMIClientSocketFactory();
return sslRMICsf;
}
use of javax.rmi.ssl.SslRMIClientSocketFactory in project Payara by payara.
the class DynamicInterceptor method getSecureInstanceConnection.
private MBeanServerConnection getSecureInstanceConnection(String instanceName) throws InstanceNotFoundException {
synchronized (instanceConnections) {
if (!instanceConnections.containsKey(instanceName)) {
try {
//
System.out.println("\nInitialize the environment map");
final Map<String, Object> env = new HashMap<String, Object>();
// Provide the SSL/TLS-based RMI Client Socket Factory required
// by the JNDI/RMI Registry Service Provider to communicate with
// the SSL/TLS-protected RMI Registry
SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
env.put("com.sun.jndi.rmi.factory.socket", csf);
String urlStr = "service:jmx:rmi:///jndi/rmi://" + MbeanService.getInstance().getHost(instanceName) + ":" + MbeanService.getInstance().getJMXPort(instanceName) + "/jmxrmi";
JMXServiceURL url = new JMXServiceURL(urlStr);
JMXConnector jmxConn = JMXConnectorFactory.connect(url, env);
MBeanServerConnection conn = jmxConn.getMBeanServerConnection();
instanceConnections.put(instanceName, conn);
} catch (Exception ex) {
throw new InstanceNotFoundException(ex.getLocalizedMessage());
}
}
return instanceConnections.get(instanceName);
}
}
Aggregations