/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 5106721
* @summary Check the emission of notifications when a Security Manager is
* installed. Test the property "jmx.remote.x.check.notification.emission".
* @author Luis-Miguel Alventosa
* @run clean NotificationEmissionTest
* @run build NotificationEmissionTest
* @run main NotificationEmissionTest 1
* @run main NotificationEmissionTest 2
* @run main NotificationEmissionTest 3
* @run main NotificationEmissionTest 4
* @run main NotificationEmissionTest 5
*/
public class NotificationEmissionTest {
return new Subject(true,
}
}
public interface NBMBean {
}
public static class NB
extends NotificationBroadcasterSupport
implements NBMBean {
} else {
}
}
}
echo("handleNotification:");
echo("\tNotification = " + n);
echo("\tHandback = " + h);
}
}
return 1;
} else {
for (Notification n : received) {
echo("Received notification: " + n);
echo("Notification type must be \"nb\"");
return 1;
}
int index = (int) n.getSequenceNumber();
return 1;
}
}
}
return 0;
}
switch (testcase) {
case 1:
return testNotificationEmissionProperty();
case 2:
return testNotificationEmissionPositive(false);
case 3:
return testNotificationEmissionNegative(false);
case 4:
return testNotificationEmissionPositive(true);
case 5:
return testNotificationEmissionNegative(true);
default:
echo("Invalid testcase");
return 1;
}
}
throws Exception {
try {
if (exception) {
return 1;
} else {
}
} catch (Exception e) {
if (exception) {
echo("Exception: " + e);
} else {
echo("Exception: " + e);
return 1;
}
}
return 0;
}
int error = 0;
return error;
}
}
}
return testNotificationEmission(true, propValue, false, true);
}
boolean sm,
boolean policyPositive)
throws Exception {
// Set policy file
//
// Create a new MBeanServer
//
try {
// Create server environment map
//
if (prop)
// Create the JMXServiceURL
//
// Create a JMXConnectorServer
//
env,
mbs);
// Start the JMXConnectorServer
//
// Create server environment map
//
// Create JMXConnector and connect to JMXConnectorServer
//
// Get non-secure MBeanServerConnection
//
final MBeanServerConnection mbsc =
// Create NB MBean
//
// Add notification listener
//
// Set security manager
//
if (sm) {
echo("Setting SM");
}
// Invoke the "sendNotification" method
//
// If the check is effective and we're using policy.negative,
// then we should see the two notifs sent by nb2 (of which one
// has a getSource() that is nb3), but not the notif sent by nb1.
// Otherwise we should see all three notifs. The check is only
// effective if the property jmx.remote.x.check.notification.emission
// is explicitly true and there is a security manager.
int expectedNotifs =
// Wait for notifications to be emitted
//
// Remove notification listener
//
int result = 0;
if (result > 0) {
return result;
}
} finally {
// Close the connection
//
// Stop the connector server
//
// Release the MBeanServer
//
}
return 0;
}
}
echo("\n--- Check the emission of notifications " +
"when a Security Manager is installed");
int error = 0;
if (error > 0) {
throw new IllegalArgumentException(msg);
} else {
echo("\nTest PASSED!");
}
}
}