8007471: Improve MBean notifications

Improve MBean notifications

Reviewed-by: dfuchs, mchung, alanb, skoivu
This commit is contained in:
Dmitry Samersoff 2013-03-31 22:00:37 +04:00
parent e0c7d59246
commit 07ca78ead7
2 changed files with 28 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -397,6 +397,20 @@ public class ArrayNotificationBuffer implements NotificationBuffer {
if (nextSeq < nextSequenceNumber()) { if (nextSeq < nextSequenceNumber()) {
candidate = notificationAt(nextSeq); candidate = notificationAt(nextSeq);
// Skip security check if NotificationBufferFilter is not overloaded
if (!(filter instanceof ServerNotifForwarder.NotifForwarderBufferFilter)) {
try {
ServerNotifForwarder.checkMBeanPermission(this.mBeanServer,
candidate.getObjectName(),"addNotificationListener");
} catch (InstanceNotFoundException | SecurityException e) {
if (logger.debugOn()) {
logger.debug("fetchNotifications", "candidate: " + candidate + " skipped. exception " + e);
}
++nextSeq;
continue;
}
}
if (logger.debugOn()) { if (logger.debugOn()) {
logger.debug("fetchNotifications", "candidate: " + logger.debug("fetchNotifications", "candidate: " +
candidate); candidate);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -226,8 +226,9 @@ public class ServerNotifForwarder {
* why we add the found notifications to a supplied List rather than * why we add the found notifications to a supplied List rather than
* just returning a boolean. * just returning a boolean.
*/ */
private final NotificationBufferFilter bufferFilter = private final NotifForwarderBufferFilter bufferFilter = new NotifForwarderBufferFilter();
new NotificationBufferFilter() {
final class NotifForwarderBufferFilter implements NotificationBufferFilter {
public void apply(List<TargetedNotification> targetedNotifs, public void apply(List<TargetedNotification> targetedNotifs,
ObjectName source, Notification notif) { ObjectName source, Notification notif) {
// We proceed in two stages here, to avoid holding the listenerMap // We proceed in two stages here, to avoid holding the listenerMap
@ -366,9 +367,16 @@ public class ServerNotifForwarder {
* Explicitly check the MBeanPermission for * Explicitly check the MBeanPermission for
* the current access control context. * the current access control context.
*/ */
public void checkMBeanPermission( public final void checkMBeanPermission(
final ObjectName name, final String actions) final ObjectName name, final String actions)
throws InstanceNotFoundException, SecurityException { throws InstanceNotFoundException, SecurityException {
checkMBeanPermission(mbeanServer,name,actions);
}
static void checkMBeanPermission(
final MBeanServer mbs, final ObjectName name, final String actions)
throws InstanceNotFoundException, SecurityException {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
AccessControlContext acc = AccessController.getContext(); AccessControlContext acc = AccessController.getContext();
@ -378,7 +386,7 @@ public class ServerNotifForwarder {
new PrivilegedExceptionAction<ObjectInstance>() { new PrivilegedExceptionAction<ObjectInstance>() {
public ObjectInstance run() public ObjectInstance run()
throws InstanceNotFoundException { throws InstanceNotFoundException {
return mbeanServer.getObjectInstance(name); return mbs.getObjectInstance(name);
} }
}); });
} catch (PrivilegedActionException e) { } catch (PrivilegedActionException e) {