Package org.forgerock.openam.cors
Class CORSService
- java.lang.Object
-
- org.forgerock.openam.cors.CORSService
-
public class CORSService extends Object
See http://www.w3.org/TR/cors/ for further information. Once constructed, this service serves a number of purposes:- Validates requests are CORS (by analysis of the Origin header).
- Determines if a request is to follow the preflight or actual request flow.
- Verifies the requests are valid in this configuration of CORS (through comparison against pre- configured values.
- Alters the responses such that they are valid for CORS.
-
-
Constructor Summary
Constructors Constructor Description CORSService(boolean enabled, List<String> acceptedOrigins, List<String> acceptedMethods, List<String> acceptedHeaders, List<String> exposedHeaders, int maxAge, boolean allowCredentials, String expectedHostname)Constructor setting all necessary values to create a usable CORSService.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhandleRequest(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res)Entry point for classes using the service.
-
-
-
Constructor Detail
-
CORSService
public CORSService(boolean enabled, List<String> acceptedOrigins, List<String> acceptedMethods, List<String> acceptedHeaders, List<String> exposedHeaders, int maxAge, boolean allowCredentials, String expectedHostname)Constructor setting all necessary values to create a usable CORSService. If the maxAge parameter is less than zero, we will set it to zero here. The acceptedHeaders and exposedHeaders lists must contain at least one entry each.- Parameters:
acceptedOrigins- A list of origins from which we accept CORS requestsacceptedMethods- A list of HTTP methods of whose type we accept CORS requestsacceptedHeaders- (Optional) A list of HTTP headers which - if included - in the request don't make it abortexposedHeaders- (Optional) The list of headers which the user-agent can expose to its CORS-clientmaxAge- The maximum cache-length of the pre-flight response by the CORS-client in secondsallowCredentials- Whether we include the allow credentials headerexpectedHostname- (Optional) the name of the host the request should be headed to in its Host header- Throws:
IllegalArgumentException- If the acceptedOrigins or acceptedMethods params are null or empty
-
-
Method Detail
-
handleRequest
public boolean handleRequest(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOExceptionEntry point for classes using the service. Validates requests against the CORS specification, and add headers required to the response.- Parameters:
req- CORS HTTP requestres- HTTP response- Returns:
- true if the caller is to continue processing the request
- Throws:
IOException- if an I/O error occurs while handling the response
-
-