View | Details | Raw Unified | Return to bug 56777
Collapse All | Expand All

(-)java/org/apache/catalina/loader/WebappLoader.java (-2 / +2 lines)
Lines 57-63 import org.apache.catalina.core.StandardContext; Link Here
57
import org.apache.catalina.mbeans.MBeanUtils;
57
import org.apache.catalina.mbeans.MBeanUtils;
58
import org.apache.catalina.util.LifecycleMBeanBase;
58
import org.apache.catalina.util.LifecycleMBeanBase;
59
import org.apache.naming.resources.DirContextURLStreamHandler;
59
import org.apache.naming.resources.DirContextURLStreamHandler;
60
import org.apache.naming.resources.DirContextURLStreamHandlerFactory;
60
import org.apache.naming.resources.TomcatURLStreamHandlerFactory;
61
import org.apache.naming.resources.Resource;
61
import org.apache.naming.resources.Resource;
62
import org.apache.tomcat.util.ExceptionUtils;
62
import org.apache.tomcat.util.ExceptionUtils;
63
import org.apache.tomcat.util.modeler.Registry;
63
import org.apache.tomcat.util.modeler.Registry;
Lines 560-566 public class WebappLoader extends LifecycleMBeanBase Link Here
560
560
561
        // Register a stream handler factory for the JNDI protocol
561
        // Register a stream handler factory for the JNDI protocol
562
        URLStreamHandlerFactory streamHandlerFactory =
562
        URLStreamHandlerFactory streamHandlerFactory =
563
                DirContextURLStreamHandlerFactory.getInstance();
563
                TomcatURLStreamHandlerFactory.getInstance();
564
        if (first) {
564
        if (first) {
565
            first = false;
565
            first = false;
566
            try {
566
            try {
(-)java/org/apache/catalina/realm/MemoryRealm.java (-23 / +36 lines)
Lines 19-35 Link Here
19
package org.apache.catalina.realm;
19
package org.apache.catalina.realm;
20
20
21
21
22
import java.io.File;
22
import java.io.IOException;
23
import java.io.InputStream;
23
import java.security.Principal;
24
import java.security.Principal;
24
import java.util.ArrayList;
25
import java.util.ArrayList;
25
import java.util.HashMap;
26
import java.util.HashMap;
26
import java.util.Map;
27
import java.util.Map;
27
28
28
import org.apache.catalina.Globals;
29
import org.apache.catalina.LifecycleException;
29
import org.apache.catalina.LifecycleException;
30
import org.apache.juli.logging.Log;
30
import org.apache.juli.logging.Log;
31
import org.apache.juli.logging.LogFactory;
31
import org.apache.juli.logging.LogFactory;
32
import org.apache.tomcat.util.digester.Digester;
32
import org.apache.tomcat.util.digester.Digester;
33
import org.apache.tomcat.util.file.ConfigFileLoader;
33
34
34
35
35
/**
36
/**
Lines 282-311 public class MemoryRealm extends RealmBase { Link Here
282
    @Override
283
    @Override
283
    protected void startInternal() throws LifecycleException {
284
    protected void startInternal() throws LifecycleException {
284
285
285
        // Validate the existence of our database file
286
        String pathName = getPathname();
286
        File file = new File(pathname);
287
        InputStream is = null;
287
        if (!file.isAbsolute())
288
288
            file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
289
        if (!file.exists() || !file.canRead())
290
            throw new LifecycleException
291
                (sm.getString("memoryRealm.loadExist",
292
                              file.getAbsolutePath()));
293
294
        // Load the contents of the database file
295
        if (log.isDebugEnabled())
296
            log.debug(sm.getString("memoryRealm.loadPath",
297
                             file.getAbsolutePath()));
298
        Digester digester = getDigester();
299
        try {
289
        try {
300
            synchronized (digester) {
290
            is = ConfigFileLoader.getInputStream(pathName);
301
                digester.push(this);
291
302
                digester.parse(file);
292
            // Load the contents of the database file
293
            if (log.isDebugEnabled()) {
294
                log.debug(sm.getString("memoryRealm.loadPath", pathName));
303
            }
295
            }
304
        } catch (Exception e) {
296
305
            throw new LifecycleException
297
            Digester digester = getDigester();
306
                (sm.getString("memoryRealm.readXml"), e);
298
            try {
299
                synchronized (digester) {
300
                    digester.push(this);
301
                    digester.parse(is);
302
                }
303
            } catch (Exception e) {
304
                throw new LifecycleException
305
                        (sm.getString("memoryRealm.readXml"), e);
306
            } finally {
307
                digester.reset();
308
            }
309
310
        } catch (IOException ioe) {
311
            throw new LifecycleException(sm.getString("memoryRealm.loadExist",
312
                            pathName), ioe);
313
307
        } finally {
314
        } finally {
308
            digester.reset();
315
            if (is != null) {
316
                try {
317
                    is.close();
318
                } catch (IOException e) {
319
                    // ignore
320
                }
321
            }
309
        }
322
        }
310
323
311
        super.startInternal();
324
        super.startInternal();
(-)java/org/apache/catalina/users/MemoryUserDatabase.java (-38 / +31 lines)
Lines 17-25 Link Here
17
package org.apache.catalina.users;
17
package org.apache.catalina.users;
18
18
19
import java.io.File;
19
import java.io.File;
20
import java.io.FileInputStream;
21
import java.io.FileOutputStream;
20
import java.io.FileOutputStream;
22
import java.io.IOException;
21
import java.io.IOException;
22
import java.io.InputStream;
23
import java.io.OutputStreamWriter;
23
import java.io.OutputStreamWriter;
24
import java.io.PrintWriter;
24
import java.io.PrintWriter;
25
import java.util.HashMap;
25
import java.util.HashMap;
Lines 34-39 import org.apache.juli.logging.Log; Link Here
34
import org.apache.juli.logging.LogFactory;
34
import org.apache.juli.logging.LogFactory;
35
import org.apache.tomcat.util.digester.AbstractObjectCreationFactory;
35
import org.apache.tomcat.util.digester.AbstractObjectCreationFactory;
36
import org.apache.tomcat.util.digester.Digester;
36
import org.apache.tomcat.util.digester.Digester;
37
import org.apache.tomcat.util.file.ConfigFileLoader;
37
import org.apache.tomcat.util.res.StringManager;
38
import org.apache.tomcat.util.res.StringManager;
38
import org.xml.sax.Attributes;
39
import org.xml.sax.Attributes;
39
40
Lines 394-445 public class MemoryUserDatabase implements UserDatabase { Link Here
394
                groups.clear();
395
                groups.clear();
395
                roles.clear();
396
                roles.clear();
396
397
397
                // Construct a reader for the XML input file (if it exists)
398
                String pathName = getPathname();
398
                File file = new File(pathname);
399
                InputStream is = null;
399
                if (!file.isAbsolute()) {
400
                    file = new File(System.getProperty(Globals.CATALINA_BASE_PROP),
401
                                    pathname);
402
                }
403
                if (!file.exists()) {
404
                    log.error(sm.getString("memoryUserDatabase.fileNotFound",
405
                            file.getAbsolutePath()));
406
                    return;
407
                }
408
400
409
                // Construct a digester to read the XML input file
410
                Digester digester = new Digester();
411
                try {
412
                    digester.setFeature(
413
                            "http://apache.org/xml/features/allow-java-encodings",
414
                            true);
415
                } catch (Exception e) {
416
                    log.warn(sm.getString("memoryUserDatabase.xmlFeatureEncoding"), e);
417
                }
418
                digester.addFactoryCreate
419
                    ("tomcat-users/group",
420
                     new MemoryGroupCreationFactory(this), true);
421
                digester.addFactoryCreate
422
                    ("tomcat-users/role",
423
                     new MemoryRoleCreationFactory(this), true);
424
                digester.addFactoryCreate
425
                    ("tomcat-users/user",
426
                     new MemoryUserCreationFactory(this), true);
427
428
                // Parse the XML input file to load this database
429
                FileInputStream fis = null;
430
                try {
401
                try {
431
                    fis =  new FileInputStream(file);
402
                    is = ConfigFileLoader.getInputStream(pathName);
432
                    digester.parse(fis);
403
404
                    // Construct a digester to read the XML input file
405
                    Digester digester = new Digester();
406
                    try {
407
                        digester.setFeature(
408
                                "http://apache.org/xml/features/allow-java-encodings",
409
                                true);
410
                    } catch (Exception e) {
411
                        log.warn(sm.getString("memoryUserDatabase.xmlFeatureEncoding"), e);
412
                    }
413
                    digester.addFactoryCreate
414
                            ("tomcat-users/group",
415
                                    new MemoryGroupCreationFactory(this), true);
416
                    digester.addFactoryCreate
417
                            ("tomcat-users/role",
418
                                    new MemoryRoleCreationFactory(this), true);
419
                    digester.addFactoryCreate
420
                            ("tomcat-users/user",
421
                                    new MemoryUserCreationFactory(this), true);
422
423
                    // Parse the XML input to load this database
424
                    digester.parse(is);
425
                } catch (IOException ioe) {
426
                    log.error(sm.getString("memoryUserDatabase.fileNotFound", pathName));
433
                } finally {
427
                } finally {
434
                    if (fis != null) {
428
                    if (is != null) {
435
                        try {
429
                        try {
436
                            fis.close();
430
                            is.close();
437
                        } catch (IOException ioe) {
431
                        } catch (IOException ioe) {
438
                            // Ignore
432
                            // Ignore
439
                        }
433
                        }
440
                    }
434
                    }
441
                }
435
                }
442
443
            }
436
            }
444
        }
437
        }
445
438
(-)java/org/apache/naming/resources/ClasspathURLStreamHandler.java (+50 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.naming.resources;
18
19
import java.io.FileNotFoundException;
20
import java.io.IOException;
21
import java.net.URL;
22
import java.net.URLConnection;
23
import java.net.URLStreamHandler;
24
25
import org.apache.tomcat.util.res.StringManager;
26
27
public class ClasspathURLStreamHandler extends URLStreamHandler {
28
29
    private static final StringManager sm =
30
            StringManager.getManager(Constants.Package);
31
32
33
    @Override
34
    protected URLConnection openConnection(URL u) throws IOException {
35
        String path = u.getPath();
36
37
        // Thread context class loader first
38
        URL classpathUrl = Thread.currentThread().getContextClassLoader().getResource(path);
39
        if (classpathUrl == null) {
40
            // This class's class loader if no joy with the tccl
41
            classpathUrl = ClasspathURLStreamHandler.class.getResource(path);
42
        }
43
44
        if (classpathUrl == null) {
45
            throw new FileNotFoundException(sm.getString("classpathUrlStreamHandler.notFound", u));
46
        }
47
48
        return classpathUrl.openConnection();
49
    }
50
}
(-)java/org/apache/naming/resources/DirContextURLStreamHandlerFactory.java (-80 lines)
Lines 1-80 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */ 
17
18
package org.apache.naming.resources;
19
20
import java.net.URLStreamHandler;
21
import java.net.URLStreamHandlerFactory;
22
import java.util.List;
23
import java.util.concurrent.CopyOnWriteArrayList;
24
25
/**
26
 * Factory for Stream handlers to a JNDI directory context that also supports
27
 * users specifying additional stream handler.
28
 * 
29
 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
30
 */
31
public class DirContextURLStreamHandlerFactory
32
        implements URLStreamHandlerFactory {
33
    
34
    // Singleton
35
    private static DirContextURLStreamHandlerFactory instance =
36
        new DirContextURLStreamHandlerFactory();
37
38
    public static DirContextURLStreamHandlerFactory getInstance() {
39
        return instance;
40
    }
41
42
    public static void addUserFactory(URLStreamHandlerFactory factory) {
43
        instance.userFactories.add(factory);
44
    }
45
46
47
    private List<URLStreamHandlerFactory> userFactories =
48
        new CopyOnWriteArrayList<URLStreamHandlerFactory>();
49
50
    private DirContextURLStreamHandlerFactory() {
51
        // Hide the default constructor
52
    }
53
    
54
    
55
    /**
56
     * Creates a new URLStreamHandler instance with the specified protocol.
57
     * Will return null if the protocol is not <code>jndi</code>.
58
     * 
59
     * @param protocol the protocol (must be "jndi" here)
60
     * @return a URLStreamHandler for the jndi protocol, or null if the 
61
     * protocol is not JNDI
62
     */
63
    @Override
64
    public URLStreamHandler createURLStreamHandler(String protocol) {
65
        if (protocol.equals("jndi")) {
66
            return new DirContextURLStreamHandler();
67
        } else {
68
            for (URLStreamHandlerFactory factory : userFactories) {
69
                URLStreamHandler handler =
70
                    factory.createURLStreamHandler(protocol);
71
                if (handler != null) {
72
                    return handler;
73
                }
74
            }
75
            return null;
76
        }
77
    }
78
    
79
    
80
}
(-)java/org/apache/naming/resources/LocalStrings.properties (+1 lines)
Lines 43-45 standardResources.exists=File base {0} does not exist Link Here
43
standardResources.notStarted=Resources has not yet been started
43
standardResources.notStarted=Resources has not yet been started
44
standardResources.null=Document base cannot be null
44
standardResources.null=Document base cannot be null
45
standardResources.slash=Document base {0} must not end with a slash
45
standardResources.slash=Document base {0} must not end with a slash
46
classpathUrlStreamHandler.notFound=Unable to load the resource [{0}] using the thread context class loader or the current class's class loader
(-)java/org/apache/naming/resources/TomcatURLStreamHandlerFactory.java (+83 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */ 
17
18
package org.apache.naming.resources;
19
20
import java.net.URLStreamHandler;
21
import java.net.URLStreamHandlerFactory;
22
import java.util.List;
23
import java.util.concurrent.CopyOnWriteArrayList;
24
25
/**
26
 * Factory for Stream handlers to a JNDI directory context,
27
 * or for Stream handlers to a classpath url,
28
 * which also supports users specifying additional stream handler.
29
 * 
30
 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
31
 */
32
public class TomcatURLStreamHandlerFactory
33
        implements URLStreamHandlerFactory {
34
    
35
    // Singleton
36
    private static TomcatURLStreamHandlerFactory instance =
37
        new TomcatURLStreamHandlerFactory();
38
39
    public static TomcatURLStreamHandlerFactory getInstance() {
40
        return instance;
41
    }
42
43
    public static void addUserFactory(URLStreamHandlerFactory factory) {
44
        instance.userFactories.add(factory);
45
    }
46
47
48
    private List<URLStreamHandlerFactory> userFactories =
49
        new CopyOnWriteArrayList<URLStreamHandlerFactory>();
50
51
    private TomcatURLStreamHandlerFactory() {
52
        // Hide the default constructor
53
    }
54
    
55
    
56
    /**
57
     * Creates a new URLStreamHandler instance with the specified protocol.
58
     * Will return null if the protocol is not <code>jndi</code>.
59
     * 
60
     * @param protocol the protocol (must be "jndi" here)
61
     * @return a URLStreamHandler for the jndi protocol, or null if the 
62
     * protocol is not JNDI
63
     */
64
    @Override
65
    public URLStreamHandler createURLStreamHandler(String protocol) {
66
        if (protocol.equals("jndi")) {
67
            return new DirContextURLStreamHandler();
68
        } else if (protocol.equals("classpath")) {
69
            return new ClasspathURLStreamHandler();
70
        } else {
71
            for (URLStreamHandlerFactory factory : userFactories) {
72
                URLStreamHandler handler =
73
                    factory.createURLStreamHandler(protocol);
74
                if (handler != null) {
75
                    return handler;
76
                }
77
            }
78
            return null;
79
        }
80
    }
81
    
82
    
83
}
(-)java/org/apache/tomcat/util/file/ConfigFileLoader.java (+68 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
package org.apache.tomcat.util.file;
19
20
import java.io.File;
21
import java.io.IOException;
22
import java.io.InputStream;
23
import java.net.URI;
24
import java.net.URL;
25
26
/**
27
 * This class is used to obtain {@link InputStream}s for configuration files
28
 * from a given location String. This allows greater flexibility than these
29
 * files having to be loaded directly from a file system.
30
 */
31
public class ConfigFileLoader {
32
33
    private static final URI CATALINA_BASE_URI;
34
35
    static {
36
        File catalinaBase = new File(System.getProperty("catalina.base"));
37
        CATALINA_BASE_URI = catalinaBase.toURI();
38
    }
39
40
    private ConfigFileLoader() {
41
        // Utility class. Hide the default constructor.
42
    }
43
44
45
    /**
46
     * Load the resource from the specified location.
47
     *
48
     * @param location The location for the resource of interest. The location
49
     *                 may be a URL or a file path. Relative paths will be
50
     *                 resolved against CATALINA_BASE.
51
     *
52
     * @return The InputStream for the given resource. The caller is responsible
53
     *         for closing this stream when it is no longer used.
54
     *
55
     * @throws IOException If an InputStream cannot be created using the
56
     *                     provided location
57
     */
58
    public static InputStream getInputStream(String location) throws IOException {
59
60
        // Absolute URIs will be left alone
61
        // Relative files will be resolved relative to catalina base
62
        // Absolute files will be converted to URIs
63
        URI uri = CATALINA_BASE_URI.resolve(location);
64
        URL url = uri.toURL();
65
66
        return url.openConnection().getInputStream();
67
    }
68
}
(-)java/org/apache/tomcat/util/net/AbstractEndpoint.java (-24 / +2 lines)
Lines 16-22 Link Here
16
 */
16
 */
17
package org.apache.tomcat.util.net;
17
package org.apache.tomcat.util.net;
18
18
19
import java.io.File;
20
import java.io.OutputStreamWriter;
19
import java.io.OutputStreamWriter;
21
import java.net.InetAddress;
20
import java.net.InetAddress;
22
import java.net.InetSocketAddress;
21
import java.net.InetSocketAddress;
Lines 728-752 public abstract class AbstractEndpoint<S> { Link Here
728
        }
727
        }
729
    }
728
    }
730
729
731
732
    public String adjustRelativePath(String path, String relativeTo) {
733
        // Empty or null path can't point to anything useful. The assumption is
734
        // that the value is deliberately empty / null so leave it that way.
735
        if (path == null || path.length() == 0) {
736
            return path;
737
        }
738
        String newPath = path;
739
        File f = new File(newPath);
740
        if ( !f.isAbsolute()) {
741
            newPath = relativeTo + File.separator + newPath;
742
            f = new File(newPath);
743
        }
744
        if (!f.exists()) {
745
            getLog().warn("configured file:["+newPath+"] does not exist.");
746
        }
747
        return newPath;
748
    }
749
750
    protected abstract Log getLog();
730
    protected abstract Log getLog();
751
    // Flags to indicate optional feature support
731
    // Flags to indicate optional feature support
752
    // Some of these are always hard-coded, some are hard-coded to false (i.e.
732
    // Some of these are always hard-coded, some are hard-coded to false (i.e.
Lines 833-840 public abstract class AbstractEndpoint<S> { Link Here
833
    private String keystoreFile = System.getProperty("user.home")+"/.keystore";
813
    private String keystoreFile = System.getProperty("user.home")+"/.keystore";
834
    public String getKeystoreFile() { return keystoreFile;}
814
    public String getKeystoreFile() { return keystoreFile;}
835
    public void setKeystoreFile(String s ) {
815
    public void setKeystoreFile(String s ) {
836
        keystoreFile = adjustRelativePath(s,
816
        keystoreFile = s;
837
                System.getProperty(Constants.CATALINA_BASE_PROP));
838
    }
817
    }
839
818
840
    private String keystorePass = null;
819
    private String keystorePass = null;
Lines 874-881 public abstract class AbstractEndpoint<S> { Link Here
874
    private String truststoreFile = System.getProperty("javax.net.ssl.trustStore");
853
    private String truststoreFile = System.getProperty("javax.net.ssl.trustStore");
875
    public String getTruststoreFile() {return truststoreFile;}
854
    public String getTruststoreFile() {return truststoreFile;}
876
    public void setTruststoreFile(String s) {
855
    public void setTruststoreFile(String s) {
877
        truststoreFile = adjustRelativePath(s,
856
        truststoreFile = s;
878
                System.getProperty(Constants.CATALINA_BASE_PROP));
879
    }
857
    }
880
858
881
    private String truststorePass =
859
    private String truststorePass =
(-)java/org/apache/tomcat/util/net/jsse/JSSESocketFactory.java (-14 / +3 lines)
Lines 17-24 Link Here
17
17
18
package org.apache.tomcat.util.net.jsse;
18
package org.apache.tomcat.util.net.jsse;
19
19
20
import java.io.File;
21
import java.io.FileInputStream;
22
import java.io.FileNotFoundException;
20
import java.io.FileNotFoundException;
23
import java.io.IOException;
21
import java.io.IOException;
24
import java.io.InputStream;
22
import java.io.InputStream;
Lines 63-68 import javax.net.ssl.X509KeyManager; Link Here
63
61
64
import org.apache.tomcat.util.compat.JreCompat;
62
import org.apache.tomcat.util.compat.JreCompat;
65
import org.apache.tomcat.util.compat.JreVendor;
63
import org.apache.tomcat.util.compat.JreVendor;
64
import org.apache.tomcat.util.file.ConfigFileLoader;
66
import org.apache.tomcat.util.net.AbstractEndpoint;
65
import org.apache.tomcat.util.net.AbstractEndpoint;
67
import org.apache.tomcat.util.net.Constants;
66
import org.apache.tomcat.util.net.Constants;
68
import org.apache.tomcat.util.net.SSLUtil;
67
import org.apache.tomcat.util.net.SSLUtil;
Lines 431-442 public class JSSESocketFactory implements ServerSocketFactory, SSLUtil { Link Here
431
            }
430
            }
432
            if(!("PKCS11".equalsIgnoreCase(type) ||
431
            if(!("PKCS11".equalsIgnoreCase(type) ||
433
                    "".equalsIgnoreCase(path))) {
432
                    "".equalsIgnoreCase(path))) {
434
                File keyStoreFile = new File(path);
433
                istream = ConfigFileLoader.getInputStream(path);
435
                if (!keyStoreFile.isAbsolute()) {
436
                    keyStoreFile = new File(System.getProperty(
437
                            Constants.CATALINA_BASE_PROP), path);
438
                }
439
                istream = new FileInputStream(keyStoreFile);
440
            }
434
            }
441
435
442
            char[] storePass = null;
436
            char[] storePass = null;
Lines 718-733 public class JSSESocketFactory implements ServerSocketFactory, SSLUtil { Link Here
718
    protected Collection<? extends CRL> getCRLs(String crlf)
712
    protected Collection<? extends CRL> getCRLs(String crlf)
719
        throws IOException, CRLException, CertificateException {
713
        throws IOException, CRLException, CertificateException {
720
714
721
        File crlFile = new File(crlf);
722
        if( !crlFile.isAbsolute() ) {
723
            crlFile = new File(
724
                    System.getProperty(Constants.CATALINA_BASE_PROP), crlf);
725
        }
726
        Collection<? extends CRL> crls = null;
715
        Collection<? extends CRL> crls = null;
727
        InputStream is = null;
716
        InputStream is = null;
728
        try {
717
        try {
729
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
718
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
730
            is = new FileInputStream(crlFile);
719
            is = ConfigFileLoader.getInputStream(crlf);
731
            crls = cf.generateCRLs(is);
720
            crls = cf.generateCRLs(is);
732
        } catch(IOException iex) {
721
        } catch(IOException iex) {
733
            throw iex;
722
            throw iex;
(-)test/org/apache/naming/resources/TestClasspathUrlStreamHandler.java (+44 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.naming.resources;
18
19
import java.io.IOException;
20
import java.io.InputStream;
21
import java.net.URL;
22
import java.util.Properties;
23
24
import org.junit.Assert;
25
import org.junit.BeforeClass;
26
import org.junit.Test;
27
28
public class TestClasspathUrlStreamHandler {
29
30
    @BeforeClass
31
    public static void setup() {
32
        URL.setURLStreamHandlerFactory(TomcatURLStreamHandlerFactory.getInstance());
33
    }
34
35
    @Test
36
    public void testClasspathURL01() throws IOException {
37
        URL u = new URL("classpath:/org/apache/naming/resources/LocalStrings.properties");
38
        InputStream is = u.openStream();
39
        Properties p = new Properties();
40
        p.load(is);
41
        String msg = (String) p.get("resources.null");
42
        Assert.assertEquals("Document base cannot be null",  msg);
43
    }
44
}
(-)test/org/apache/naming/resources/TestDirContextURLStreamHandlerFactory.java (-82 lines)
Lines 1-82 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.naming.resources;
18
19
import java.net.MalformedURLException;
20
import java.net.URL;
21
import java.net.URLStreamHandler;
22
import java.net.URLStreamHandlerFactory;
23
24
import static org.junit.Assert.assertNotNull;
25
import static org.junit.Assert.assertNull;
26
27
import org.junit.Test;
28
29
public class TestDirContextURLStreamHandlerFactory {
30
31
    @Test
32
    public void testUserSuppliedFactory() throws Exception {
33
34
        URL url = null;
35
36
        // Initially unknown
37
        try {
38
            url = new URL("foo://www.apache.org");
39
        } catch (MalformedURLException ignore) {
40
            // Ignore
41
        }
42
        assertNull(url);
43
44
        // Set the factory
45
        URL.setURLStreamHandlerFactory(
46
                DirContextURLStreamHandlerFactory.getInstance());
47
48
        // Still unknown
49
        try {
50
            url = new URL("foo://www.apache.org");
51
        } catch (MalformedURLException ignore) {
52
            // Ignore
53
        }
54
        assertNull(url);
55
56
        // Register a user factory
57
        DirContextURLStreamHandlerFactory.addUserFactory(
58
                new FooURLStreamHandlerFactory());
59
60
        // Now it works
61
        try {
62
            url = new URL("foo://www.apache.org");
63
        } catch (MalformedURLException ignore) {
64
            // Ignore
65
        }
66
        assertNotNull(url);
67
    }
68
69
    public static class FooURLStreamHandlerFactory
70
            implements URLStreamHandlerFactory {
71
72
        @Override
73
        public URLStreamHandler createURLStreamHandler(String protocol) {
74
            if ("foo".equals(protocol)) {
75
                // This is good enough for this test but not for actual use
76
                return new DirContextURLStreamHandler();
77
            } else {
78
                return null;
79
            }
80
        }
81
    }
82
}
(-)test/org/apache/naming/resources/TestTomcatURLStreamHandlerFactory.java (+82 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.naming.resources;
18
19
import java.net.MalformedURLException;
20
import java.net.URL;
21
import java.net.URLStreamHandler;
22
import java.net.URLStreamHandlerFactory;
23
24
import static org.junit.Assert.assertNotNull;
25
import static org.junit.Assert.assertNull;
26
27
import org.junit.Test;
28
29
public class TestTomcatURLStreamHandlerFactory {
30
31
    @Test
32
    public void testUserSuppliedFactory() throws Exception {
33
34
        URL url = null;
35
36
        // Initially unknown
37
        try {
38
            url = new URL("foo://www.apache.org");
39
        } catch (MalformedURLException ignore) {
40
            // Ignore
41
        }
42
        assertNull(url);
43
44
        // Set the factory
45
        URL.setURLStreamHandlerFactory(
46
                TomcatURLStreamHandlerFactory.getInstance());
47
48
        // Still unknown
49
        try {
50
            url = new URL("foo://www.apache.org");
51
        } catch (MalformedURLException ignore) {
52
            // Ignore
53
        }
54
        assertNull(url);
55
56
        // Register a user factory
57
        TomcatURLStreamHandlerFactory.addUserFactory(
58
                new FooURLStreamHandlerFactory());
59
60
        // Now it works
61
        try {
62
            url = new URL("foo://www.apache.org");
63
        } catch (MalformedURLException ignore) {
64
            // Ignore
65
        }
66
        assertNotNull(url);
67
    }
68
69
    public static class FooURLStreamHandlerFactory
70
            implements URLStreamHandlerFactory {
71
72
        @Override
73
        public URLStreamHandler createURLStreamHandler(String protocol) {
74
            if ("foo".equals(protocol)) {
75
                // This is good enough for this test but not for actual use
76
                return new DirContextURLStreamHandler();
77
            } else {
78
                return null;
79
            }
80
        }
81
    }
82
}
(-)test/org/apache/tomcat/util/file/TestConfigFileLoader.java (+73 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
package org.apache.tomcat.util.file;
19
20
import java.io.File;
21
import java.io.FileNotFoundException;
22
import java.io.IOException;
23
import java.io.InputStream;
24
import java.net.URL;
25
26
import org.apache.naming.resources.TomcatURLStreamHandlerFactory;
27
import org.junit.Assert;
28
import org.junit.BeforeClass;
29
import org.junit.Test;
30
31
public class TestConfigFileLoader {
32
33
    @BeforeClass
34
    public static void setup() {
35
        URL.setURLStreamHandlerFactory(
36
                TomcatURLStreamHandlerFactory.getInstance());
37
        File buildDir = new File(
38
                System.getProperty("tomcat.test.tomcatbuild", "output/build"));
39
        System.setProperty("catalina.base", buildDir.getAbsolutePath());
40
    }
41
42
    @Test
43
    public void test01() throws IOException {
44
        doTest("classpath:org/apache/catalina/mbeans-descriptors.xml");
45
    }
46
47
    @Test(expected=FileNotFoundException.class)
48
    public void test02() throws IOException {
49
        doTest("classpath:org/apache/catalina/foo");
50
    }
51
52
    @Test
53
    public void test03() throws IOException {
54
        doTest("conf/server.xml");
55
    }
56
57
    @Test(expected=FileNotFoundException.class)
58
    public void test04() throws IOException {
59
        doTest("conf/unknown");
60
    }
61
62
    private void doTest(String path) throws IOException {
63
        InputStream is = null;
64
        try {
65
            is = ConfigFileLoader.getInputStream(path);
66
            Assert.assertNotNull(is);
67
        } finally {
68
            if (is != null) {
69
                is.close();
70
            }
71
        }
72
    }
73
}
(-)webapps/docs/config/http.xml (-3 / +6 lines)
Lines 1017-1023 Link Here
1017
    <attribute name="crlFile" required="false">
1017
    <attribute name="crlFile" required="false">
1018
      <p>The certificate revocation list to be used to verify client
1018
      <p>The certificate revocation list to be used to verify client
1019
      certificates. If not defined, client certificates will not be checked
1019
      certificates. If not defined, client certificates will not be checked
1020
      against a certificate revocation list.</p>
1020
      against a certificate revocation list. The file may be specified using a
1021
      URL, an absolute path or a relative (to CATAINA_BASE) path.</p>
1021
    </attribute>
1022
    </attribute>
1022
1023
1023
    <attribute name="keyAlias" required="false">
1024
    <attribute name="keyAlias" required="false">
Lines 1042-1048 Link Here
1042
      the file "<code>.keystore</code>" in the operating system home
1043
      the file "<code>.keystore</code>" in the operating system home
1043
      directory of the user that is running Tomcat. If your
1044
      directory of the user that is running Tomcat. If your
1044
      <code>keystoreType</code> doesn't need a file use <code>""</code>
1045
      <code>keystoreType</code> doesn't need a file use <code>""</code>
1045
      (empty string) for this parameter.</p>
1046
      (empty string) for this parameter. The file may be specified using a
1047
      URL, an absolute path or a relative (to CATAINA_BASE) path.</p>
1046
    </attribute>
1048
    </attribute>
1047
1049
1048
    <attribute name="keystorePass" required="false">
1050
    <attribute name="keystorePass" required="false">
Lines 1136-1142 Link Here
1136
      <p>The trust store file to use to validate client certificates. The
1138
      <p>The trust store file to use to validate client certificates. The
1137
      default is the value of the <code>javax.net.ssl.trustStore</code> system
1139
      default is the value of the <code>javax.net.ssl.trustStore</code> system
1138
      property. If neither this attribute nor the default system property is
1140
      property. If neither this attribute nor the default system property is
1139
      set, no trust store will be configured.</p>
1141
      set, no trust store will be configured. The file may be specified using a
1142
      URL, an absolute path or a relative (to CATAINA_BASE) path.</p>
1140
    </attribute>
1143
    </attribute>
1141
1144
1142
    <attribute name="truststorePass" required="false">
1145
    <attribute name="truststorePass" required="false">
(-)webapps/docs/config/realm.xml (-2 / +2 lines)
Lines 811-818 Link Here
811
      </attribute>
811
      </attribute>
812
812
813
      <attribute name="pathname" required="false">
813
      <attribute name="pathname" required="false">
814
        <p>Absolute or relative (to $CATALINA_BASE) pathname to the XML file
814
        <p>URL, absolute path or relative path (to $CATALINA_BASE) for the XML
815
        containing our user information.  See below for details on the
815
        file containing our user information.  See below for details on the
816
        XML element format required.  If no pathname is specified, the
816
        XML element format required.  If no pathname is specified, the
817
        default value is <code>conf/tomcat-users.xml</code>.</p>
817
        default value is <code>conf/tomcat-users.xml</code>.</p>
818
      </attribute>
818
      </attribute>
(-)webapps/docs/jndi-resources-howto.xml (-2 / +3 lines)
Lines 471-478 public class MyBean2 { Link Here
471
          pathname="conf/tomcat-users.xml"
471
          pathname="conf/tomcat-users.xml"
472
          readonly="false" />]]></source>
472
          readonly="false" />]]></source>
473
473
474
    <p>The <code>pathname</code> attribute can be absolute or relative. If
474
    <p>The <code>pathname</code> attribute can be a URL, an absolute path or a
475
    relative, it is relative to <code>$CATALINA_BASE</code>.</p>
475
    relative path. If relative, it is relative to <code>$CATALINA_BASE</code>.
476
    </p>
476
477
477
    <p>The <code>readonly</code> attribute is optional and defaults to
478
    <p>The <code>readonly</code> attribute is optional and defaults to
478
    <code>true</code> if not supplied. If the XML is writeable then it will be
479
    <code>true</code> if not supplied. If the XML is writeable then it will be

Return to bug 56777