You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2008/07/10 22:16:55 UTC
svn commit: r675713 - in /geronimo/server/trunk/framework/modules:
geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/
geronimo-commands/src/main/groovy/org/apache/geronimo/commands/
geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/depl...
Author: gawor
Date: Thu Jul 10 13:16:55 2008
New Revision: 675713
URL: http://svn.apache.org/viewvc?rev=675713&view=rev
Log:
enable deployer and gshell commands to communicate with jmx server over ssl/tls (part of GERONIMO-3876)
Modified:
geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParams.java
geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParamsImpl.java
geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java
geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy
geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java
geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
Modified: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParams.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParams.java?rev=675713&r1=675712&r2=675713&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParams.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParams.java Thu Jul 10 13:16:55 2008
@@ -19,7 +19,7 @@
package org.apache.geronimo.cli.deployer;
/**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
*/
public interface ConnectionParams {
String getURI();
@@ -39,4 +39,6 @@
boolean isVerbose();
boolean isOffline();
+
+ boolean isSecure();
}
Modified: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParamsImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParamsImpl.java?rev=675713&r1=675712&r2=675713&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParamsImpl.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/ConnectionParamsImpl.java Thu Jul 10 13:16:55 2008
@@ -21,7 +21,7 @@
package org.apache.geronimo.cli.deployer;
/**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
*/
public class ConnectionParamsImpl implements ConnectionParams {
@@ -34,9 +34,14 @@
private boolean syserr;
private boolean verbose;
private boolean offline;
+ private boolean secure;
public ConnectionParamsImpl(String uri, String host, Integer port, String driver, String user, String password, boolean syserr, boolean verbose, boolean offline) {
+ this(uri, host, port, driver, user, password, syserr, verbose, offline, false);
+ }
+
+ public ConnectionParamsImpl(String uri, String host, Integer port, String driver, String user, String password, boolean syserr, boolean verbose, boolean offline, boolean secure) {
this.uri = uri;
this.host = host;
this.port = port;
@@ -46,6 +51,7 @@
this.syserr = syserr;
this.verbose = verbose;
this.offline = offline;
+ this.secure = secure;
}
public ConnectionParamsImpl() {
@@ -122,4 +128,12 @@
public void setOffline(boolean offline) {
this.offline = offline;
}
+
+ public boolean isSecure() {
+ return secure;
+ }
+
+ public void setSecure(boolean secure) {
+ this.secure = secure;
+ }
}
Modified: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java?rev=675713&r1=675712&r2=675713&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java Thu Jul 10 13:16:55 2008
@@ -62,6 +62,9 @@
private final static String ARGUMENT_OFFLINE_SHORTFORM = "o";
private final static String ARGUMENT_OFFLINE = "offline";
+
+ private final static String ARGUMENT_SECURE_SHORTFORM = "s";
+ private final static String ARGUMENT_SECURE = "secure";
private final Collection<CommandMetaData> commandMetaData;
@@ -96,6 +99,7 @@
addSyserr();
addVerbose();
addOffline();
+ addSecure();
}
public CommandMetaData getCommandMetaData() {
@@ -146,6 +150,10 @@
return commandLine.hasOption(ARGUMENT_OFFLINE_SHORTFORM);
}
+ public boolean isSecure() {
+ return commandLine.hasOption(ARGUMENT_SECURE_SHORTFORM);
+ }
+
@Override
public void displayHelp() {
String[] args = new String[0];
@@ -281,6 +289,13 @@
false,
"Deploy offline to a local server, using whatever deployers are available in the local server");
}
+
+ protected void addSecure() {
+ options.addOption(ARGUMENT_SECURE_SHORTFORM,
+ ARGUMENT_SECURE,
+ false,
+ "Use secure channel to communicate with the server. Unsecured channel is used by default.");
+ }
protected void addVerbose() {
options.addOption(ARGUMENT_VERBOSE_SHORTFORM,
Modified: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy?rev=675713&r1=675712&r2=675713&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy (original)
+++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy Thu Jul 10 13:16:55 2008
@@ -54,6 +54,9 @@
@Option(name='-w', aliases=['--password'], description='Password')
String password
+ @Option(name='--secure', description='Use secure channel')
+ boolean secure = false
+
@Requirement
PromptReader prompter
@@ -84,7 +87,7 @@
def kernel = new BasicKernel('gshell deployer')
def deploymentManager = new RemoteDeploymentManager(Collections.emptySet())
def deploymentFactory = new DeploymentFactoryWithKernel(kernel, deploymentManager)
- def connectionParams = new ConnectionParamsImpl(host: hostname, port: port, user: username, password: password, offline: false)
+ def connectionParams = new ConnectionParamsImpl(host: hostname, port: port, user: username, password: password, offline: false, secure: secure)
def connection = new ServerConnection(connectionParams, io.out, io.inputStream, kernel, deploymentFactory)
// Disconnect previous connection if any
@@ -93,7 +96,7 @@
variables.parent.set(SERVER_CONNECTION, connection)
if (!quiet) {
- io.out.println('Connection established')
+ io.out.println('Connection established')
}
return connection
Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java?rev=675713&r1=675712&r2=675713&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java Thu Jul 10 13:16:55 2008
@@ -29,6 +29,8 @@
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
+import javax.management.remote.rmi.RMIConnectorServer;
+import javax.rmi.ssl.SslRMIClientSocketFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,14 +82,15 @@
int pos = uri.indexOf(":");
String protocol = pos == -1 ? uri : uri.substring(0, pos);
uri = pos == -1 ? "" : uri.substring(pos+1);
- if(protocol.equals("jmx")) {
+ if(protocol.equals("jmx") || protocol.equals("jmxs")) {
+ boolean secure = protocol.equals("jmxs");
if(!uri.startsWith("//")) {
- return new ConnectParams(protocol, "localhost", DEFAULT_PORT);
+ return new ConnectParams(protocol, "localhost", DEFAULT_PORT, secure);
}
uri = uri.substring(2);
pos = uri.indexOf(':');
if(pos == -1) {
- return new ConnectParams(protocol, uri.equals("") ? "localhost" : uri, DEFAULT_PORT);
+ return new ConnectParams(protocol, uri.equals("") ? "localhost" : uri, DEFAULT_PORT, secure);
}
if(uri.indexOf('/', pos+1) > -1) {
return null;
@@ -98,7 +101,7 @@
String host = uri.substring(0, pos);
String port = uri.substring(pos+1);
try {
- return new ConnectParams(protocol, host.equals("") ? "localhost" : host, Integer.parseInt(port));
+ return new ConnectParams(protocol, host.equals("") ? "localhost" : host, Integer.parseInt(port), secure);
} catch (NumberFormatException e) {
return null;
}
@@ -133,7 +136,7 @@
}
try {
- if (params.getProtocol().equals("jmx")) {
+ if (params.getProtocol().equals("jmx") || params.getProtocol().equals("jmxs")) {
return newRemoteDeploymentManager(username, password, params);
} else if(params.getProtocol().equals("inVM")) {
return new LocalDeploymentManager(KernelRegistry.getKernel(params.getHost()));
@@ -160,6 +163,12 @@
String[] credentials = new String[]{username, password};
environment.put(JMXConnector.CREDENTIALS, credentials);
environment.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, BaseDeploymentFactory.class.getClassLoader());
+ String connectorName = "/JMXConnector";
+ if (params.isSecure()) {
+ connectorName = "/JMXSecureConnector";
+ SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
+ environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
+ }
try {
// if ipv6 numeric address wrap with "[" "]"
String host = params.getHost();
@@ -167,9 +176,9 @@
host = "[" + host + "]";
}
if (log.isDebugEnabled()) {
- log.debug("Using JMXServiceURL with host=" + host + ", port=" + params.getPort());
+ log.debug("Using JMXServiceURL with host=" + host + ", port=" + params.getPort() + ", secure=" + params.isSecure());
}
- JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+ host +":"+params.getPort()+"/JMXConnector");
+ JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+ host +":"+params.getPort()+connectorName);
JMXConnector jmxConnector = JMXConnectorFactory.connect(address, environment);
RemoteDeploymentManager manager = getRemoteDeploymentManager();
manager.init(jmxConnector, host);
@@ -199,11 +208,17 @@
private String protocol;
private String host;
private int port;
+ private boolean secure;
public ConnectParams(String protocol, String host, int port) {
+ this(protocol, host, port, false);
+ }
+
+ public ConnectParams(String protocol, String host, int port, boolean secure) {
this.protocol = protocol;
this.host = host;
this.port = port;
+ this.secure = secure;
}
public String getProtocol() {
@@ -218,6 +233,10 @@
return port;
}
+ public boolean isSecure() {
+ return secure;
+ }
+
public String toString() {
return protocol+" / "+host+" / "+port;
}
Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java?rev=675713&r1=675712&r2=675713&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java Thu Jul 10 13:16:55 2008
@@ -51,6 +51,7 @@
public class ServerConnection {
private final static String DEFAULT_URI = "deployer:geronimo:jmx";
+ private final static String DEFAULT_SECURE_URI = "deployer:geronimo:jmxs";
private final DeploymentFactory geronimoDeploymentFactory;
@@ -68,8 +69,7 @@
this.geronimoDeploymentFactory = geronimoDeploymentFactory;
this.out = out;
- this.in = in;
- boolean offline = false;
+ this.in = in;
String uri = params.getURI();
String driver = params.getDriver();
@@ -79,19 +79,20 @@
Integer port = params.getPort();
verboseMessages = params.isVerbose();
logToSysErr = params.isSyserr();
- offline = params.isOffline();
-
+ boolean offline = params.isOffline();
+ boolean secure = params.isSecure();
+
if ((driver != null) && uri == null) {
throw new DeploymentSyntaxException("A custom driver requires a custom URI");
}
if (host != null || port != null) {
- uri = DEFAULT_URI + "://" + (host == null ? "" : host) + (port == null ? "" : ":" + port);
+ uri = getDefaultURI(secure) + "://" + (host == null ? "" : host) + (port == null ? "" : ":" + port);
}
if (offline) {
startOfflineDeployer(kernel);
manager = new LocalDeploymentManager(kernel);
} else {
- tryToConnect(uri, driver, user, password);
+ tryToConnect(uri, driver, user, password, secure);
}
if (manager == null) {
throw new DeploymentException("Unexpected error; connection failed.");
@@ -103,6 +104,10 @@
offlineDeployerStarter.start();
}
+ private static String getDefaultURI(boolean secure) {
+ return (secure) ? DEFAULT_SECURE_URI : DEFAULT_URI;
+ }
+
public void close() throws DeploymentException {
if (manager != null) {
manager.release();
@@ -117,14 +122,14 @@
return auth.uri;
}
- private void tryToConnect(String argURI, String driver, String user, String password) throws DeploymentException {
+ private void tryToConnect(String argURI, String driver, String user, String password, boolean secure) throws DeploymentException {
DeploymentFactoryManager mgr = DeploymentFactoryManager.getInstance();
if (driver != null) {
loadDriver(driver, mgr);
} else {
mgr.registerDeploymentFactory(geronimoDeploymentFactory);
}
- String useURI = argURI == null ? DEFAULT_URI : argURI;
+ String useURI = argURI == null ? getDefaultURI(secure) : argURI;
if (user == null && password == null) {
InputStream in;