Path: blob/master/test/jdk/sun/rmi/transport/tcp/disableMultiplexing/DisableMultiplexing.java
41159 views
/*1* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 418320425* @summary The RMI runtime should fail to export a remote object on a TCP26* port for an applet or application that does not have permission to listen27* on that port, rather than engage in the deprecated "multiplexing protocol".28* @author Peter Jones29*30* @build DisableMultiplexing_Stub31* @run main/othervm -Djava.security.manager=allow DisableMultiplexing32*/3334import java.rmi.*;35import java.rmi.server.*;3637public class DisableMultiplexing implements Remote {3839public static void main(String[] args) {4041System.err.println("\nRegression test for bug 4183204\n");4243System.err.println("Setting draconian security manager.");44System.setSecurityManager(new SecurityManager() {45public void checkListen(int port) {46throw new SecurityException("THOU SHALT NOT LISTEN");47}48});4950System.err.println("Creating remote object.");51DisableMultiplexing obj = new DisableMultiplexing();5253try {54System.err.println("Attempting to export remote object.");55UnicastRemoteObject.exportObject(obj);56try {57UnicastRemoteObject.unexportObject(obj, true);58} catch (NoSuchObjectException e) {59}60throw new RuntimeException(61"TEST FAILED: remote object successfully exported");62} catch (SecurityException e) {63System.err.println("TEST PASSED: ");64e.printStackTrace();65} catch (Exception e) {66e.printStackTrace();67throw new RuntimeException("TEST FAILED: " + e.toString());68}69}70}717273