Package org.apache.juneau.rest.client
Class RedirectSecurity
java.lang.Object
org.apache.juneau.rest.client.RedirectSecurity
Pure decision logic for whether caller-set credential headers (such as
Authorization
or Cookie) should be forwarded or stripped when a REST call is transparently replayed
against a redirect target (an HTTP 3xx response's Location).
This class contains only the decision — it does not itself intercept, follow, or rewrite any request. Each transport binding (classic, HttpClient-4.5/5.x, Jetty, OkHttp, the JDK client, etc.) is responsible for calling into this class from its own redirect hook and acting on the result.
The policy is intentionally simple and conservative:
- Credentials are forwarded only when the redirect target is the exact same origin
as the original request — same scheme, same host (case-insensitive), and same port
(after applying the standard default port for
http/https). - Credentials are stripped on any other origin change (different scheme, host, or port).
- Credentials are stripped on an
https→httpscheme downgrade, even in the (impossible under the same-origin rule above) case that host and port otherwise match.
Both from and to must be absolute URIs (non-null scheme and host);
callers are responsible for resolving a relative Location header against the original
request URI before calling into this class.
Example:
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe outcome of a credential-forwarding decision for a single redirect hop. -
Method Summary
Modifier and TypeMethodDescriptionDecides whether credentials should be forwarded or stripped for a single redirect hop.static booleanisDowngrade(URI from, URI to) Returnstrueif the redirect represents anhttps→httpscheme downgrade.static booleansameOrigin(URI from, URI to) Returnstrueiffromandtoshare the same origin — scheme, host (case-insensitive), and port (after default-port normalization forhttp/https).static booleanshouldStripCredentials(URI from, URI to) Convenience boolean form ofdecide(URI, URI).Returns the header names that must be stripped from a request before it is replayed cross-origin.
-
Method Details
-
sameOrigin
Returnstrueiffromandtoshare the same origin — scheme, host (case-insensitive), and port (after default-port normalization forhttp/https).- Parameters:
from- The original request URI. Must be absolute (non-nullscheme and host).to- The redirect target URI. Must be absolute (non-nullscheme and host).- Returns:
trueif both URIs resolve to the same origin.- Throws:
IllegalArgumentException- If either argument isnullor not an absolute URI.
-
isDowngrade
Returnstrueif the redirect represents anhttps→httpscheme downgrade.- Parameters:
from- The original request URI. Must be absolute (non-nullscheme and host).to- The redirect target URI. Must be absolute (non-nullscheme and host).- Returns:
trueiffromishttpsandtoishttp.- Throws:
IllegalArgumentException- If either argument isnullor not an absolute URI.
-
decide
Decides whether credentials should be forwarded or stripped for a single redirect hop.- Parameters:
from- The original request URI. Must be absolute (non-nullscheme and host).to- The redirect target URI. Must be absolute (non-nullscheme and host).- Returns:
RedirectSecurity.CredentialDecision.STRIPunlesstois the exact same origin asfrom(and not a scheme downgrade), in which caseRedirectSecurity.CredentialDecision.FORWARD.- Throws:
IllegalArgumentException- If either argument isnullor not an absolute URI.
-
shouldStripCredentials
Convenience boolean form ofdecide(URI, URI).- Parameters:
from- The original request URI. Must be absolute (non-nullscheme and host).to- The redirect target URI. Must be absolute (non-nullscheme and host).- Returns:
trueif credentials must be stripped before replaying the request againstto.- Throws:
IllegalArgumentException- If either argument isnullor not an absolute URI.
-
stripOnCrossOrigin
Returns the header names that must be stripped from a request before it is replayed cross-origin. Reuses the canonical credential-header set fromRedactedHeaders.DEFAULT.- Returns:
- The set of header names to strip on a cross-origin (or downgraded) redirect.
-