Record Class ProxyRoute
- Record Components:
kind- how to reach the networkhost- the proxy host, ornullforProxyRoute.Kind.DIRECTport- the proxy port, or0forProxyRoute.Kind.DIRECTusername- the proxy username, ornullwhen unauthenticatedpassword- the proxy password, ornullwhen unauthenticated
A route is deliberately not stored on an account. A proxy is infrastructure rather than account
identity, and — decisively — AltAccount travels into shared vault
repositories, so a route living there would publish a paid proxy's host, port, and credentials to
every member of every repository the alt is shared into.
Authenticated SOCKS5 is not supported. The JDK's SOCKS client reads credentials
from process-global state — the java.net.socks.* system properties, or the default
Authenticator — and a library that installs either has reached into its host's JVM to
do it. withCredentials(String, char[]) therefore throws on a SOCKS5 route rather than
silently connecting unauthenticated, which would send the request from an address the host did not
choose. Unauthenticated SOCKS5 works; front an authenticated one with a local HTTP proxy.
The password is held as a private copy: the array passed in and the array password()
returns are never the one stored, so neither a caller wiping its own array nor one scribbling on the
returned array changes the credential a route authenticates with.
- Since:
- 0.8.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionProxyRoute(ProxyRoute.Kind kind, String host, int port, String username, char[] password) Validates the shape, and refuses the credential combination the JDK cannot honour per-request. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether this route carries credentials.static ProxyRoutedirect()Returns the route meaning "no proxy".endpoint()Returns the source address this route presents to a service, as a stable key.booleanCompares routes by value, including the password's contents.inthashCode()Returns a hash consistent withequals(Object).host()Returns the value of thehostrecord component.static ProxyRouteCreates an unauthenticated HTTP proxy route.booleanisDirect()Returns whether this route reaches the network without a proxy.kind()Returns the value of thekindrecord component.char[]password()Returns a copy of the proxy password, so the caller cannot alter the stored credential.intport()Returns the value of theportrecord component.static ProxyRouteCreates an unauthenticated SOCKS5 proxy route.toString()Returns a description carrying no credential.username()Returns the value of theusernamerecord component.withCredentials(String username, char[] password) Returns a copy carrying proxy credentials.
-
Constructor Details
-
ProxyRoute
Validates the shape, and refuses the credential combination the JDK cannot honour per-request.- Since:
- 0.8.0
-
-
Method Details
-
password
public char[] password()Returns a copy of the proxy password, so the caller cannot alter the stored credential.- Returns:
- a fresh copy of the password, or
nullwhen unauthenticated - Since:
- 0.8.0
-
direct
Returns the route meaning "no proxy".- Returns:
- the direct route
- Since:
- 0.8.0
-
http
Creates an unauthenticated HTTP proxy route.- Parameters:
host- the proxy hostport- the proxy port- Returns:
- the route
- Since:
- 0.8.0
-
socks5
Creates an unauthenticated SOCKS5 proxy route.- Parameters:
host- the proxy hostport- the proxy port- Returns:
- the route
- Since:
- 0.8.0
-
withCredentials
Returns a copy carrying proxy credentials.- Parameters:
username- the proxy usernamepassword- the proxy password- Returns:
- a copy that authenticates
- Throws:
UnsupportedOperationException- if this is a SOCKS5 route — seeProxyRouteIllegalStateException- if this is the direct route, which authenticates against nothing- Since:
- 0.8.0
-
isDirect
public boolean isDirect()Returns whether this route reaches the network without a proxy.- Returns:
- true if direct
- Since:
- 0.8.0
-
authenticated
public boolean authenticated()Returns whether this route carries credentials.- Returns:
- true if a username is set
- Since:
- 0.8.0
-
endpoint
Returns the source address this route presents to a service, as a stable key. Value identity for a route is its endpoint rather than the whole record, because what a service rate-limits is the address, not the credential that reached it.- Returns:
- a key identifying the endpoint
- Since:
- 0.8.0
-
equals
Compares routes by value, including the password's contents. The generatedequalswould compare the password arrays by identity, so two routes built from the same credential would never be equal. -
hashCode
public int hashCode()Returns a hash consistent withequals(Object). -
toString
Returns a description carrying no credential. The generatedtoStringwould print the password array, and a host logging the route it chose would write a proxy credential to its log. The username is left out as well: rotating gateways encode the session and the customer in it. -
kind
-
host
-
port
-
username
-