incubator-kitty-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pids...@apache.org
Subject svn commit: r1128902 - in /incubator/kitty/trunk/src/main/java/org/apache/kitty: CmdShell.groovy client/Client.groovy
Date Sun, 29 May 2011 16:46:03 GMT
Author: pidster
Date: Sun May 29 16:46:02 2011
New Revision: 1128902

URL: http://svn.apache.org/viewvc?rev=1128902&view=rev
Log:
add authentication as per KITTY-1

Modified:
    incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy
    incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy

Modified: incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy?rev=1128902&r1=1128901&r2=1128902&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy (original)
+++ incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy Sun May 29 16:46:02
2011
@@ -136,11 +136,18 @@ class CmdShell {
 					cmdHelp()
 					break;
 				case 1:
-					if (params.length > 3) {
+					if (params.length > 5) {
 						println "You have entered an invalid number of parameters, you may enter host and port
as parameters only"
+						break;
 					}
-					if (params.length == 3) {
-						cmdConnect(params[1],params[2])
+					if (params.length == 5) {
+						cmdConnect(params[1], params[2], params[3], params[4])
+					}
+					else if (params.length == 4) {
+						println "Please supply a password"
+					}
+					else if (params.length == 3) {
+						cmdConnect(params[1], params[2])
 					}
 					else {
 						if (params.length == 2) {
@@ -270,6 +277,18 @@ class CmdShell {
 		}
 	}
 
+	static cmdConnect(_host, _port, _username, _password) {
+		println "connecting with $_username to $_host at port $_port...."
+		getClient().connect(_host, _port, _username, _password)
+		if (getClient().getRemote()) {
+			println "Successfully connected to host"
+			remote = getClient().getRemote()
+		}
+		else {
+			println "Connection attempt was unsuccessful"
+		}
+	}
+
 	static cmdDisconnect() {
 		println "disconnecting..."
 		if (client.getRemote()) {

Modified: incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy?rev=1128902&r1=1128901&r2=1128902&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy (original)
+++ incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy Sun May 29 16:46:02
2011
@@ -22,6 +22,7 @@ import java.io.IOException
 
 import javax.management.Attribute
 import javax.management.ObjectName
+import javax.management.remote.JMXConnector
 import javax.management.remote.JMXConnectorFactory
 import javax.management.remote.JMXServiceURL
 
@@ -54,26 +55,34 @@ class Client {
 	def mbean
 
 	public connect(def _host, def _port) {
-		// TODO
+		connect(_host, _port, null, null)
+	}
+		
+	public connect(def _host, def _port, def _username, def _password) {
+
 		def serviceURL
 		def properties = new HashMap()
-		if (remote != null)
-		{
+		
+		if (remote != null) {
 			disconnect()
 		}
+		
+		if ((_username != null) && (_password != null)) {
+			properties.put JMXConnector.CREDENTIALS, [_username, _password] as String[]
+		}
 
 		try {
 			serviceURL = "service:jmx:rmi:///jndi/rmi://$_host:$_port/jmxrmi"
 			this.url = new JMXServiceURL(serviceURL)
-			println "the url is $url"
+			
 			// TODO add auth & credentials to properties
 			this.connector = JMXConnectorFactory.connect(this.url, properties)
 			this.remote = this.connector.getMBeanServerConnection()
 		}
-		catch(IOException e) {
+		catch(Exception e) {
 			connector = null
 			remote = null
-			println e.getMessage()
+			println "ERROR! " + e.getMessage()
 		}
 		finally {
 			if (this.remote != null) {
@@ -147,9 +156,21 @@ class Client {
 	 * @return
 	 */
 	public ls() {
+		
+		if (!this.remote) {
+			println "No remote is set!"
+			return
+		}
+
+		if (!this.domain) {
+			println "No domain is set!"
+			return
+		}
+
 		if (this.remote) {
 			if (this.domain) {
 				def objectName = this.domain + ":"
+				
 				def objectName2
 				if (objectName.length() > 0) {
 					objectName += ",".concat(this.mBeansPath.join())  // make sure mBeansPath is a list,
otherwise remove the .join() command
@@ -158,6 +179,10 @@ class Client {
 				else {
 					objectName2 = objectName
 				}
+
+				println "objectName: " + objectName
+				println "objectName2: " + objectName2
+				
 				def pool = new ObjectName(objectName2 + "*")
 				def paths = {}
 				println objectName



Mime
View raw message