1.1 --- a/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java Tue Jun 18 20:52:10 2013 -0700 1.2 +++ b/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java Fri Jun 14 16:31:55 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -34,6 +34,9 @@ 1.11 1.12 import java.io.File; 1.13 import java.io.IOException; 1.14 +import java.io.SerializablePermission; 1.15 +import java.security.AccessController; 1.16 +import java.security.PrivilegedAction; 1.17 import java.util.Vector; 1.18 import java.util.Hashtable; 1.19 import java.util.Enumeration; 1.20 @@ -49,6 +52,7 @@ 1.21 import com.sun.corba.se.impl.util.PackagePrefixChecker; 1.22 import sun.rmi.rmic.Main; 1.23 1.24 + 1.25 /** 1.26 * An IIOP stub/tie generator for rmic. 1.27 * 1.28 @@ -78,6 +82,7 @@ 1.29 protected boolean castArray = false; 1.30 protected Hashtable transactionalObjects = new Hashtable() ; 1.31 protected boolean POATie = false ; 1.32 + protected boolean emitPermissionCheck = false; 1.33 1.34 /** 1.35 * Default constructor for Main to use. 1.36 @@ -193,6 +198,9 @@ 1.37 } else if (argv[i].equals("-standardPackage")) { 1.38 standardPackage = true; 1.39 argv[i] = null; 1.40 + } else if (argv[i].equals("-emitPermissionCheck")) { 1.41 + emitPermissionCheck = true; 1.42 + argv[i] = null; 1.43 } else if (arg.equals("-xstubbase")) { 1.44 argv[i] = null; 1.45 if (++i < argv.length && argv[i] != null && !argv[i].startsWith("-")) { 1.46 @@ -390,9 +398,22 @@ 1.47 1.48 writePackageAndImports(p); 1.49 1.50 +// generate 1.51 +// import java.security.AccessController; 1.52 +// import java.security.PrivilegedAction; 1.53 +// import java.io.SerializablePermission; 1.54 + if (emitPermissionCheck) { 1.55 + p.pln("import java.security.AccessController;"); 1.56 + p.pln("import java.security.PrivilegedAction;"); 1.57 + p.pln("import java.io.SerializablePermission;"); 1.58 + p.pln(); 1.59 + p.pln(); 1.60 + } 1.61 + 1.62 // Declare the stub class; implement all remote interfaces. 1.63 1.64 p.p("public class " + currentClass); 1.65 + 1.66 p.p(" extends " + getName(stubBaseClass)); 1.67 p.p(" implements "); 1.68 if (remoteInterfaces.length > 0) { 1.69 @@ -422,6 +443,57 @@ 1.70 writeIds( p, theType, false ); 1.71 p.pln(); 1.72 1.73 + if (emitPermissionCheck) { 1.74 + 1.75 + // produce the following generated code for example 1.76 + // private static Void checkPermission() { 1.77 + // SecurityManager sm = System.getSecurityManager(); 1.78 + // if (sm != null) { 1.79 + // sm.checkPermission(new SerializablePermission( 1.80 + // "enableSubclassImplementation")); // testing 1.81 + // } 1.82 + // return null; 1.83 + // } 1.84 + // 1.85 + // private _XXXXX_Stub(Void ignore) { 1.86 + // } 1.87 + // 1.88 + // public _XXXXX_Stub() { 1.89 + // this(checkPermission()); 1.90 + // } 1.91 + // 1.92 + // where XXXXX is the name of the remote interface 1.93 + 1.94 + p.pln(); 1.95 + p.plnI("private static Void checkPermission() {"); 1.96 + p.plnI("SecurityManager sm = System.getSecurityManager();"); 1.97 + p.pln("if (sm != null) {"); 1.98 + p.pI(); 1.99 + p.plnI("sm.checkPermission(new SerializablePermission("); 1.100 + p.plnI("\"enableSubclassImplementation\"));"); 1.101 + p.pO(); 1.102 + p.pO(); 1.103 + p.pOln("}"); 1.104 + p.pln("return null;"); 1.105 + p.pO(); 1.106 + p.pOln("}"); 1.107 + p.pln(); 1.108 + p.pO(); 1.109 + 1.110 + p.pI(); 1.111 + p.pln("private " + currentClass + "(Void ignore) { }"); 1.112 + p.pln(); 1.113 + 1.114 + p.plnI("public " + currentClass + "() { "); 1.115 + p.pln("this(checkPermission());"); 1.116 + p.pOln("}"); 1.117 + p.pln(); 1.118 + } 1.119 + 1.120 + if (!emitPermissionCheck) { 1.121 + p.pI(); 1.122 + } 1.123 + 1.124 // Write the _ids() method... 1.125 1.126 p.plnI("public String[] _ids() { "); 1.127 @@ -815,7 +887,6 @@ 1.128 CompoundType theType) throws IOException { 1.129 1.130 // Wtite the method declaration and opening brace... 1.131 - 1.132 String methodName = method.getName(); 1.133 String methodIDLName = method.getIDLName(); 1.134