Package com.jsgalactic.axiom.security
Interface RateLimitKey
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Chooses the key a request is counted under by
RateLimit: one budget per distinct key.
A key is text of 1 to 512 characters. It is built from facts the
server established (the transport peer, a trusted proxy's view, the verified identity), never
from a request header an attacker chooses freely; otherwise a client would pick a fresh key per
request and never be limited. RateLimit bounds how many keys it tracks, so a key function
that is flooded with new values evicts old entries instead of growing memory.
An empty or oversized result means the request has no usable key. RateLimit then
counts it under ANONYMOUS, one shared budget, so keyless requests are still limited.
Implementations are called concurrently and must be thread-safe and fast.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic RateLimitKeyclientAddress(TrustedProxies proxies) Keys by the client address resolved through trusted proxies: forwarding headers are believed only from configured proxies, as inTrustedProxies.resolve(com.jsgalactic.axiom.http.Request).Returns the key of the request.static RateLimitKeyKeys by the transport peer address (Request.remoteAddress()), ignoring every header.static RateLimitKeyprincipal(RateLimitKey anonymous) Keys by the authenticated principal, falling back to another function for anonymous requests.
-
Field Details
-
ANONYMOUS
The key of requests whose key function produced none.- See Also:
-
-
Method Details
-
key
Returns the key of the request.- Parameters:
context- request context- Returns:
- the key, or empty when this function has none
-
peerAddress
Keys by the transport peer address (Request.remoteAddress()), ignoring every header. This is the default ofRateLimit: it cannot be spoofed, but behind a reverse proxy every client shares the proxy's address; useclientAddress(TrustedProxies)there.- Returns:
- the peer-address key function
-
clientAddress
Keys by the client address resolved through trusted proxies: forwarding headers are believed only from configured proxies, as inTrustedProxies.resolve(com.jsgalactic.axiom.http.Request).- Parameters:
proxies- the trusted proxy configuration- Returns:
- the client-address key function
-
principal
Keys by the authenticated principal, falling back to another function for anonymous requests. Place the authenticating middleware before the limiter.- Parameters:
anonymous- used when the request has no identity, typicallypeerAddress()- Returns:
- the principal key function
-