summaryrefslogtreecommitdiff
path: root/java/broker/src/main/java/org/apache/qpid/server/logging/actors
diff options
context:
space:
mode:
Diffstat (limited to 'java/broker/src/main/java/org/apache/qpid/server/logging/actors')
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java68
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java5
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java62
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java62
4 files changed, 140 insertions, 57 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java
new file mode 100644
index 0000000000..8cf121b3d9
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java
@@ -0,0 +1,68 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.logging.actors;
+
+import java.security.AccessController;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+
+public abstract class AbstractManagementActor 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.
+ */
+ protected static final String UNKNOWN_PRINCIPAL = "N/A";
+
+ /** used when the principal name cannot be discovered from the Subject */
+ private final String _fallbackPrincipalName;
+
+ public AbstractManagementActor(RootMessageLogger rootLogger, String fallbackPrincipalName)
+ {
+ super(rootLogger);
+ _fallbackPrincipalName = fallbackPrincipalName;
+ }
+
+ /**
+ * Returns current {@link AuthenticatedPrincipal} name or {@link #_fallbackPrincipalName}
+ * if it can't be found.
+ */
+ protected String getPrincipalName()
+ {
+ String identity = _fallbackPrincipalName;
+
+ final Subject subject = Subject.getSubject(AccessController.getContext());
+ if (subject != null)
+ {
+ AuthenticatedPrincipal authenticatedPrincipal = AuthenticatedPrincipal.getOptionalAuthenticatedPrincipalFromSubject(subject);
+ if(authenticatedPrincipal != null)
+ {
+ identity = authenticatedPrincipal.getName();
+ }
+ }
+ return identity;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java
index 97134515a0..6251471139 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java
@@ -105,6 +105,11 @@ public class CurrentActor
{
Stack<LogActor> stack = _currentActor.get();
stack.pop();
+
+ if (stack.isEmpty())
+ {
+ _currentActor.remove();
+ }
}
/**
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java
new file mode 100644
index 0000000000..9b445c2bd9
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.logging.actors;
+
+import java.text.MessageFormat;
+
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.subjects.LogSubjectFormat;
+
+/**
+ * HttpManagement actor to use in {@link AbstractServlet} to log all http management operational logging.
+ *
+ * An instance is required per http Session.
+ */
+public class HttpManagementActor extends AbstractManagementActor
+{
+ private String _cachedLogString;
+ private String _lastPrincipalName;
+ private String _address;
+
+ public HttpManagementActor(RootMessageLogger rootLogger, String ip, int port)
+ {
+ super(rootLogger, UNKNOWN_PRINCIPAL);
+ _address = ip + ":" + port;
+ }
+
+ private synchronized String getAndCacheLogString()
+ {
+ String principalName = getPrincipalName();
+
+ if(!principalName.equals(_lastPrincipalName))
+ {
+ _lastPrincipalName = principalName;
+ _cachedLogString = "[" + MessageFormat.format(LogSubjectFormat.MANAGEMENT_FORMAT, principalName, _address) + "] ";
+ }
+
+ return _cachedLogString;
+ }
+
+ public String getLogMessage()
+ {
+ return getAndCacheLogString();
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java
index a2f3506502..ba5ea47fc1 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java
@@ -21,58 +21,31 @@
package org.apache.qpid.server.logging.actors;
import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.subjects.LogSubjectFormat;
-import javax.management.remote.JMXPrincipal;
-import javax.security.auth.Subject;
-import java.security.AccessController;
-import java.security.Principal;
import java.text.MessageFormat;
-import java.util.Set;
/**
* Management actor to use in {@link MBeanInvocationHandlerImpl} to log all management operational logging.
*/
-public class ManagementActor extends AbstractActor
+public class ManagementActor extends AbstractManagementActor
{
- /**
- * 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";
-
private String _lastThreadName = null;
/**
- * LOG FORMAT for the ManagementActor,
- * Uses a MessageFormat call to insert the required values according to
- * these indices:
- *
- * 0 - User ID
- * 1 - IP
- */
- public static final String MANAGEMENT_FORMAT = "mng:{0}({1})";
-
- /**
* The logString to be used for logging
*/
private String _logStringContainingPrincipal;
- /** used when the principal name cannot be discovered from the Subject */
- private final String _fallbackPrincipalName;
-
/** @param rootLogger The RootLogger to use for this Actor */
public ManagementActor(RootMessageLogger rootLogger)
{
- super(rootLogger);
- _fallbackPrincipalName = UNKNOWN_PRINCIPAL;
+ super(rootLogger, UNKNOWN_PRINCIPAL);
}
public ManagementActor(RootMessageLogger rootLogger, String principalName)
{
- super(rootLogger);
- _fallbackPrincipalName = principalName;
+ super(rootLogger, principalName);
}
private synchronized String getAndCacheLogString()
@@ -96,7 +69,7 @@ public class ManagementActor extends AbstractActor
if (split.length == 2)
{
String ip = currentName.split("-")[1];
- actor = MessageFormat.format(MANAGEMENT_FORMAT, principalName, ip);
+ actor = MessageFormat.format(LogSubjectFormat.MANAGEMENT_FORMAT, principalName, ip);
}
else
{
@@ -119,33 +92,8 @@ public class ManagementActor extends AbstractActor
return logString;
}
- /**
- * Returns current JMX principal name.
- *
- * @return principal name or null if principal can not be found
- */
- private String getPrincipalName()
- {
- String identity = _fallbackPrincipalName;
-
- // 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()
{
return getAndCacheLogString();
}
-
}