/*
* 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 NotificationAccessController methods are properly called.
* @author Luis-Miguel Alventosa
* @run clean NotificationAccessControllerTest
* @run build NotificationAccessControllerTest
* @run main NotificationAccessControllerTest
*/
public class NotificationAccessControllerTest {
private boolean throwException;
this.throwException = throwException;
}
public void addNotificationListener(
throws SecurityException {
echo("addNotificationListener:");
echo("\tsubject: " +
if (throwException)
&&
throw new SecurityException();
}
public void removeNotificationListener(
throws SecurityException {
echo("removeNotificationListener:");
echo("\tsubject: " +
if (throwException)
&&
throw new SecurityException();
}
public void fetchNotification(
throws SecurityException {
echo("fetchNotification:");
echo("\tsubject: " +
if (!throwException)
throw new SecurityException();
}
}
return new Subject(true,
}
}
public interface NBMBean {
}
public static class NB
extends NotificationBroadcasterSupport
implements NBMBean {
} else {
}
}
}
echo("handleNotification:");
echo("\tNotification = " + n);
echo("\tHandback = " + h);
}
}
/**
* Check received notifications
*/
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;
}
/**
* Run test
*/
throws Exception {
" notification access control checks " +
": fetch ")) + "=-=-=");
// Create a new MBeanServer
//
try {
// Create server environment map
//
if (enableChecks) {
new NAC(throwException));
}
// 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
//
try {
if (enableChecks && throwException) {
echo("Didn't get expected exception");
return 1;
}
} catch (SecurityException e) {
if (enableChecks && throwException) {
echo("Got expected exception: " + e);
} else {
echo("Got unexpected exception: " + e);
return 1;
}
}
// Invoke the "sendNotification" method
//
// Wait for notifications to be emitted
//
// Remove notification listener
//
if (!throwException)
try {
if (enableChecks && throwException) {
echo("Didn't get expected exception");
return 1;
}
} catch (SecurityException e) {
if (enableChecks && throwException) {
echo("Got expected exception: " + e);
} else {
echo("Got unexpected exception: " + e);
return 1;
}
}
int result = 0;
if (!enableChecks) {
// List must contain three notifs from sources nb1, nb2 and nb3
//
}
if (enableChecks && !throwException) {
// List must contain one notif from source nb1
//
}
if (enableChecks && throwException) {
// List must contain two notifs from sources nb2 and nb3
//
}
if (result > 0) {
return result;
}
} catch (Exception e) {
echo("Failed to perform operation: " + e);
e.printStackTrace();
return 1;
} finally {
// Close the connection
//
// Stop the connector server
//
// Release the MBeanServer
//
}
return 0;
}
/*
* Print message
*/
}
int error = 0;
if (error > 0) {
throw new IllegalArgumentException(msg);
} else {
}
}
}