|
From: <ls...@us...> - 2007-05-17 20:40:36
|
Revision: 3221
http://jnode.svn.sourceforge.net/jnode/?rev=3221&view=rev
Author: lsantha
Date: 2007-05-17 13:40:30 -0700 (Thu, 17 May 2007)
Log Message:
-----------
Openjdk patches.
Added Paths:
-----------
trunk/core/src/openjdk/sun/sun/misc/Service.java
trunk/core/src/openjdk/sun/sun/misc/ServiceConfigurationError.java
trunk/core/src/openjdk/sun/sun/reflect/
trunk/core/src/openjdk/sun/sun/reflect/Reflection.java
trunk/core/src/openjdk/sun/sun/security/util/
trunk/core/src/openjdk/sun/sun/security/util/SecurityConstants.java
Added: trunk/core/src/openjdk/sun/sun/misc/Service.java
===================================================================
--- trunk/core/src/openjdk/sun/sun/misc/Service.java (rev 0)
+++ trunk/core/src/openjdk/sun/sun/misc/Service.java 2007-05-17 20:40:30 UTC (rev 3221)
@@ -0,0 +1,427 @@
+/*
+ * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.misc;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.TreeSet;
+
+
+/**
+ * A simple service-provider lookup mechanism. A <i>service</i> is a
+ * well-known set of interfaces and (usually abstract) classes. A <i>service
+ * provider</i> is a specific implementation of a service. The classes in a
+ * provider typically implement the interfaces and subclass the classes defined
+ * in the service itself. Service providers may be installed in an
+ * implementation of the Java platform in the form of extensions, that is, jar
+ * files placed into any of the usual extension directories. Providers may
+ * also be made available by adding them to the applet or application class
+ * path or by some other platform-specific means.
+ *
+ * <p> In this lookup mechanism a service is represented by an interface or an
+ * abstract class. (A concrete class may be used, but this is not
+ * recommended.) A provider of a given service contains one or more concrete
+ * classes that extend this <i>service class</i> with data and code specific to
+ * the provider. This <i>provider class</i> will typically not be the entire
+ * provider itself but rather a proxy that contains enough information to
+ * decide whether the provider is able to satisfy a particular request together
+ * with code that can create the actual provider on demand. The details of
+ * provider classes tend to be highly service-specific; no single class or
+ * interface could possibly unify them, so no such class has been defined. The
+ * only requirement enforced here is that provider classes must have a
+ * zero-argument constructor so that they may be instantiated during lookup.
+ *
+ * <p> A service provider identifies itself by placing a provider-configuration
+ * file in the resource directory <tt>META-INF/services</tt>. The file's name
+ * should consist of the fully-qualified name of the abstract service class.
+ * The file should contain a list of fully-qualified concrete provider-class
+ * names, one per line. Space and tab characters surrounding each name, as
+ * well as blank lines, are ignored. The comment character is <tt>'#'</tt>
+ * (<tt>0x23</tt>); on each line all characters following the first comment
+ * character are ignored. The file must be encoded in UTF-8.
+ *
+ * <p> If a particular concrete provider class is named in more than one
+ * configuration file, or is named in the same configuration file more than
+ * once, then the duplicates will be ignored. The configuration file naming a
+ * particular provider need not be in the same jar file or other distribution
+ * unit as the provider itself. The provider must be accessible from the same
+ * class loader that was initially queried to locate the configuration file;
+ * note that this is not necessarily the class loader that found the file.
+ *
+ * <p> <b>Example:</b> Suppose we have a service class named
+ * <tt>java.io.spi.CharCodec</tt>. It has two abstract methods:
+ *
+ * <pre>
+ * public abstract CharEncoder getEncoder(String encodingName);
+ * public abstract CharDecoder getDecoder(String encodingName);
+ * </pre>
+ *
+ * Each method returns an appropriate object or <tt>null</tt> if it cannot
+ * translate the given encoding. Typical <tt>CharCodec</tt> providers will
+ * support more than one encoding.
+ *
+ * <p> If <tt>sun.io.StandardCodec</tt> is a provider of the <tt>CharCodec</tt>
+ * service then its jar file would contain the file
+ * <tt>META-INF/services/java.io.spi.CharCodec</tt>. This file would contain
+ * the single line:
+ *
+ * <pre>
+ * sun.io.StandardCodec # Standard codecs for the platform
+ * </pre>
+ *
+ * To locate an encoder for a given encoding name, the internal I/O code would
+ * do something like this:
+ *
+ * <pre>
+ * CharEncoder getEncoder(String encodingName) {
+ * Iterator ps = Service.providers(CharCodec.class);
+ * while (ps.hasNext()) {
+ * CharCodec cc = (CharCodec)ps.next();
+ * CharEncoder ce = cc.getEncoder(encodingName);
+ * if (ce != null)
+ * return ce;
+ * }
+ * return null;
+ * }
+ * </pre>
+ *
+ * The provider-lookup mechanism always executes in the security context of the
+ * caller. Trusted system code should typically invoke the methods in this
+ * class from within a privileged security context.
+ *
+ * @author Mark Reinhold
+ * @version 1.18, 07/05/05
+ * @since 1.3
+ */
+
+public final class Service {
+
+ private static final String prefix = "META-INF/services/";
+
+ private Service() { }
+
+ private static void fail(Class service, String msg, Throwable cause)
+ throws ServiceConfigurationError
+ {
+ ServiceConfigurationError sce
+ = new ServiceConfigurationError(service.getName() + ": " + msg);
+ sce.initCause(cause);
+ throw sce;
+ }
+
+ private static void fail(Class service, String msg)
+ throws ServiceConfigurationError
+ {
+ throw new ServiceConfigurationError(service.getName() + ": " + msg);
+ }
+
+ private static void fail(Class service, URL u, int line, String msg)
+ throws ServiceConfigurationError
+ {
+ fail(service, u + ":" + line + ": " + msg);
+ }
+
+ /**
+ * Parse a single line from the given configuration file, adding the name
+ * on the line to both the names list and the returned set iff the name is
+ * not already a member of the returned set.
+ */
+ private static int parseLine(Class service, URL u, BufferedReader r, int lc,
+ List names, Set returned)
+ throws IOException, ServiceConfigurationError
+ {
+ String ln = r.readLine();
+ if (ln == null) {
+ return -1;
+ }
+ int ci = ln.indexOf('#');
+ if (ci >= 0) ln = ln.substring(0, ci);
+ ln = ln.trim();
+ int n = ln.length();
+ if (n != 0) {
+ if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0))
+ fail(service, u, lc, "Illegal configuration-file syntax");
+ int cp = ln.codePointAt(0);
+ if (!Character.isJavaIdentifierStart(cp))
+ fail(service, u, lc, "Illegal provider-class name: " + ln);
+ for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
+ cp = ln.codePointAt(i);
+ if (!Character.isJavaIdentifierPart(cp) && (cp != '.'))
+ fail(service, u, lc, "Illegal provider-class name: " + ln);
+ }
+ if (!returned.contains(ln)) {
+ names.add(ln);
+ returned.add(ln);
+ }
+ }
+ return lc + 1;
+ }
+
+ /**
+ * Parse the content of the given URL as a provider-configuration file.
+ *
+ * @param service
+ * The service class for which providers are being sought;
+ * used to construct error detail strings
+ *
+ * @param url
+ * The URL naming the configuration file to be parsed
+ *
+ * @param returned
+ * A Set containing the names of provider classes that have already
+ * been returned. This set will be updated to contain the names
+ * that will be yielded from the returned <tt>Iterator</tt>.
+ *
+ * @return A (possibly empty) <tt>Iterator</tt> that will yield the
+ * provider-class names in the given configuration file that are
+ * not yet members of the returned set
+ *
+ * @throws ServiceConfigurationError
+ * If an I/O error occurs while reading from the given URL, or
+ * if a configuration-file format error is detected
+ */
+ private static Iterator parse(Class service, URL u, Set returned)
+ throws ServiceConfigurationError
+ {
+ InputStream in = null;
+ BufferedReader r = null;
+ ArrayList names = new ArrayList();
+ try {
+ in = u.openStream();
+ r = new BufferedReader(new InputStreamReader(in, "utf-8"));
+ int lc = 1;
+ while ((lc = parseLine(service, u, r, lc, names, returned)) >= 0);
+ } catch (IOException x) {
+ fail(service, ": " + x);
+ } finally {
+ try {
+ if (r != null) r.close();
+ if (in != null) in.close();
+ } catch (IOException y) {
+ fail(service, ": " + y);
+ }
+ }
+ return names.iterator();
+ }
+
+
+ /**
+ * Private inner class implementing fully-lazy provider lookup
+ */
+ private static class LazyIterator implements Iterator {
+
+ Class service;
+ ClassLoader loader;
+ Enumeration configs = null;
+ Iterator pending = null;
+ Set returned = new TreeSet();
+ String nextName = null;
+
+ private LazyIterator(Class service, ClassLoader loader) {
+ this.service = service;
+ this.loader = loader;
+ }
+
+ public boolean hasNext() throws ServiceConfigurationError {
+ if (nextName != null) {
+ return true;
+ }
+ if (configs == null) {
+ try {
+ String fullName = prefix + service.getName();
+ if (loader == null)
+ configs = ClassLoader.getSystemResources(fullName);
+ else
+ configs = loader.getResources(fullName);
+ } catch (IOException x) {
+ fail(service, ": " + x);
+ }
+ }
+ while ((pending == null) || !pending.hasNext()) {
+ if (!configs.hasMoreElements()) {
+ return false;
+ }
+ pending = parse(service, (URL)configs.nextElement(), returned);
+ }
+ nextName = (String)pending.next();
+ return true;
+ }
+
+ public Object next() throws ServiceConfigurationError {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ String cn = nextName;
+ nextName = null;
+ try {
+ return Class.forName(cn, true, loader).newInstance();
+ } catch (ClassNotFoundException x) {
+ fail(service,
+ "Provider " + cn + " not found");
+ } catch (Exception x) {
+ fail(service,
+ "Provider " + cn + " could not be instantiated: " + x,
+ x);
+ }
+ return null; /* This cannot happen */
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+
+ /**
+ * Locates and incrementally instantiates the available providers of a
+ * given service using the given class loader.
+ *
+ * <p> This method transforms the name of the given service class into a
+ * provider-configuration filename as described above and then uses the
+ * <tt>getResources</tt> method of the given class loader to find all
+ * available files with that name. These files are then read and parsed to
+ * produce a list of provider-class names. The iterator that is returned
+ * uses the given class loader to lookup and then instantiate each element
+ * of the list.
+ *
+ * <p> Because it is possible for extensions to be installed into a running
+ * Java virtual machine, this method may return different results each time
+ * it is invoked. <p>
+ *
+ * @param service
+ * The service's abstract service class
+ *
+ * @param loader
+ * The class loader to be used to load provider-configuration files
+ * and instantiate provider classes, or <tt>null</tt> if the system
+ * class loader (or, failing that the bootstrap class loader) is to
+ * be used
+ *
+ * @return An <tt>Iterator</tt> that yields provider objects for the given
+ * service, in some arbitrary order. The iterator will throw a
+ * <tt>ServiceConfigurationError</tt> if a provider-configuration
+ * file violates the specified format or if a provider class cannot
+ * be found and instantiated.
+ *
+ * @throws ServiceConfigurationError
+ * If a provider-configuration file violates the specified format
+ * or names a provider class that cannot be found and instantiated
+ *
+ * @see #providers(java.lang.Class)
+ * @see #installedProviders(java.lang.Class)
+ */
+ public static Iterator providers(Class service, ClassLoader loader)
+ throws ServiceConfigurationError
+ {
+ return new LazyIterator(service, loader);
+ }
+
+
+ /**
+ * Locates and incrementally instantiates the available providers of a
+ * given service using the context class loader. This convenience method
+ * is equivalent to
+ *
+ * <pre>
+ * ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ * return Service.providers(service, cl);
+ * </pre>
+ *
+ * @param service
+ * The service's abstract service class
+ *
+ * @return An <tt>Iterator</tt> that yields provider objects for the given
+ * service, in some arbitrary order. The iterator will throw a
+ * <tt>ServiceConfigurationError</tt> if a provider-configuration
+ * file violates the specified format or if a provider class cannot
+ * be found and instantiated.
+ *
+ * @throws ServiceConfigurationError
+ * If a provider-configuration file violates the specified format
+ * or names a provider class that cannot be found and instantiated
+ *
+ * @see #providers(java.lang.Class, java.lang.ClassLoader)
+ */
+ public static Iterator providers(Class service)
+ throws ServiceConfigurationError
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return Service.providers(service, cl);
+ }
+
+
+ /**
+ * Locates and incrementally instantiates the available providers of a
+ * given service using the extension class loader. This convenience method
+ * simply locates the extension class loader, call it
+ * <tt>extClassLoader</tt>, and then does
+ *
+ * <pre>
+ * return Service.providers(service, extClassLoader);
+ * </pre>
+ *
+ * If the extension class loader cannot be found then the system class
+ * loader is used; if there is no system class loader then the bootstrap
+ * class loader is used.
+ *
+ * @param service
+ * The service's abstract service class
+ *
+ * @return An <tt>Iterator</tt> that yields provider objects for the given
+ * service, in some arbitrary order. The iterator will throw a
+ * <tt>ServiceConfigurationError</tt> if a provider-configuration
+ * file violates the specified format or if a provider class cannot
+ * be found and instantiated.
+ *
+ * @throws ServiceConfigurationError
+ * If a provider-configuration file violates the specified format
+ * or names a provider class that cannot be found and instantiated
+ *
+ * @see #providers(java.lang.Class, java.lang.ClassLoader)
+ */
+ public static Iterator installedProviders(Class service)
+ throws ServiceConfigurationError
+ {
+ ClassLoader cl = ClassLoader.getSystemClassLoader();
+ ClassLoader prev = null;
+ while (cl != null) {
+ prev = cl;
+ cl = cl.getParent();
+ }
+ return Service.providers(service, prev);
+ }
+
+}
Added: trunk/core/src/openjdk/sun/sun/misc/ServiceConfigurationError.java
===================================================================
--- trunk/core/src/openjdk/sun/sun/misc/ServiceConfigurationError.java (rev 0)
+++ trunk/core/src/openjdk/sun/sun/misc/ServiceConfigurationError.java 2007-05-17 20:40:30 UTC (rev 3221)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 1999-2000 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.misc;
+
+
+/**
+ * Error thrown when something goes wrong while looking up service providers.
+ * In particular, this error will be thrown in the following situations:
+ *
+ * <ul>
+ * <li> A concrete provider class cannot be found,
+ * <li> A concrete provider class cannot be instantiated,
+ * <li> The format of a provider-configuration file is illegal, or
+ * <li> An IOException occurs while reading a provider-configuration file.
+ * </ul>
+ *
+ * @author Mark Reinhold
+ * @version 1.14, 07/05/05
+ * @since 1.3
+ */
+
+public class ServiceConfigurationError extends Error {
+
+ /**
+ * Constructs a new instance with the specified detail string.
+ */
+ public ServiceConfigurationError(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs a new instance that wraps the specified throwable.
+ */
+ public ServiceConfigurationError(Throwable x) {
+ super(x);
+ }
+
+}
Added: trunk/core/src/openjdk/sun/sun/reflect/Reflection.java
===================================================================
--- trunk/core/src/openjdk/sun/sun/reflect/Reflection.java (rev 0)
+++ trunk/core/src/openjdk/sun/sun/reflect/Reflection.java 2007-05-17 20:40:30 UTC (rev 3221)
@@ -0,0 +1,325 @@
+/*
+ * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.reflect;
+
+import java.lang.reflect.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Common utility routines used by both java.lang and
+ java.lang.reflect */
+
+public class Reflection {
+
+ /** Used to filter out fields and methods from certain classes from public
+ view, where they are sensitive or they may contain VM-internal objects.
+ These Maps are updated very rarely. Rather than synchronize on
+ each access, we use copy-on-write */
+ private static volatile Map<Class,String[]> fieldFilterMap;
+ private static volatile Map<Class,String[]> methodFilterMap;
+
+ static {
+ Map<Class,String[]> map = new HashMap<Class,String[]>();
+ map.put(Reflection.class,
+ new String[] {"fieldFilterMap", "methodFilterMap"});
+ map.put(System.class, new String[] {"security"});
+ fieldFilterMap = map;
+
+ methodFilterMap = new HashMap<Class,String[]>();
+ }
+
+ /** Returns the class of the method <code>realFramesToSkip</code>
+ frames up the stack (zero-based), ignoring frames associated
+ with java.lang.reflect.Method.invoke() and its implementation.
+ The first frame is that associated with this method, so
+ <code>getCallerClass(0)</code> returns the Class object for
+ sun.reflect.Reflection. Frames associated with
+ java.lang.reflect.Method.invoke() and its implementation are
+ completely ignored and do not count toward the number of "real"
+ frames skipped. */
+ public static native Class getCallerClass(int realFramesToSkip);
+
+ /** Retrieves the access flags written to the class file. For
+ inner classes these flags may differ from those returned by
+ Class.getModifiers(), which searches the InnerClasses
+ attribute to find the source-level access flags. This is used
+ instead of Class.getModifiers() for run-time access checks due
+ to compatibility reasons; see 4471811. Only the values of the
+ low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
+ valid. */
+ private static native int getClassAccessFlags(Class c);
+
+ /** A quick "fast-path" check to try to avoid getCallerClass()
+ calls. */
+ public static boolean quickCheckMemberAccess(Class memberClass,
+ int modifiers)
+ {
+ return Modifier.isPublic(getClassAccessFlags(memberClass) & modifiers);
+ }
+
+ public static void ensureMemberAccess(Class currentClass,
+ Class memberClass,
+ Object target,
+ int modifiers)
+ throws IllegalAccessException
+ {
+ if (currentClass == null || memberClass == null) {
+ throw new InternalError();
+ }
+
+ if (!verifyMemberAccess(currentClass, memberClass, target, modifiers)) {
+ throw new IllegalAccessException("Class " + currentClass.getName() +
+ " can not access a member of class " +
+ memberClass.getName() +
+ " with modifiers \"" +
+ Modifier.toString(modifiers) +
+ "\"");
+ }
+ }
+
+ public static boolean verifyMemberAccess(Class currentClass,
+ // Declaring class of field
+ // or method
+ Class memberClass,
+ // May be NULL in case of statics
+ Object target,
+ int modifiers)
+ {
+ // Verify that currentClass can access a field, method, or
+ // constructor of memberClass, where that member's access bits are
+ // "modifiers".
+
+ boolean gotIsSameClassPackage = false;
+ boolean isSameClassPackage = false;
+
+ if (currentClass == memberClass) {
+ // Always succeeds
+ return true;
+ }
+
+ if (!Modifier.isPublic(getClassAccessFlags(memberClass))) {
+ isSameClassPackage = isSameClassPackage(currentClass, memberClass);
+ gotIsSameClassPackage = true;
+ if (!isSameClassPackage) {
+ return false;
+ }
+ }
+
+ // At this point we know that currentClass can access memberClass.
+
+ if (Modifier.isPublic(modifiers)) {
+ return true;
+ }
+
+ boolean successSoFar = false;
+
+ if (Modifier.isProtected(modifiers)) {
+ // See if currentClass is a subclass of memberClass
+ if (isSubclassOf(currentClass, memberClass)) {
+ successSoFar = true;
+ }
+ }
+
+ if (!successSoFar && !Modifier.isPrivate(modifiers)) {
+ if (!gotIsSameClassPackage) {
+ isSameClassPackage = isSameClassPackage(currentClass,
+ memberClass);
+ gotIsSameClassPackage = true;
+ }
+
+ if (isSameClassPackage) {
+ successSoFar = true;
+ }
+ }
+
+ if (!successSoFar) {
+ return false;
+ }
+
+ if (Modifier.isProtected(modifiers)) {
+ // Additional test for protected members: JLS 6.6.2
+ Class targetClass = (target == null ? memberClass : target.getClass());
+ if (targetClass != currentClass) {
+ if (!gotIsSameClassPackage) {
+ isSameClassPackage = isSameClassPackage(currentClass, memberClass);
+ gotIsSameClassPackage = true;
+ }
+ if (!isSameClassPackage) {
+ if (!isSubclassOf(targetClass, currentClass)) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private static boolean isSameClassPackage(Class c1, Class c2) {
+ return isSameClassPackage(c1.getClassLoader(), c1.getName(),
+ c2.getClassLoader(), c2.getName());
+ }
+
+ /** Returns true if two classes are in the same package; classloader
+ and classname information is enough to determine a class's package */
+ private static boolean isSameClassPackage(ClassLoader loader1, String name1,
+ ClassLoader loader2, String name2)
+ {
+ if (loader1 != loader2) {
+ return false;
+ } else {
+ int lastDot1 = name1.lastIndexOf('.');
+ int lastDot2 = name2.lastIndexOf('.');
+ if ((lastDot1 == -1) || (lastDot2 == -1)) {
+ // One of the two doesn't have a package. Only return true
+ // if the other one also doesn't have a package.
+ return (lastDot1 == lastDot2);
+ } else {
+ int idx1 = 0;
+ int idx2 = 0;
+
+ // Skip over '['s
+ if (name1.charAt(idx1) == '[') {
+ do {
+ idx1++;
+ } while (name1.charAt(idx1) == '[');
+ if (name1.charAt(idx1) != 'L') {
+ // Something is terribly wrong. Shouldn't be here.
+ throw new InternalError("Illegal class name " + name1);
+ }
+ }
+ if (name2.charAt(idx2) == '[') {
+ do {
+ idx2++;
+ } while (name2.charAt(idx2) == '[');
+ if (name2.charAt(idx2) != 'L') {
+ // Something is terribly wrong. Shouldn't be here.
+ throw new InternalError("Illegal class name " + name2);
+ }
+ }
+
+ // Check that package part is identical
+ int length1 = lastDot1 - idx1;
+ int length2 = lastDot2 - idx2;
+
+ if (length1 != length2) {
+ return false;
+ }
+ return name1.regionMatches(false, idx1, name2, idx2, length1);
+ }
+ }
+ }
+
+ static boolean isSubclassOf(Class queryClass,
+ Class ofClass)
+ {
+ while (queryClass != null) {
+ if (queryClass == ofClass) {
+ return true;
+ }
+ queryClass = queryClass.getSuperclass();
+ }
+ return false;
+ }
+
+ // fieldNames must contain only interned Strings
+ public static synchronized void registerFieldsToFilter(Class containingClass,
+ String ... fieldNames) {
+ fieldFilterMap =
+ registerFilter(fieldFilterMap, containingClass, fieldNames);
+ }
+
+ // methodNames must contain only interned Strings
+ public static synchronized void registerMethodsToFilter(Class containingClass,
+ String ... methodNames) {
+ methodFilterMap =
+ registerFilter(methodFilterMap, containingClass, methodNames);
+ }
+
+ private static Map<Class,String[]> registerFilter(Map<Class,String[]> map,
+ Class containingClass, String ... names) {
+ if (map.get(containingClass) != null) {
+ throw new IllegalArgumentException
+ ("Filter already registered: " + containingClass);
+ }
+ map = new HashMap<Class,String[]>(map);
+ map.put(containingClass, names);
+ return map;
+ }
+
+ public static Field[] filterFields(Class containingClass,
+ Field[] fields) {
+ if (fieldFilterMap == null) {
+ // Bootstrapping
+ return fields;
+ }
+ return (Field[])filter(fields, fieldFilterMap.get(containingClass));
+ }
+
+ public static Method[] filterMethods(Class containingClass, Method[] methods) {
+ if (methodFilterMap == null) {
+ // Bootstrapping
+ return methods;
+ }
+ return (Method[])filter(methods, methodFilterMap.get(containingClass));
+ }
+
+ private static Member[] filter(Member[] members, String[] filteredNames) {
+ if ((filteredNames == null) || (members.length == 0)) {
+ return members;
+ }
+ int numNewMembers = 0;
+ for (Member member : members) {
+ boolean shouldSkip = false;
+ for (String filteredName : filteredNames) {
+ if (member.getName() == filteredName) {
+ shouldSkip = true;
+ break;
+ }
+ }
+ if (!shouldSkip) {
+ ++numNewMembers;
+ }
+ }
+ Member[] newMembers =
+ (Member[])Array.newInstance(members[0].getClass(), numNewMembers);
+ int destIdx = 0;
+ for (Member member : members) {
+ boolean shouldSkip = false;
+ for (String filteredName : filteredNames) {
+ if (member.getName() == filteredName) {
+ shouldSkip = true;
+ break;
+ }
+ }
+ if (!shouldSkip) {
+ newMembers[destIdx++] = member;
+ }
+ }
+ return newMembers;
+ }
+}
Added: trunk/core/src/openjdk/sun/sun/security/util/SecurityConstants.java
===================================================================
--- trunk/core/src/openjdk/sun/sun/security/util/SecurityConstants.java (rev 0)
+++ trunk/core/src/openjdk/sun/sun/security/util/SecurityConstants.java 2007-05-17 20:40:30 UTC (rev 3221)
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.security.util;
+
+import java.io.FilePermission;
+import java.awt.AWTPermission;
+import java.util.PropertyPermission;
+import java.lang.RuntimePermission;
+import java.net.SocketPermission;
+import java.net.NetPermission;
+import java.security.SecurityPermission;
+import java.security.AllPermission;
+import javax.security.auth.AuthPermission;
+
+/**
+ * Permission constants and string constants used to create permissions
+ * used throughout the JDK.
+ */
+public final class SecurityConstants {
+ // Cannot create one of these
+ private SecurityConstants () {
+ }
+
+ // Commonly used string constants for permission actions used by
+ // SecurityManager. Declare here for shortcut when checking permissions
+ // in FilePermission, SocketPermission, and PropertyPermission.
+
+ public static final String FILE_DELETE_ACTION = "delete";
+ public static final String FILE_EXECUTE_ACTION = "execute";
+ public static final String FILE_READ_ACTION = "read";
+ public static final String FILE_WRITE_ACTION = "write";
+
+ public static final String SOCKET_RESOLVE_ACTION = "resolve";
+ public static final String SOCKET_CONNECT_ACTION = "connect";
+ public static final String SOCKET_LISTEN_ACTION = "listen";
+ public static final String SOCKET_ACCEPT_ACTION = "accept";
+ public static final String SOCKET_CONNECT_ACCEPT_ACTION = "connect,accept";
+
+ public static final String PROPERTY_RW_ACTION = "read,write";
+ public static final String PROPERTY_READ_ACTION = "read";
+ public static final String PROPERTY_WRITE_ACTION = "write";
+
+ // Permission constants used in the various checkPermission() calls in JDK.
+
+ // java.lang.Class, java.lang.SecurityManager, java.lang.System,
+ // java.net.URLConnection, java.security.AllPermission, java.security.Policy,
+ // sun.security.provider.PolicyFile
+ public static final AllPermission ALL_PERMISSION = new AllPermission();
+
+ // java.lang.SecurityManager
+ public static final AWTPermission TOPLEVEL_WINDOW_PERMISSION =
+ new AWTPermission("showWindowWithoutWarningBanner");
+
+ // java.lang.SecurityManager
+ public static final AWTPermission ACCESS_CLIPBOARD_PERMISSION =
+ new AWTPermission("accessClipboard");
+
+ // java.lang.SecurityManager
+ public static final AWTPermission CHECK_AWT_EVENTQUEUE_PERMISSION =
+ new AWTPermission("accessEventQueue");
+
+ // java.awt.Dialog
+ public static final AWTPermission TOOLKIT_MODALITY_PERMISSION =
+ new AWTPermission("toolkitModality");
+
+ // java.awt.Robot
+ public static final AWTPermission READ_DISPLAY_PIXELS_PERMISSION =
+ new AWTPermission("readDisplayPixels");
+
+ // java.awt.Robot
+ public static final AWTPermission CREATE_ROBOT_PERMISSION =
+ new AWTPermission("createRobot");
+
+ // java.awt.MouseInfo
+ public static final AWTPermission WATCH_MOUSE_PERMISSION =
+ new AWTPermission("watchMousePointer");
+
+ // java.awt.Window
+ public static final AWTPermission SET_WINDOW_ALWAYS_ON_TOP_PERMISSION =
+ new AWTPermission("setWindowAlwaysOnTop");
+
+ // java.awt.Toolkit
+ public static final AWTPermission ALL_AWT_EVENTS_PERMISSION =
+ new AWTPermission("listenToAllAWTEvents");
+
+ // java.awt.SystemTray
+ public static final AWTPermission ACCESS_SYSTEM_TRAY_PERMISSION =
+ new AWTPermission("accessSystemTray");
+
+ // java.net.URL
+ public static final NetPermission SPECIFY_HANDLER_PERMISSION =
+ new NetPermission("specifyStreamHandler");
+
+ // java.net.ProxySelector
+ public static final NetPermission SET_PROXYSELECTOR_PERMISSION =
+ new NetPermission("setProxySelector");
+
+ // java.net.ProxySelector
+ public static final NetPermission GET_PROXYSELECTOR_PERMISSION =
+ new NetPermission("getProxySelector");
+
+ // java.net.CookieHandler
+ public static final NetPermission SET_COOKIEHANDLER_PERMISSION =
+ new NetPermission("setCookieHandler");
+
+ // java.net.CookieHandler
+ public static final NetPermission GET_COOKIEHANDLER_PERMISSION =
+ new NetPermission("getCookieHandler");
+
+ // java.net.ResponseCache
+ public static final NetPermission SET_RESPONSECACHE_PERMISSION =
+ new NetPermission("setResponseCache");
+
+ // java.net.ResponseCache
+ public static final NetPermission GET_RESPONSECACHE_PERMISSION =
+ new NetPermission("getResponseCache");
+
+ // java.lang.SecurityManager, sun.applet.AppletPanel, sun.misc.Launcher
+ public static final RuntimePermission CREATE_CLASSLOADER_PERMISSION =
+ new RuntimePermission("createClassLoader");
+
+ // java.lang.SecurityManager
+ public static final RuntimePermission CHECK_MEMBER_ACCESS_PERMISSION =
+ new RuntimePermission("accessDeclaredMembers");
+
+ // java.lang.SecurityManager, sun.applet.AppletSecurity
+ public static final RuntimePermission MODIFY_THREAD_PERMISSION =
+ new RuntimePermission("modifyThread");
+
+ // java.lang.SecurityManager, sun.applet.AppletSecurity
+ public static final RuntimePermission MODIFY_THREADGROUP_PERMISSION =
+ new RuntimePermission("modifyThreadGroup");
+
+ // java.lang.Class
+ public static final RuntimePermission GET_PD_PERMISSION =
+ new RuntimePermission("getProtectionDomain");
+
+ // java.lang.Class, java.lang.ClassLoader, java.lang.Thread
+ public static final RuntimePermission GET_CLASSLOADER_PERMISSION =
+ new RuntimePermission("getClassLoader");
+
+ // java.lang.Thread
+ public static final RuntimePermission STOP_THREAD_PERMISSION =
+ new RuntimePermission("stopThread");
+
+ // java.lang.Thread
+ public static final RuntimePermission GET_STACK_TRACE_PERMISSION =
+ new RuntimePermission("getStackTrace");
+
+ // java.security.AccessControlContext
+ public static final SecurityPermission CREATE_ACC_PERMISSION =
+ new SecurityPermission("createAccessControlContext");
+
+ // java.security.AccessControlContext
+ public static final SecurityPermission GET_COMBINER_PERMISSION =
+ new SecurityPermission("getDomainCombiner");
+
+ // java.security.Policy, java.security.ProtectionDomain
+ public static final SecurityPermission GET_POLICY_PERMISSION =
+ new SecurityPermission ("getPolicy");
+
+ // java.lang.SecurityManager
+ public static final SocketPermission LOCAL_LISTEN_PERMISSION =
+ new SocketPermission("localhost:1024-", SOCKET_LISTEN_ACTION);
+
+ // javax.security.auth.Subject
+ public static final AuthPermission DO_AS_PERMISSION =
+ new AuthPermission("doAs");
+
+ // javax.security.auth.Subject
+ public static final AuthPermission DO_AS_PRIVILEGED_PERMISSION =
+ new AuthPermission("doAsPrivileged");
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|