You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2011/09/07 13:56:10 UTC
svn commit: r1166134 - in /qpid/trunk/qpid/java:
broker/src/main/java/org/apache/qpid/server/logging/actors/
broker/src/main/java/org/apache/qpid/server/logging/messages/
broker/src/main/java/org/apache/qpid/server/management/
broker/src/test/java/org/...
Author: robbie
Date: Wed Sep 7 11:56:10 2011
New Revision: 1166134
URL: http://svn.apache.org/viewvc?rev=1166134&view=rev
Log:
QPID-3467: replace the 'connection id' with the Username of the logged in user for the ManagementActor, since the value for the connection id was arrived at using an incorrect assumption that the id number in the thread name for a particular RMI thread is specific to a given JMX connection when it isnt.
Applied patch from Oleksandr Rudyy <or...@gmail.com>
Modified:
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java?rev=1166134&r1=1166133&r2=1166134&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java Wed Sep 7 11:56:10 2011
@@ -20,11 +20,15 @@
*/
package org.apache.qpid.server.logging.actors;
-import org.apache.qpid.server.logging.LogMessage;
-import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.RootMessageLogger;
+import java.security.AccessController;
+import java.security.Principal;
import java.text.MessageFormat;
+import java.util.Set;
+
+import javax.management.remote.JMXPrincipal;
+import javax.security.auth.Subject;
/**
* NOTE: This actor is not thread safe.
@@ -40,16 +44,23 @@ import java.text.MessageFormat;
*/
public class ManagementActor extends AbstractActor
{
+ /**
+ * Holds the principal name to display when principal subject is not available.
+ * <p>
+ * This is useful for cases when users invoke JMX operation over JConsole
+ * attached to the local JVM.
+ */
+ private static final String UNKNOWN_PRINCIPAL = "N/A";
+
String _lastThreadName = null;
/**
* LOG FORMAT for the ManagementActor,
- * Uses a MessageFormat call to insert the requried values according to
- * these indicies:
+ * Uses a MessageFormat call to insert the required values according to
+ * these indices:
*
- * 0 - Connection ID
- * 1 - User ID
- * 2 - IP
+ * 0 - User ID
+ * 1 - IP
*/
public static final String MANAGEMENT_FORMAT = "mng:{0}({1})";
@@ -75,19 +86,20 @@ public class ManagementActor extends Abs
_lastThreadName = currentName;
// Management Thread names have this format.
- //RMI TCP Connection(2)-169.24.29.116
+ // RMI TCP Connection(2)-169.24.29.116
// This is true for both LocalAPI and JMX Connections
// However to be defensive lets test.
String[] split = currentName.split("\\(");
if (split.length == 2)
{
- String connectionID = split[1].split("\\)")[0];
String ip = currentName.split("-")[1];
-
- actor = MessageFormat.format(MANAGEMENT_FORMAT,
- connectionID,
- ip);
+ String principalName = getPrincipalName();
+ if (principalName == null)
+ {
+ principalName = UNKNOWN_PRINCIPAL;
+ }
+ actor = MessageFormat.format(MANAGEMENT_FORMAT, principalName, ip);
}
else
{
@@ -105,6 +117,30 @@ public class ManagementActor extends Abs
}
}
+ /**
+ * Returns current JMX principal name.
+ *
+ * @return principal name or null if principal can not be found
+ */
+ protected String getPrincipalName()
+ {
+ String identity = null;
+
+ // retrieve Subject from current AccessControlContext
+ final Subject subject = Subject.getSubject(AccessController.getContext());
+ if (subject != null)
+ {
+ // retrieve JMXPrincipal from Subject
+ final Set<JMXPrincipal> principals = subject.getPrincipals(JMXPrincipal.class);
+ if (principals != null && !principals.isEmpty())
+ {
+ final Principal principal = principals.iterator().next();
+ identity = principal.getName();
+ }
+ }
+ return identity;
+ }
+
public String getLogMessage()
{
updateLogString();
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties?rev=1166134&r1=1166133&r2=1166134&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties Wed Sep 7 11:56:10 2011
@@ -30,4 +30,4 @@ STOPPED = MNG-1005 : Stopped
# 0 - Path
SSL_KEYSTORE = MNG-1006 : Using SSL Keystore : {0}
OPEN = MNG-1007 : Open : User {0}
-CLOSE = MNG-1008 : Close
\ No newline at end of file
+CLOSE = MNG-1008 : Close : User {0}
\ No newline at end of file
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java?rev=1166134&r1=1166133&r2=1166134&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java Wed Sep 7 11:56:10 2011
@@ -313,7 +313,7 @@ public class MBeanInvocationHandlerImpl
else if (notification.getType().equals(JMXConnectionNotification.CLOSED) ||
notification.getType().equals(JMXConnectionNotification.FAILED))
{
- _logActor.message(ManagementConsoleMessages.CLOSE());
+ _logActor.message(ManagementConsoleMessages.CLOSE(user));
}
}
}
Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java?rev=1166134&r1=1166133&r2=1166134&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java Wed Sep 7 11:56:10 2011
@@ -20,13 +20,13 @@
*/
package org.apache.qpid.server.logging.actors;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.logging.LogMessage;
-import org.apache.qpid.server.logging.LogSubject;
-import org.apache.qpid.AMQException;
-
+import java.security.PrivilegedAction;
+import java.util.Collections;
import java.util.List;
+import javax.management.remote.JMXPrincipal;
+import javax.security.auth.Subject;
+
/**
* Test : AMQPManagementActorTest
* Validate the AMQPManagementActor class.
@@ -96,8 +96,40 @@ public class ManagementActorTest extends
// Verify that the message has the right values
assertTrue("Message contains the [mng: prefix",
- logs.get(0).toString().contains("[mng:" + CONNECTION_ID + "(" + IP + ")"));
+ logs.get(0).toString().contains("[mng:N/A(" + IP + ")"));
+ }
+
+ /**
+ * Tests appearance of principal name in log message
+ */
+ public void testSubjectPrincipalNameAppearance()
+ {
+ Subject subject = new Subject(true, Collections.singleton(new JMXPrincipal("guest")), Collections.EMPTY_SET,
+ Collections.EMPTY_SET);
+
+ final String message = Subject.doAs(subject, new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return sendTestLogMessage(_amqpActor);
+ }
+ });
+
+ // Verify that the log message was created
+ assertNotNull("Test log message is not created!", message);
+
+ List<Object> logs = _rawLogger.getLogMessages();
+
+ // Verify that at least one log message was added to log
+ assertEquals("Message log size not as expected.", 1, logs.size());
+
+ String logMessage = logs.get(0).toString();
+
+ // Verify that the logged message is present in the output
+ assertTrue("Message was not found in log message", logMessage.contains(message));
+ // Verify that the message has the right principal value
+ assertTrue("Message contains the [mng: prefix", logMessage.contains("[mng:guest(" + IP + ")"));
}
}
Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java?rev=1166134&r1=1166133&r2=1166134&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java Wed Sep 7 11:56:10 2011
@@ -68,61 +68,6 @@ public class ManagementActorLoggingTest
/**
* Description:
- * When a JMX Management connection is made then this will be logged out.
- *
- * Input:
- *
- * 1. Running Broker
- * 2. Connect Management client via JMX
- * Output:
- *
- * <date> MNG-1007 : Open <user>
- *
- * Validation Steps:
- * 1. The MNG ID is correct
- * 2. The user is correct
- *
- * On connection close a MNG-1008 is expected
- *
- * * <date> MNG-1008 : Close
- *
- * Validation Steps:
- * 1. The MNG ID is correct
- *
- * @throws java.io.IOException - if there is a problem reseting the log monitor
- */
- public void testJMXManagementConsoleConnection() throws IOException
- {
- List<String> results = waitAndFindMatches("MNG-1007");
-
- assertEquals("Unexpected Management Connection count", 1, results.size());
-
- String log = getLogMessage(results, 0);
-
- validateMessageID("MNG-1007", log);
-
- assertTrue("User not in log message:" + log, log.endsWith(USER));
- // Extract the id from the log string
- // MESSAGE [mng:1(rmi://169.24.29.116)] MNG-1007 : Open : User admin
- int connectionID = Integer.parseInt(fromActor(getLog(results.get(0))).charAt(4) + "");
-
- results = findMatches("MNG-1008");
-
- assertEquals("Unexpected Management Connection close count", 0, results.size());
-
- _jmxUtils.close();
- _closed = true;
-
- results = waitAndFindMatches("MNG-1008");
-
- assertEquals("Unexpected Management Connection count", 1, results.size());
-
- assertEquals("Close does not have same id as open,", connectionID,
- Integer.parseInt(fromActor(getLog(results.get(0))).charAt(4) + ""));
- }
-
- /**
- * Description:
* When a connected client has its connection closed via the Management Console this will be logged as a CON-1002 message.
* Input:
*
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org