Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/parsers/SecuritySupport.java
48505 views
/*1* Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.parsers;2627import java.security.*;28import java.net.*;29import java.io.*;30import java.util.*;3132/**33* This class is duplicated for each JAXP subpackage so keep it in sync.34* It is package private and therefore is not exposed as part of the JAXP35* API.36*37* Security related methods that only work on J2SE 1.2 and newer.38*/39class SecuritySupport {404142ClassLoader getContextClassLoader() throws SecurityException{43return (ClassLoader)44AccessController.doPrivileged(new PrivilegedAction() {45public Object run() {46ClassLoader cl = null;47//try {48cl = Thread.currentThread().getContextClassLoader();49//} catch (SecurityException ex) { }5051if (cl == null)52cl = ClassLoader.getSystemClassLoader();5354return cl;55}56});57}5859String getSystemProperty(final String propName) {60return (String)61AccessController.doPrivileged(new PrivilegedAction() {62public Object run() {63return System.getProperty(propName);64}65});66}6768FileInputStream getFileInputStream(final File file)69throws FileNotFoundException70{71try {72return (FileInputStream)73AccessController.doPrivileged(new PrivilegedExceptionAction() {74public Object run() throws FileNotFoundException {75return new FileInputStream(file);76}77});78} catch (PrivilegedActionException e) {79throw (FileNotFoundException)e.getException();80}81}8283InputStream getResourceAsStream(final ClassLoader cl,84final String name)85{86return (InputStream)87AccessController.doPrivileged(new PrivilegedAction() {88public Object run() {89InputStream ris;90if (cl == null) {91ris = Object.class.getResourceAsStream(name);92} else {93ris = cl.getResourceAsStream(name);94}95return ris;96}97});98}99100boolean doesFileExist(final File f) {101return ((Boolean)102AccessController.doPrivileged(new PrivilegedAction() {103public Object run() {104return new Boolean(f.exists());105}106})).booleanValue();107}108109}110111112