1 /*
   2  * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  *  @test
  26  *  @bug 6592792
  27  *  @summary Add com.sun.xml.internal to the "package.access" property in $JAVA_HOME/lib/security/java.security
  28  *  @run shell Test6592792.sh
  29  */
  30 
  31 import java.lang.*;
  32 import java.lang.reflect.*;
  33 import com.sun.xml.internal.ws.server.*;
  34 import com.sun.xml.internal.ws.server.SingletonResolver;
  35 import com.sun.xml.internal.ws.api.server.*;
  36 
  37 public class Test {
  38 
  39   public static void main(String[] args) throws Exception{
  40       // Enable the security manager
  41       SecurityManager sm = new SecurityManager();
  42       System.setSecurityManager(sm);
  43       new Test();
  44   }
  45 
  46   Object invokeMethod(Object target,Method m,Object args[]) throws Exception {
  47       SingletonResolver r = new SingletonResolver(target);
  48       Invoker invoker = r.createInvoker();
  49       return invoker.invoke(null, m, args);
  50   }
  51 
  52   public Test() throws Exception{
  53       try {
  54           Class c=Class.forName("java.lang.Class");
  55 
  56           Class ctab[]=new Class[1];
  57           ctab[0]=Class.forName("java.lang.String");
  58           Method forName=c.getMethod("forName",ctab);
  59 
  60           Class gtab[]=new Class[2];
  61           gtab[0]=Class.forName("java.lang.String");
  62           gtab[1]=Class[].class;
  63           Method getMethod=c.getMethod("getMethod",gtab);
  64 
  65           Method newInstance=c.getMethod("newInstance",(Class[])null);
  66 
  67           Object otab[]=new Object[1];
  68           otab[0]="sun.misc.Unsafe";
  69 
  70           Object o=invokeMethod(null,forName,otab);
  71           c = (Class)o;         // sun.misc.Unsafe class
  72           // Test FAILED: Should n't have got the reference.   
  73           throw new RuntimeException("Test Failed: Got reference to: "+o);
  74 
  75 
  76           //o=invokeMethod(c,getMethod, new Object[]{"getUnsafe", (Class[])null});
  77           //System.out.println("Got reference to: "+o);
  78           //throw new RuntimeException("Got reference to: "+o);
  79           //o=invokeMethod(c,(Method)o,null);
  80           //System.out.println("Got reference to: "+o);
  81           //throw new RuntimeException("Got reference to: "+o);
  82    
  83       } catch(java.security.AccessControlException e) {
  84           System.out.println("Test passed");
  85           //e.printStackTrace();
  86       } 
  87    }
  88 }