2
* The Apache Software License, Version 1.1
5
* Copyright (c) 2002 The Apache Software Foundation. All rights
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
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
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.
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.
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.
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
47
* ====================================================================
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/>.
2
* Copyright 2002,2004,2006 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
56
17
package org.apache.xerces.impl.dv;
20
import java.io.FileInputStream;
21
import java.io.FileNotFoundException;
22
import java.io.InputStream;
24
import java.security.AccessController;
25
import java.security.PrivilegedAction;
26
import java.security.PrivilegedActionException;
27
import java.security.PrivilegedExceptionAction;
61
* This class is duplicated for each JAXP subpackage so keep it in sync.
62
* It is package private and therefore is not exposed as part of the JAXP
65
* Base class with security related methods that work on JDK 1.1.
30
* This class is duplicated for each subpackage so keep it in sync.
31
* It is package private and therefore is not exposed as part of any API.
67
class SecuritySupport {
70
* Make this of type Object so that the verifier won't try to
71
* prove its type, thus possibly trying to load the SecuritySupport12
74
private static final Object securitySupport;
77
SecuritySupport ss = null;
79
Class c = Class.forName("java.security.AccessController");
80
// if that worked, we're on 1.2.
82
// don't reference the class explicitly so it doesn't
83
// get dragged in accidentally.
84
c = Class.forName("javax.mail.SecuritySupport12");
85
Constructor cons = c.getConstructor(new Class[] { });
86
ss = (SecuritySupport)cons.newInstance(new Object[] { });
89
* Unfortunately, we can't load the class using reflection
90
* because the class is package private. And the class has
91
* to be package private so the APIs aren't exposed to other
92
* code that could use them to circumvent security. Thus,
93
* we accept the risk that the direct reference might fail
94
* on some JDK 1.1 JVMs, even though we would never execute
95
* this code in such a case. Sigh...
97
ss = new SecuritySupport12();
98
} catch (Exception ex) {
102
ss = new SecuritySupport();
103
securitySupport = ss;
35
final class SecuritySupport {
37
private static final SecuritySupport securitySupport = new SecuritySupport();
108
* Return an appropriate instance of this class, depending on whether
109
* we're on a JDK 1.1 or J2SE 1.2 (or later) system.
40
* Return an instance of this class.
111
42
static SecuritySupport getInstance() {
112
return (SecuritySupport)securitySupport;
43
return securitySupport;
115
46
ClassLoader getContextClassLoader() {
48
AccessController.doPrivileged(new PrivilegedAction() {
50
ClassLoader cl = null;
52
cl = Thread.currentThread().getContextClassLoader();
53
} catch (SecurityException ex) { }
119
59
ClassLoader getSystemClassLoader() {
123
ClassLoader getParentClassLoader(ClassLoader cl) {
127
String getSystemProperty(String propName) {
128
return System.getProperty(propName);
131
FileInputStream getFileInputStream(File file)
132
throws FileNotFoundException
61
AccessController.doPrivileged(new PrivilegedAction() {
63
ClassLoader cl = null;
65
cl = ClassLoader.getSystemClassLoader();
66
} catch (SecurityException ex) {}
72
ClassLoader getParentClassLoader(final ClassLoader cl) {
74
AccessController.doPrivileged(new PrivilegedAction() {
76
ClassLoader parent = null;
78
parent = cl.getParent();
79
} catch (SecurityException ex) {}
81
// eliminate loops in case of the boot
82
// ClassLoader returning itself as a parent
83
return (parent == cl) ? null : parent;
88
String getSystemProperty(final String propName) {
90
AccessController.doPrivileged(new PrivilegedAction() {
92
return System.getProperty(propName);
97
FileInputStream getFileInputStream(final File file)
98
throws FileNotFoundException
134
return new FileInputStream(file);
137
InputStream getResourceAsStream(ClassLoader cl, String name) {
140
ris = ClassLoader.getSystemResourceAsStream(name);
142
ris = cl.getResourceAsStream(name);
101
return (FileInputStream)
102
AccessController.doPrivileged(new PrivilegedExceptionAction() {
103
public Object run() throws FileNotFoundException {
104
return new FileInputStream(file);
107
} catch (PrivilegedActionException e) {
108
throw (FileNotFoundException)e.getException();
147
boolean getFileExists(File f) {
151
long getLastModified(File f) {
152
return f.lastModified();
112
InputStream getResourceAsStream(final ClassLoader cl,
116
AccessController.doPrivileged(new PrivilegedAction() {
117
public Object run() {
120
ris = ClassLoader.getSystemResourceAsStream(name);
122
ris = cl.getResourceAsStream(name);
129
boolean getFileExists(final File f) {
131
AccessController.doPrivileged(new PrivilegedAction() {
132
public Object run() {
133
return f.exists() ? Boolean.TRUE : Boolean.FALSE;
138
long getLastModified(final File f) {
140
AccessController.doPrivileged(new PrivilegedAction() {
141
public Object run() {
142
return new Long(f.lastModified());
147
private SecuritySupport () {}