Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/validation/SecuritySupport.java
32285 views
/*1* Copyright (c) 2005, 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.validation;2627import java.io.IOException;28import java.net.URL;29import java.security.*;30import java.net.*;31import java.io.*;32import java.util.*;3334/**35* This class is duplicated for each JAXP subpackage so keep it in sync.36* It is package private and therefore is not exposed as part of the JAXP37* API.38*39* Security related methods that only work on J2SE 1.2 and newer.40*/41class SecuritySupport {424344ClassLoader getContextClassLoader() {45return (ClassLoader)46AccessController.doPrivileged(new PrivilegedAction() {47public Object run() {48ClassLoader cl = null;49//try {50cl = Thread.currentThread().getContextClassLoader();51//} catch (SecurityException ex) { }52if (cl == null)53cl = ClassLoader.getSystemClassLoader();54return 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 getURLInputStream(final URL url)84throws IOException85{86try {87return (InputStream)88AccessController.doPrivileged(new PrivilegedExceptionAction() {89public Object run() throws IOException {90return url.openStream();91}92});93} catch (PrivilegedActionException e) {94throw (IOException)e.getException();95}96}9798URL getResourceAsURL(final ClassLoader cl,99final String name)100{101return (URL)102AccessController.doPrivileged(new PrivilegedAction() {103public Object run() {104URL url;105if (cl == null) {106url = Object.class.getResource(name);107} else {108url = cl.getResource(name);109}110return url;111}112});113}114115Enumeration getResources(final ClassLoader cl,116final String name) throws IOException117{118try{119return (Enumeration)120AccessController.doPrivileged(new PrivilegedExceptionAction() {121public Object run() throws IOException{122Enumeration enumeration;123if (cl == null) {124enumeration = ClassLoader.getSystemResources(name);125} else {126enumeration = cl.getResources(name);127}128return enumeration;129}130});131}catch(PrivilegedActionException e){132throw (IOException)e.getException();133}134}135136InputStream getResourceAsStream(final ClassLoader cl,137final String name)138{139return (InputStream)140AccessController.doPrivileged(new PrivilegedAction() {141public Object run() {142InputStream ris;143if (cl == null) {144ris = Object.class.getResourceAsStream(name);145} else {146ris = cl.getResourceAsStream(name);147}148return ris;149}150});151}152153boolean doesFileExist(final File f) {154return ((Boolean)155AccessController.doPrivileged(new PrivilegedAction() {156public Object run() {157return new Boolean(f.exists());158}159})).booleanValue();160}161162}163164165