Class Utilities.EffectiveOriginResolver
- Enclosing class:
Utilities
Utilities.extractEffectiveOrigin(EffectiveOriginResolver).
Packages the inputs needed to reconstruct a client origin (scheme + host + optional port) from request headers. The resulting value never includes a path or query component.
Forwarded headers can be spoofed if Soklet is reachable directly. Choose a Utilities.EffectiveOriginResolver.TrustPolicy that matches your
deployment and, for Utilities.EffectiveOriginResolver.TrustPolicy.TRUST_PROXY_ALLOWLIST, provide a trusted proxy predicate or allowlist.
If the remote address is missing or not trusted, forwarded headers are ignored.
Extraction order is: trusted forwarded headers → Host → (optional) Origin fallback. Origin
never overrides a conflicting host value; it only fills missing scheme/port or supplies host when absent.
Defaults: if allowOriginFallback(Boolean) is left unset, Origin fallback is enabled only for
Utilities.EffectiveOriginResolver.TrustPolicy.TRUST_ALL; otherwise it is disabled.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumForwarded header trust policy. -
Method Summary
Modifier and TypeMethodDescriptionallowOriginFallback(@Nullable Boolean allowOriginFallback) Controls whetherOriginis used as a fallback signal when determining the client URL prefix.remoteAddress(@Nullable InetSocketAddress remoteAddress) The remote address of the client connection.trustedProxyAddresses(@NonNull Set<@NonNull InetAddress> trustedProxyAddresses) Allows specifying an IP allowlist for trusted proxies.trustedProxyPredicate(@Nullable Predicate<InetSocketAddress> trustedProxyPredicate) Predicate used whenUtilities.EffectiveOriginResolver.TrustPolicy.TRUST_PROXY_ALLOWLISTis in effect.withHeaders(@NonNull Map<@NonNull String, @NonNull Set<@NonNull String>> headers, @NonNull Utilities.EffectiveOriginResolver.TrustPolicy trustPolicy) Acquires a builder seeded with raw request headers and a trust policy.withRequest(@NonNull Request request, @NonNull Utilities.EffectiveOriginResolver.TrustPolicy trustPolicy) Acquires a builder seeded with aRequestand a trust policy.
-
Method Details
-
withHeaders
public static @NonNull Utilities.EffectiveOriginResolver withHeaders(@NonNull Map<@NonNull String, @NonNull Set<@NonNull String>> headers, @NonNull Utilities.EffectiveOriginResolver.TrustPolicy trustPolicy) Acquires a builder seeded with raw request headers and a trust policy.- Parameters:
headers- HTTP request headerstrustPolicy- how forwarded headers should be trusted- Returns:
- the builder
-
withRequest
public static @NonNull Utilities.EffectiveOriginResolver withRequest(@NonNull Request request, @NonNull Utilities.EffectiveOriginResolver.TrustPolicy trustPolicy) Acquires a builder seeded with aRequestand a trust policy.- Parameters:
request- the current requesttrustPolicy- how forwarded headers should be trusted- Returns:
- the builder
-
remoteAddress
public @NonNull Utilities.EffectiveOriginResolver remoteAddress(@Nullable InetSocketAddress remoteAddress) The remote address of the client connection.- Parameters:
remoteAddress- the remote address, ornullif unavailable- Returns:
- this builder
-
trustedProxyPredicate
public @NonNull Utilities.EffectiveOriginResolver trustedProxyPredicate(@Nullable Predicate<InetSocketAddress> trustedProxyPredicate) Predicate used whenUtilities.EffectiveOriginResolver.TrustPolicy.TRUST_PROXY_ALLOWLISTis in effect.- Parameters:
trustedProxyPredicate- predicate that returnstruefor trusted proxies- Returns:
- this builder
-
trustedProxyAddresses
public @NonNull Utilities.EffectiveOriginResolver trustedProxyAddresses(@NonNull Set<@NonNull InetAddress> trustedProxyAddresses) Allows specifying an IP allowlist for trusted proxies.- Parameters:
trustedProxyAddresses- IP addresses of trusted proxies- Returns:
- this builder
-
allowOriginFallback
public @NonNull Utilities.EffectiveOriginResolver allowOriginFallback(@Nullable Boolean allowOriginFallback) Controls whetherOriginis used as a fallback signal when determining the client URL prefix.- Parameters:
allowOriginFallback-trueto allowOriginfallback,falseto disable it- Returns:
- this builder
-