<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSecurity%2FAccessController</id>
		<title>Java/Security/AccessController - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSecurity%2FAccessController"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/AccessController&amp;action=history"/>
		<updated>2026-04-21T17:23:54Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Security/AccessController&amp;diff=7623&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/AccessController&amp;diff=7623&amp;oldid=prev"/>
				<updated>2010-06-01T06:48:59Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:48, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Security/AccessController&amp;diff=7622&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/AccessController&amp;diff=7622&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== AccessController.doPrivileged(new PrivilegedAction() ) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.security.AccessController;&lt;br /&gt;
import java.security.PrivilegedAction;&lt;br /&gt;
&lt;br /&gt;
public class Main {&lt;br /&gt;
  &lt;br /&gt;
  static long getLastModified(final File f) {&lt;br /&gt;
      return ((Long)&lt;br /&gt;
              AccessController.doPrivileged(new PrivilegedAction() {&lt;br /&gt;
                  public Object run() {&lt;br /&gt;
                      return new Long(f.lastModified());&lt;br /&gt;
                  }&lt;br /&gt;
              })).longValue();&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;ClassLoader&amp;gt; ClassLoader java.security.AccessController.doPrivileged(PrivilegedAction&amp;lt;ClassLoader&amp;gt; action) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
  * JBoss, Home of Professional Open Source&lt;br /&gt;
  * Copyright 2005, JBoss Inc., and individual contributors as indicated&lt;br /&gt;
  * by the @authors tag. See the copyright.txt in the distribution for a&lt;br /&gt;
  * full listing of individual contributors.&lt;br /&gt;
  *&lt;br /&gt;
  * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
  * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
  * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
  * the License, or (at your option) any later version.&lt;br /&gt;
  *&lt;br /&gt;
  * This software is distributed in the hope that it will be useful,&lt;br /&gt;
  * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
  * Lesser General Public License for more details.&lt;br /&gt;
  *&lt;br /&gt;
  * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
  * License along with this software; if not, write to the Free&lt;br /&gt;
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
  */&lt;br /&gt;
import java.security.AccessController;&lt;br /&gt;
import java.security.PrivilegedAction;&lt;br /&gt;
/** A collection of privileged actions&lt;br /&gt;
 * @author Clebert Suconic&lt;br /&gt;
 */&lt;br /&gt;
class SecurityActions&lt;br /&gt;
{&lt;br /&gt;
   static ClassLoader getTCL()&lt;br /&gt;
   {&lt;br /&gt;
      if (System.getSecurityManager() == null)&lt;br /&gt;
      {&lt;br /&gt;
         return Thread.currentThread().getContextClassLoader();&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         return AccessController.doPrivileged(new PrivilegedAction&amp;lt;ClassLoader&amp;gt;()&lt;br /&gt;
         {&lt;br /&gt;
            public ClassLoader run()&lt;br /&gt;
            {&lt;br /&gt;
               return Thread.currentThread().getContextClassLoader();&lt;br /&gt;
            }&lt;br /&gt;
         });&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   static ClassLoader getClassLoader(final Class&amp;lt;?&amp;gt; clazz)&lt;br /&gt;
   {&lt;br /&gt;
      if (System.getSecurityManager() == null)&lt;br /&gt;
      {&lt;br /&gt;
         return clazz.getClassLoader();&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         return AccessController.doPrivileged(new PrivilegedAction&amp;lt;ClassLoader&amp;gt;()&lt;br /&gt;
         {&lt;br /&gt;
            public ClassLoader run()&lt;br /&gt;
            {&lt;br /&gt;
               return clazz.getClassLoader();&lt;br /&gt;
            }&lt;br /&gt;
         });&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   static void setTCL(final ClassLoader tcl)&lt;br /&gt;
   {&lt;br /&gt;
      if (System.getSecurityManager() == null)&lt;br /&gt;
      {&lt;br /&gt;
         Thread.currentThread().setContextClassLoader(tcl);&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         AccessController.doPrivileged(new PrivilegedAction&amp;lt;Object&amp;gt;()&lt;br /&gt;
         {&lt;br /&gt;
            public Object run()&lt;br /&gt;
            {&lt;br /&gt;
               Thread.currentThread().setContextClassLoader(tcl);&lt;br /&gt;
               return null;&lt;br /&gt;
            }&lt;br /&gt;
         });&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Load class ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright  2003-2008 The Apache Software Foundation.&lt;br /&gt;
 *&lt;br /&gt;
 *  Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
 *  you may not use this file except in compliance with the License.&lt;br /&gt;
 *  You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 *      http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 *  Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 *  distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 *  See the License for the specific language governing permissions and&lt;br /&gt;
 *  limitations under the License.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
import java.lang.reflect.InvocationTargetException;&lt;br /&gt;
import java.security.AccessController;&lt;br /&gt;
import java.security.PrivilegedAction;&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * If running under JDK 1.2 load the specified class using the&lt;br /&gt;
   * &amp;lt;code&amp;gt;Thread&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;contextClassLoader&amp;lt;/code&amp;gt; if that&lt;br /&gt;
   * fails try Class.forname.&lt;br /&gt;
   * &amp;lt;p/&amp;gt;&lt;br /&gt;
   *&lt;br /&gt;
   * @param clazz&lt;br /&gt;
   * @return TODO&lt;br /&gt;
   * @throws ClassNotFoundException&lt;br /&gt;
   */&lt;br /&gt;
  public static Class loadClass(String clazz) throws ClassNotFoundException {&lt;br /&gt;
      return loadClass(clazz, true);&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public static Class loadClass(String clazz, boolean warn) throws ClassNotFoundException {&lt;br /&gt;
      try {&lt;br /&gt;
          ClassLoader tcl = getTCL(); &lt;br /&gt;
          &lt;br /&gt;
          if (tcl != null) {&lt;br /&gt;
              Class c = tcl.loadClass(clazz);&lt;br /&gt;
              if (c != null) {&lt;br /&gt;
                  return c;&lt;br /&gt;
              }&lt;br /&gt;
          }&lt;br /&gt;
      } catch (Throwable e) {&lt;br /&gt;
      }&lt;br /&gt;
      // we reached here because tcl was null or because of a&lt;br /&gt;
      // security exception, or because clazz could not be loaded...&lt;br /&gt;
      // In any case we now try one more time&lt;br /&gt;
      return Class.forName(clazz);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the Thread context class loader.&lt;br /&gt;
   * &amp;lt;p/&amp;gt;&lt;br /&gt;
   *&lt;br /&gt;
   * @return the Thread context class loader&lt;br /&gt;
   * @throws IllegalAccessException&lt;br /&gt;
   * @throws InvocationTargetException&lt;br /&gt;
   */&lt;br /&gt;
  public static ClassLoader getTCL() throws IllegalAccessException, InvocationTargetException {&lt;br /&gt;
       return (ClassLoader)AccessController.doPrivileged(new PrivilegedAction() {&lt;br /&gt;
          public Object run() {&lt;br /&gt;
              return Thread.currentThread().getContextClassLoader();&lt;br /&gt;
          }&lt;br /&gt;
       });&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lock request from going up in the classloader hierarchy ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/**&lt;br /&gt;
 * Licensed to the Apache Software Foundation (ASF) under one&lt;br /&gt;
 * or more contributor license agreements. See the NOTICE file&lt;br /&gt;
 * distributed with this work for additional information&lt;br /&gt;
 * regarding copyright ownership. The ASF licenses this file&lt;br /&gt;
 * to you under the Apache License, Version 2.0 (the&lt;br /&gt;
 * &amp;quot;License&amp;quot;); you may not use this file except in compliance&lt;br /&gt;
 * with the License. You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 * http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 * Unless required by applicable law or agreed to in writing,&lt;br /&gt;
 * software distributed under the License is distributed on an&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY&lt;br /&gt;
 * KIND, either express or implied. See the License for the&lt;br /&gt;
 * specific language governing permissions and limitations&lt;br /&gt;
 * under the License.&lt;br /&gt;
 */&lt;br /&gt;
import java.security.SecureClassLoader;&lt;br /&gt;
/**&lt;br /&gt;
 * The FireWallClassLoader is a classloader that can block request from going up&lt;br /&gt;
 * in the classloader hierarchy.&lt;br /&gt;
 * &amp;lt;P&amp;gt;&lt;br /&gt;
 * Normally, when a classloader receives a request for a resource, it will&lt;br /&gt;
 * consult its parent class loader first for that resource. The parent class&lt;br /&gt;
 * loader is typically the System ClassLoader. If the parent class loader cannot&lt;br /&gt;
 * provide the requested resource, the child class loader will be consulted for&lt;br /&gt;
 * the request. &amp;lt;I&amp;gt;Note: the parent class loader must not be confused by the&lt;br /&gt;
 * superclass of a certain class loader (e.g. SecureClassLoader). The parent&lt;br /&gt;
 * classloader is identified at constuction time and passed in as an constructor&lt;br /&gt;
 * argument.&amp;lt;/I&amp;gt;&lt;br /&gt;
 * &amp;lt;P&amp;gt;&lt;br /&gt;
 * Consulting the parent classloader first can be inconvenient for certain&lt;br /&gt;
 * applications that want guarantees about which classloader is used to load a&lt;br /&gt;
 * certain class. This could be because you want to be certain about where the&lt;br /&gt;
 * resource came from, or you want to protect yourself against (other versions)&lt;br /&gt;
 * of the same class that could be served by the System ClassLoader (e.g.&lt;br /&gt;
 * because someone put them on the classpath or in the extensions directory).&lt;br /&gt;
 * &amp;lt;P&amp;gt;&lt;br /&gt;
 * For these cases, the FireWallClassLoader can be used.&lt;br /&gt;
 * &lt;br /&gt;
 * &amp;lt;PRE&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * System ClassLoader | FireWallClassLoader | User&amp;quot;s ClassLoader&lt;br /&gt;
 * &lt;br /&gt;
 * &amp;lt;/PRE&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * The FireWallClassLoader is placed between the user&amp;quot;s class loader and the&lt;br /&gt;
 * parent class loader. It has a set of filters that define what classes are&lt;br /&gt;
 * allowed to go through. These filters describe (a groups of) packages, or a&lt;br /&gt;
 * specific classes or resources that are allowed through to the parent&lt;br /&gt;
 * classloader. Take as example this filter set:&lt;br /&gt;
 * &lt;br /&gt;
 * &amp;lt;pre&amp;gt;&lt;br /&gt;
 * [&amp;amp;quot;com.iona.&amp;amp;quot;, &amp;amp;quot;javax.servlet.jsp.&amp;amp;quot;]&lt;br /&gt;
 * &amp;lt;/pre&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This will allow requests to any class/resource staring with com.iona. or&lt;br /&gt;
 * javax.servlet.jsp. through to the parent classloader and block all other&lt;br /&gt;
 * requests.&lt;br /&gt;
 * &amp;lt;P&amp;gt;&lt;br /&gt;
 * A very common set of filters would be a set that allows nothing through&lt;br /&gt;
 * except the classes used by the JDK. The {@link JDKFireWallClassLoaderFactory}&lt;br /&gt;
 * factory class can create such FireWallClassLoader.&lt;br /&gt;
 * &amp;lt;P&amp;gt;&lt;br /&gt;
 * The FireWallClassLoader does not load any classes.&lt;br /&gt;
 */&lt;br /&gt;
public class FireWallClassLoader extends SecureClassLoader {&lt;br /&gt;
    private final String[] filters;&lt;br /&gt;
    private final String[] fnFilters;&lt;br /&gt;
    private final String[] negativeFilters;&lt;br /&gt;
    private final String[] negativeFNFilters;&lt;br /&gt;
    /**&lt;br /&gt;
     * Constructor.&lt;br /&gt;
     * &lt;br /&gt;
     * @param parent The Parent ClassLoader to use.&lt;br /&gt;
     * @param fs A set of filters to let through. The filters and be either in&lt;br /&gt;
     *            package form (&amp;lt;CODE&amp;gt;org.omg.&amp;lt;/CODE&amp;gt; or &amp;lt;CODE&amp;gt;org.omg.*&amp;lt;/CODE&amp;gt;)&lt;br /&gt;
     *            or specify a single class (&amp;lt;CODE&amp;gt;junit.framework.TestCase&amp;lt;/CODE&amp;gt;).&lt;br /&gt;
     *            &amp;lt;P&amp;gt;&lt;br /&gt;
     *            When the package form is used, all classed in all subpackages&lt;br /&gt;
     *            of this package are let trough the firewall. When the class&lt;br /&gt;
     *            form is used, the filter only lets that single class through.&lt;br /&gt;
     *            Note that when that class depends on another class, this class&lt;br /&gt;
     *            does not need to be mentioned as a filter, because if the&lt;br /&gt;
     *            originating class is loaded by the parent classloader, the&lt;br /&gt;
     *            FireWallClassLoader will not receive requests for the&lt;br /&gt;
     *            dependant class.&lt;br /&gt;
     */&lt;br /&gt;
    public FireWallClassLoader(ClassLoader parent, String[] fs) {&lt;br /&gt;
        this(parent, fs, new String[0]);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Constructor.&lt;br /&gt;
     * &lt;br /&gt;
     * @param parent The Parent ClassLoader to use.&lt;br /&gt;
     * @param fs A set of filters to let through. The filters and be either in&lt;br /&gt;
     *            package form (&amp;lt;CODE&amp;gt;org.omg.&amp;lt;/CODE&amp;gt; or &amp;lt;CODE&amp;gt;org.omg.*&amp;lt;/CODE&amp;gt;)&lt;br /&gt;
     *            or specify a single class (&amp;lt;CODE&amp;gt;junit.framework.TestCase&amp;lt;/CODE&amp;gt;).&lt;br /&gt;
     *            &amp;lt;P&amp;gt;&lt;br /&gt;
     *            When the package form is used, all classed in all subpackages&lt;br /&gt;
     *            of this package are let trough the firewall. When the class&lt;br /&gt;
     *            form is used, the filter only lets that single class through.&lt;br /&gt;
     *            Note that when that class depends on another class, this class&lt;br /&gt;
     *            does not need to be mentioned as a filter, because if the&lt;br /&gt;
     *            originating class is loaded by the parent classloader, the&lt;br /&gt;
     *            FireWallClassLoader will not receive requests for the&lt;br /&gt;
     *            dependant class.&lt;br /&gt;
     * @param negativeFs List of negative filters to use. Negative filters take&lt;br /&gt;
     *            precedence over positive filters. When a class or resource is&lt;br /&gt;
     *            requested that matches a negative filter it is not let through&lt;br /&gt;
     *            the firewall even if an allowing filter would exist in the&lt;br /&gt;
     *            positive filter list.&lt;br /&gt;
     */&lt;br /&gt;
    public FireWallClassLoader(ClassLoader parent, String[] fs, String[] negativeFs) {&lt;br /&gt;
        super(parent);&lt;br /&gt;
        this.filters = processFilters(fs);&lt;br /&gt;
        this.negativeFilters = processFilters(negativeFs);&lt;br /&gt;
        this.fnFilters = filters2FNFilters(this.filters);&lt;br /&gt;
        this.negativeFNFilters = filters2FNFilters(this.negativeFilters);&lt;br /&gt;
        boolean javaCovered = false;&lt;br /&gt;
        if (this.filters == null) {&lt;br /&gt;
            javaCovered = true;&lt;br /&gt;
        } else {&lt;br /&gt;
            for (int i = 0; i &amp;lt; this.filters.length; i++) {&lt;br /&gt;
                if (this.filters[i].equals(&amp;quot;java.&amp;quot;)) {&lt;br /&gt;
                    javaCovered = true;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (this.negativeFilters != null) {&lt;br /&gt;
            String java = &amp;quot;java.&amp;quot;;&lt;br /&gt;
            // try all that would match java: j, ja, jav, java and java.&lt;br /&gt;
            for (int i = java.length(); i &amp;gt;= 0; i--) {&lt;br /&gt;
                for (int j = 0; j &amp;lt; this.negativeFilters.length; j++) {&lt;br /&gt;
                    if (negativeFilters[j].equals(java.substring(0, i))) {&lt;br /&gt;
                        javaCovered = false;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (!javaCovered) {&lt;br /&gt;
            throw new SecurityException(&amp;quot;It&amp;quot;s unsafe to construct a &amp;quot; &lt;br /&gt;
                        + &amp;quot;FireWallClassLoader that does not let the java. &amp;quot; &lt;br /&gt;
                        + &amp;quot;package through.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    private static String[] processFilters(String[] fs) {&lt;br /&gt;
        if (fs == null || fs.length == 0) {&lt;br /&gt;
            return null;&lt;br /&gt;
        }&lt;br /&gt;
        String[] f = new String[fs.length];&lt;br /&gt;
        for (int i = 0; i &amp;lt; fs.length; i++) {&lt;br /&gt;
            String filter = fs[i];&lt;br /&gt;
            if (filter.endsWith(&amp;quot;*&amp;quot;)) {&lt;br /&gt;
                filter = filter.substring(0, filter.length() - 1);&lt;br /&gt;
            }&lt;br /&gt;
            f[i] = filter;&lt;br /&gt;
        }&lt;br /&gt;
        return f;&lt;br /&gt;
    }&lt;br /&gt;
    private static String[] filters2FNFilters(String[] fs) {&lt;br /&gt;
        if (fs == null || fs.length == 0) {&lt;br /&gt;
            return null;&lt;br /&gt;
        }&lt;br /&gt;
        String[] f = new String[fs.length];&lt;br /&gt;
        for (int i = 0; i &amp;lt; fs.length; i++) {&lt;br /&gt;
            f[i] = fs[i].replace(&amp;quot;.&amp;quot;, &amp;quot;/&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        return f;&lt;br /&gt;
    }&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; loadClass(String name, boolean resolve) throws ClassNotFoundException {&lt;br /&gt;
        if (negativeFilters != null) {&lt;br /&gt;
            for (int i = 0; i &amp;lt; negativeFilters.length; i++) {&lt;br /&gt;
                if (name.startsWith(negativeFilters[i])) {&lt;br /&gt;
                    throw new ClassNotFoundException(name);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (filters != null) {&lt;br /&gt;
            for (int i = 0; i &amp;lt; filters.length; i++) {&lt;br /&gt;
                if (name.startsWith(filters[i])) {&lt;br /&gt;
                    return super.loadClass(name, resolve);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        } else {&lt;br /&gt;
            return super.loadClass(name, resolve);&lt;br /&gt;
        }&lt;br /&gt;
        throw new ClassNotFoundException(name);&lt;br /&gt;
    }&lt;br /&gt;
    /*protected Class&amp;lt;?&amp;gt; findClass(String name) throws ClassNotFoundException {&lt;br /&gt;
        if (negativeFilters != null) {&lt;br /&gt;
            for (int i = 0; i &amp;lt; negativeFilters.length; i++) {&lt;br /&gt;
                if (name.startsWith(negativeFilters[i])) {&lt;br /&gt;
                    throw new ClassNotFoundException(name);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (filters != null) {&lt;br /&gt;
            for (int i = 0; i &amp;lt; filters.length; i++) {&lt;br /&gt;
                if (name.startsWith(filters[i])) {&lt;br /&gt;
                    return super.findClass(name);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        } else {&lt;br /&gt;
            return super.loadClass(name);&lt;br /&gt;
        }&lt;br /&gt;
        throw new ClassNotFoundException(name);&lt;br /&gt;
    }*/&lt;br /&gt;
    &lt;br /&gt;
    public java.net.URL getResource(String name) {&lt;br /&gt;
        if (negativeFNFilters != null) {&lt;br /&gt;
            for (int i = 0; i &amp;lt; negativeFNFilters.length; i++) {&lt;br /&gt;
                if (name.startsWith(negativeFNFilters[i])) {&lt;br /&gt;
                    return null;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (fnFilters != null) {&lt;br /&gt;
            for (int i = 0; i &amp;lt; fnFilters.length; i++) {&lt;br /&gt;
                if (name.startsWith(fnFilters[i])) {&lt;br /&gt;
                    return super.getResource(name);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        } else {&lt;br /&gt;
            return super.getResource(name);&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the list of filters used by this FireWallClassLoader. The list is&lt;br /&gt;
     * a copy of the array internally used.&lt;br /&gt;
     * &lt;br /&gt;
     * @return The filters used.&lt;br /&gt;
     */&lt;br /&gt;
    public String[] getFilters() {&lt;br /&gt;
        if (filters == null) {&lt;br /&gt;
            return null;&lt;br /&gt;
        }&lt;br /&gt;
        return (String[])filters.clone();&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the list of negative filters used by this FireWallClassLoader.&lt;br /&gt;
     * The list is a copy of the array internally used.&lt;br /&gt;
     * &lt;br /&gt;
     * @return The filters used.&lt;br /&gt;
     */&lt;br /&gt;
    public String[] getNegativeFilters() {&lt;br /&gt;
        if (negativeFilters == null) {&lt;br /&gt;
            return null;&lt;br /&gt;
        }&lt;br /&gt;
        return (String[])negativeFilters.clone();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Make AccessibleObject Accessible ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.lang.reflect.AccessibleObject;&lt;br /&gt;
import java.security.AccessController;&lt;br /&gt;
import java.security.PrivilegedAction;&lt;br /&gt;
&lt;br /&gt;
public class Utils {&lt;br /&gt;
&lt;br /&gt;
  public static void makeAccessible( final AccessibleObject object ) {&lt;br /&gt;
      if (!object.isAccessible()) {&lt;br /&gt;
          if (System.getSecurityManager() == null) {&lt;br /&gt;
              object.setAccessible(true);&lt;br /&gt;
          } else {&lt;br /&gt;
              AccessController.doPrivileged(new PrivilegedAction&amp;lt;Object&amp;gt;() {&lt;br /&gt;
                  public Object run() {&lt;br /&gt;
                      object.setAccessible(true);&lt;br /&gt;
                      return null;&lt;br /&gt;
                  }&lt;br /&gt;
              });&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Search for resource in different places. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright  2003-2008 The Apache Software Foundation.&lt;br /&gt;
 *&lt;br /&gt;
 *  Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
 *  you may not use this file except in compliance with the License.&lt;br /&gt;
 *  You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 *      http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 *  Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 *  distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 *  See the License for the specific language governing permissions and&lt;br /&gt;
 *  limitations under the License.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
import java.lang.reflect.InvocationTargetException;&lt;br /&gt;
import java.net.URL;&lt;br /&gt;
import java.security.AccessController;&lt;br /&gt;
import java.security.PrivilegedAction;&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * This method will search for &amp;lt;code&amp;gt;resource&amp;lt;/code&amp;gt; in different&lt;br /&gt;
   * places. The search order is as follows:&lt;br /&gt;
   * &amp;lt;ol&amp;gt;&lt;br /&gt;
   * &amp;lt;p&amp;gt;&amp;lt;li&amp;gt;Search for &amp;lt;code&amp;gt;resource&amp;lt;/code&amp;gt; using the thread context&lt;br /&gt;
   * class loader under Java2.&lt;br /&gt;
   * &amp;lt;p&amp;gt;&amp;lt;li&amp;gt;Try one last time with&lt;br /&gt;
   * &amp;lt;code&amp;gt;ClassLoader.getSystemResource(resource)&amp;lt;/code&amp;gt;, that is is&lt;br /&gt;
   * using the system class loader in JDK 1.2 and virtual machine&amp;quot;s&lt;br /&gt;
   * built-in class loader in JDK 1.1.&lt;br /&gt;
   * &amp;lt;/ol&amp;gt;&lt;br /&gt;
   * &amp;lt;p/&amp;gt;&lt;br /&gt;
   *&lt;br /&gt;
   * @param resource&lt;br /&gt;
   * @return TODO&lt;br /&gt;
   */&lt;br /&gt;
  public static URL getResource(String resource) {&lt;br /&gt;
      ClassLoader classLoader = null;&lt;br /&gt;
      URL url = null;&lt;br /&gt;
      try {&lt;br /&gt;
          classLoader = getTCL();&lt;br /&gt;
          if (classLoader != null) {&lt;br /&gt;
              url = classLoader.getResource(resource);&lt;br /&gt;
              if (url != null) {&lt;br /&gt;
                  return url;&lt;br /&gt;
              }&lt;br /&gt;
          }&lt;br /&gt;
      } catch (Throwable t) {&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      // Last ditch attempt: get the resource from the class path. It&lt;br /&gt;
      // may be the case that clazz was loaded by the Extension class&lt;br /&gt;
      // loader which the parent of the system class loader. Hence the&lt;br /&gt;
      // code below.&lt;br /&gt;
   &lt;br /&gt;
      return ClassLoader.getSystemResource(resource);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the Thread context class loader.&lt;br /&gt;
   * &amp;lt;p/&amp;gt;&lt;br /&gt;
   *&lt;br /&gt;
   * @return the Thread context class loader&lt;br /&gt;
   * @throws IllegalAccessException&lt;br /&gt;
   * @throws InvocationTargetException&lt;br /&gt;
   */&lt;br /&gt;
  public static ClassLoader getTCL() throws IllegalAccessException, InvocationTargetException {&lt;br /&gt;
       return (ClassLoader)AccessController.doPrivileged(new PrivilegedAction() {&lt;br /&gt;
          public Object run() {&lt;br /&gt;
              return Thread.currentThread().getContextClassLoader();&lt;br /&gt;
          }&lt;br /&gt;
       });&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Use AccessController to check the AWT permission ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
import java.awt.AWTPermission;&lt;br /&gt;
import java.io.FilePermission;&lt;br /&gt;
import java.security.AccessController;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) throws Exception {&lt;br /&gt;
    AWTPermission ap = new AWTPermission(&amp;quot;accessClipboard&amp;quot;);&lt;br /&gt;
    AccessController.checkPermission(ap);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Use AccessController to check the file permission ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
import java.awt.AWTPermission;&lt;br /&gt;
import java.io.FilePermission;&lt;br /&gt;
import java.security.AccessController;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) throws Exception {&lt;br /&gt;
    FilePermission fp = new FilePermission(&amp;quot;c:\\autoexec.bat&amp;quot;, &amp;quot;read&amp;quot;);&lt;br /&gt;
    AccessController.checkPermission(fp);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>