public class PacUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
PRECOMPILED_GLOB_CACHE_MAX_ITEMS
Size of the cache used for precompiled GLOBs.
|
Constructor and Description |
---|
PacUtils() |
Modifier and Type | Method and Description |
---|---|
static Pattern |
createRegexPatternFromGlob(String glob)
Translate a GLOB pattern into a RegExp pattern.
|
static boolean |
ipPrefixMatch(InetAddress ipAddress,
String ipPrefix)
Checks if an IP address matches a given CIDR pattern.
|
static <T> String |
toSemiColonList(List<T> list)
Converts list into semi-colon separated string where each element
is represented by the result of
Object.toString() . |
static <T> String |
toSemiColonList(List<T> list,
java.util.function.Function<T,String> fn)
Converts list into semi-colon separated string where each element
is represented by the result of the
fn function. |
static String |
toSemiColonListInetAddress(InetAddress[] addresses)
Converts a list of
InetAddress into a semi-colon
separated string. |
static String |
toSemiColonListInetAddress(List<InetAddress> addresses)
Converts an array of
InetAddress into a semi-colon
separated string. |
static String |
toStrippedURLStr(URI uri)
Cleans a URI into a format suitable for passing to the PAC script.
|
public static final int PRECOMPILED_GLOB_CACHE_MAX_ITEMS
public static Pattern createRegexPatternFromGlob(String glob)
This method supports all GLOB wildcards, such as
* | matches any number of any characters including none |
? | matches any single character |
[abc] | matches one character given in the bracket |
[a-z] | matches one character from the range given in the bracket |
[!abc] | matches one character not given in the bracket |
[!a-z] | matches one character not from the range given in the bracket |
A small cache is used so that if a glob pattern has already been translated previously, the result from the cache will be returned.
glob
- public static <T> String toSemiColonList(List<T> list, java.util.function.Function<T,String> fn)
fn
function.T
- list
- list of objectsfn
- function which returns stringpublic static <T> String toSemiColonList(List<T> list)
Object.toString()
.T
- list
- list of objectsPacUtils.toSemiColonList(java.util.List, java.util.function.Function)
public static String toSemiColonListInetAddress(InetAddress[] addresses)
InetAddress
into a semi-colon
separated string. Each address is represented by the result
of InetAddress.getHostAddress()
.addresses
- PacUtils.toSemiColonList(java.util.List, java.util.function.Function)
public static String toSemiColonListInetAddress(List<InetAddress> addresses)
InetAddress
into a semi-colon
separated string. Each address is represented by the result
of InetAddress.getHostAddress()
.addresses
- PacUtils.toSemiColonList(java.util.List, java.util.function.Function)
public static boolean ipPrefixMatch(InetAddress ipAddress, String ipPrefix)
ipLiteral/bitFieldExamples of valid patterns:
198.95.249.79/32 198.95.0.0/16 3ffe:8311:ffff/48
For IPv6 the ipLiteral
is allowed to be incomplete at the end. If
not complete, then a suffix of "::" is appended to the literal, e.g. the
method will translate "3ffe:8311:ffff/48"
to
"3ffe:8311:ffff::/48"
.
A number of validation checks are carried out on the ipPrefix
argument and false
will be returned if these checks fails:
ipAddress
is IPv4 then bitField
must be between 8 and 32.
ipAddress
is IPv6 then bitField
must be between 8 and 128.
ipLiteral
value must be a valid IPv4 literal or IPv6 literal.
ipLiteral
value must match the IP protocol
type of ipAddress
.
Note: The method was developed for the purpose of supporting the
Microsoft isInNetEx()
extension to PAC scripting, but the method may
have an appeal broader than this particular use case.
ipAddress
- addressipPrefix
- patternipAddress
, match the pattern, ipPrefix
.public static String toStrippedURLStr(URI uri)
url
argument to
FindProxyForURL(url, host)
or FindProxyForURLEx(url, host)
functions).
Because a PAC script is downloaded from a potentially malicious source it may contain harmful code. Therefore, the amount of information passed to the script should be limited to what is strictly necessary for the script to make decisions about choice of proxy. Anything in the URL which can potentially identity the user or which may contain session specific information should be removed before passing to script.
The following is removed:
user-info
path
and everything that follows afterExample:
https://mary@netbeans.apache.org:8081/path/to/something?x1=Christmas&user=unknown becomes https://netbeans.apache.org:8081/
Note that the majority of PAC scripts out there do not make use of the
url
parameter at all. Instead they only use the host
parameter. The stripping of information means that the url
parameter only has two pieces of information that the host
parameter doesn't have: protocol and port number.
uri
- URL to be cleansed