1 /* 2 * The Apache Software License, Version 1.1 3 * 4 * 5 * Copyright (c) 2002 The Apache Software Foundation. All rights 6 * reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The end-user documentation included with the redistribution, 21 * if any, must include the following acknowledgment: 22 * "This product includes software developed by the 23 * Apache Software Foundation (http://www.apache.org/)." 24 * Alternately, this acknowledgment may appear in the software itself, 25 * if and wherever such third-party acknowledgments normally appear. 26 * 27 * 4. The name "Apache Software Foundation" must not be used to endorse or 28 * promote products derived from this software without prior written 29 * permission. For written permission, please contact apache@apache.org. 30 * 31 * 5. Products derived from this software may not be called "Apache", 32 * nor may "Apache" appear in their name, without prior written 33 * permission of the Apache Software Foundation. 34 * 35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 46 * SUCH DAMAGE. 47 * ==================================================================== 48 * 49 * This software consists of voluntary contributions made by many 50 * individuals on behalf of the Apache Software Foundation and was 51 * originally based on software copyright (c) 1999-2002, Sun Microsystems, 52 * Inc., http://www.sun.com. For more information on the Apache Software 53 * Foundation, please see <http://www.apache.org/>. 54 */ 55 56 package org.apache.xerces.parsers; 57 58 import java.security; 59 import java.io; 60 61 /** 62 * This class is duplicated for each JAXP subpackage so keep it in sync. 63 * It is package private and therefore is not exposed as part of the JAXP 64 * API. 65 * 66 * Security related methods that only work on J2SE 1.2 and newer. 67 */ 68 class SecuritySupport12 extends SecuritySupport { 69 70 ClassLoader getContextClassLoader() { 71 return (ClassLoader) 72 AccessController.doPrivileged(new PrivilegedAction() { 73 public Object run() { 74 ClassLoader cl = null; 75 try { 76 cl = Thread.currentThread().getContextClassLoader(); 77 } catch (SecurityException ex) { } 78 return cl; 79 } 80 }); 81 } 82 83 ClassLoader getSystemClassLoader() { 84 return (ClassLoader) 85 AccessController.doPrivileged(new PrivilegedAction() { 86 public Object run() { 87 ClassLoader cl = null; 88 try { 89 cl = ClassLoader.getSystemClassLoader(); 90 } catch (SecurityException ex) {} 91 return cl; 92 } 93 }); 94 } 95 96 ClassLoader getParentClassLoader(final ClassLoader cl) { 97 return (ClassLoader) 98 AccessController.doPrivileged(new PrivilegedAction() { 99 public Object run() { 100 ClassLoader parent = null; 101 try { 102 parent = cl.getParent(); 103 } catch (SecurityException ex) {} 104 105 // eliminate loops in case of the boot 106 // ClassLoader returning itself as a parent 107 return (parent == cl) ? null : parent; 108 } 109 }); 110 } 111 112 String getSystemProperty(final String propName) { 113 return (String) 114 AccessController.doPrivileged(new PrivilegedAction() { 115 public Object run() { 116 return System.getProperty(propName); 117 } 118 }); 119 } 120 121 FileInputStream getFileInputStream(final File file) 122 throws FileNotFoundException 123 { 124 try { 125 return (FileInputStream) 126 AccessController.doPrivileged(new PrivilegedExceptionAction() { 127 public Object run() throws FileNotFoundException { 128 return new FileInputStream(file); 129 } 130 }); 131 } catch (PrivilegedActionException e) { 132 throw (FileNotFoundException)e.getException(); 133 } 134 } 135 136 InputStream getResourceAsStream(final ClassLoader cl, 137 final String name) 138 { 139 return (InputStream) 140 AccessController.doPrivileged(new PrivilegedAction() { 141 public Object run() { 142 InputStream ris; 143 if (cl == null) { 144 ris = ClassLoader.getSystemResourceAsStream(name); 145 } else { 146 ris = cl.getResourceAsStream(name); 147 } 148 return ris; 149 } 150 }); 151 } 152 153 boolean getFileExists(final File f) { 154 return ((Boolean) 155 AccessController.doPrivileged(new PrivilegedAction() { 156 public Object run() { 157 return new Boolean(f.exists()); 158 } 159 })).booleanValue(); 160 } 161 162 long getLastModified(final File f) { 163 return ((Long) 164 AccessController.doPrivileged(new PrivilegedAction() { 165 public Object run() { 166 return new Long(f.lastModified()); 167 } 168 })).longValue(); 169 } 170 171 }