< prev index next >

src/java.base/share/classes/sun/net/spi/DefaultProxySelector.java

Print this page
rev 55657 : 8227587: Add internal privileged System.loadLibrary
Reviewed-by: rriggs
   1 /*
   2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  81         {"http", "http.proxy", "proxy", "socksProxy"},
  82         {"https", "https.proxy", "proxy", "socksProxy"},
  83         {"ftp", "ftp.proxy", "ftpProxy", "proxy", "socksProxy"},
  84         {"socket", "socksProxy"}
  85     };
  86 
  87     private static final String SOCKS_PROXY_VERSION = "socksProxyVersion";
  88 
  89     private static boolean hasSystemProxies = false;
  90 
  91     private static final List<Proxy> NO_PROXY_LIST = List.of(Proxy.NO_PROXY);
  92 
  93     static {
  94         final String key = "java.net.useSystemProxies";
  95         Boolean b = AccessController.doPrivileged(
  96             new PrivilegedAction<Boolean>() {
  97                 public Boolean run() {
  98                     return NetProperties.getBoolean(key);
  99                 }});
 100         if (b != null && b.booleanValue()) {
 101             java.security.AccessController.doPrivileged(
 102                 new java.security.PrivilegedAction<Void>() {
 103                     public Void run() {
 104                         System.loadLibrary("net");
 105                         return null;
 106                     }
 107                 });
 108             hasSystemProxies = init();
 109         }
 110     }
 111 
 112     public static int socksProxyVersion() {
 113         return AccessController.doPrivileged(
 114                 new PrivilegedAction<Integer>() {
 115                     @Override public Integer run() {
 116                         return NetProperties.getInteger(SOCKS_PROXY_VERSION, 5);
 117                     }
 118                 });
 119     }
 120 
 121     /**
 122      * How to deal with "non proxy hosts":
 123      * since we do have to generate a pattern we don't want to do that if
 124      * it's not necessary. Therefore we do cache the result, on a per-protocol
 125      * basis, and change it only when the "source", i.e. the system property,
 126      * did change.
 127      */


   1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  81         {"http", "http.proxy", "proxy", "socksProxy"},
  82         {"https", "https.proxy", "proxy", "socksProxy"},
  83         {"ftp", "ftp.proxy", "ftpProxy", "proxy", "socksProxy"},
  84         {"socket", "socksProxy"}
  85     };
  86 
  87     private static final String SOCKS_PROXY_VERSION = "socksProxyVersion";
  88 
  89     private static boolean hasSystemProxies = false;
  90 
  91     private static final List<Proxy> NO_PROXY_LIST = List.of(Proxy.NO_PROXY);
  92 
  93     static {
  94         final String key = "java.net.useSystemProxies";
  95         Boolean b = AccessController.doPrivileged(
  96             new PrivilegedAction<Boolean>() {
  97                 public Boolean run() {
  98                     return NetProperties.getBoolean(key);
  99                 }});
 100         if (b != null && b.booleanValue()) {
 101             jdk.internal.access.SharedSecrets.getJavaLangAccess().loadLibrary("net");






 102             hasSystemProxies = init();
 103         }
 104     }
 105 
 106     public static int socksProxyVersion() {
 107         return AccessController.doPrivileged(
 108                 new PrivilegedAction<Integer>() {
 109                     @Override public Integer run() {
 110                         return NetProperties.getInteger(SOCKS_PROXY_VERSION, 5);
 111                     }
 112                 });
 113     }
 114 
 115     /**
 116      * How to deal with "non proxy hosts":
 117      * since we do have to generate a pattern we don't want to do that if
 118      * it's not necessary. Therefore we do cache the result, on a per-protocol
 119      * basis, and change it only when the "source", i.e. the system property,
 120      * did change.
 121      */


< prev index next >