Module io.inverno.mod.security.http
Class CORSInterceptor<A extends io.inverno.mod.http.base.ExchangeContext,B extends Exchange<A>>
java.lang.Object
io.inverno.mod.security.http.cors.CORSInterceptor<A,B>
- Type Parameters:
A- the type of the exchange contextB- the type of exchange handled by the handler
- All Implemented Interfaces:
ExchangeInterceptor<A,B>
public class CORSInterceptor<A extends io.inverno.mod.http.base.ExchangeContext,B extends Exchange<A>>
extends Object
implements ExchangeInterceptor<A,B>
A security interceptor that implements Cross-origin resource sharing (CORS) as defined by HTTP CORS protocol.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA CORS interceptor builder.protected static classRepresents an origin composed of a scheme, a host and a port. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanFlag indicating whether credentials must be allowed.protected final StringThe allowed headers.protected final StringThe allowed methods.protected final Set<CORSInterceptor.Origin> The set of allowed origins.The set of allowed origins patterns.protected final booleanFlag indicating whether private netword must be allowed.protected final StringThe exposed headers.protected final booleanFlag indicating whether the interceptor is a static interceptor (allow one static origin).protected final booleanFlag indicating whether the interceptor is a wildcard interceptor (allow all origins).protected final IntegerThe max age in seconds for CORS information cache. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCORSInterceptor(Set<CORSInterceptor.Origin> allowedOrigins, Set<Pattern> allowedOriginsPattern, boolean allowCredentials, Set<String> allowedHeaders, Set<io.inverno.mod.http.base.Method> allowedMethods, Set<String> exposedHeaders, Integer maxAge, boolean allowPrivateNetwork) Creates a CORS interceptor. -
Method Summary
Modifier and TypeMethodDescriptionstatic CORSInterceptor.BuilderReturns a CORS interceptor builder for the specified allowed origins.protected voidcheckOrigin(CORSInterceptor.Origin origin) Determines whether the origin is a valid origin.reactor.core.publisher.Mono<? extends B> protected booleanisSameOrigin(B exchange, CORSInterceptor.Origin origin) Determines whether the request was issued from the same origin.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.inverno.mod.http.server.ExchangeInterceptor
andThen, compose
-
Field Details
-
allowedOrigins
The set of allowed origins. -
allowedOriginsPattern
The set of allowed origins patterns. -
allowCredentials
protected final boolean allowCredentialsFlag indicating whether credentials must be allowed. -
allowedHeaders
The allowed headers. -
allowedMethods
The allowed methods. -
exposedHeaders
The exposed headers. -
maxAge
The max age in seconds for CORS information cache. -
allowPrivateNetwork
protected final boolean allowPrivateNetworkFlag indicating whether private netword must be allowed. -
isWildcard
protected final boolean isWildcardFlag indicating whether the interceptor is a wildcard interceptor (allow all origins). -
isStatic
protected final boolean isStaticFlag indicating whether the interceptor is a static interceptor (allow one static origin).
-
-
Constructor Details
-
CORSInterceptor
protected CORSInterceptor(Set<CORSInterceptor.Origin> allowedOrigins, Set<Pattern> allowedOriginsPattern, boolean allowCredentials, Set<String> allowedHeaders, Set<io.inverno.mod.http.base.Method> allowedMethods, Set<String> exposedHeaders, Integer maxAge, boolean allowPrivateNetwork) Creates a CORS interceptor.
- Parameters:
allowedOrigins- the set of allowed originsallowedOriginsPattern- the set of allowed origins patternsallowCredentials- true to allow credentials, false otherwiseallowedHeaders- the set of allowed headersallowedMethods- the set of allowed methodsexposedHeaders- the set of exposed headersmaxAge- the max ageallowPrivateNetwork- true to allow private network, false otherwise
-
-
Method Details
-
builder
Returns a CORS interceptor builder for the specified allowed origins.
- Parameters:
allowedOrigins- a list of static allowed origins- Returns:
- a new CORS interceptor builder
-
intercept
-
isSameOrigin
Determines whether the request was issued from the same origin.
- Parameters:
exchange- the exchangeorigin- the target origin- Returns:
- true if the origin is the same, false otherwise or if it could not be determined
-
checkOrigin
protected void checkOrigin(CORSInterceptor.Origin origin) throws io.inverno.mod.http.base.BadRequestException, io.inverno.mod.http.base.ForbiddenException Determines whether the origin is a valid origin.
- Parameters:
origin- the origin to check- Throws:
io.inverno.mod.http.base.ForbiddenException- if the origin is not authorizedio.inverno.mod.http.base.BadRequestException
-