Package org.mycore.frontend
Class MCRFrontendUtil
java.lang.Object
org.mycore.frontend.MCRFrontendUtil
Servlet/Jersey Resource utility class.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
configureSession
(MCRSession session, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) static String
returns the base URL of the mycore systemstatic String
getBaseURL
(jakarta.servlet.ServletRequest req) returns the base URL of the mycore system.static Optional<MCRServletJob>
Returns the instance saved for the current thread viaconfigureSession(MCRSession, HttpServletRequest, HttpServletResponse)
.static String
getProperty
(jakarta.servlet.http.HttpServletRequest request, String name) static String
getRemoteAddr
(jakarta.servlet.http.HttpServletRequest req) Returns the IP address of the client that made the request.getWebAppBaseDir
(jakarta.servlet.ServletContext ctx) static boolean
isIPAddrAllowed
(String lastIP, String newIP) Checks if thenewIP
address matches the session oflastIP
address.static void
prepareBaseURLs
(String baseURL) static void
writeCacheHeaders
(jakarta.servlet.http.HttpServletResponse response, long cacheTime, long lastModified, boolean useExpire) Sets cache-control, last-modified and expires parameter to the response header.
-
Field Details
-
BASE_URL_ATTRIBUTE
- See Also:
-
SESSION_NETMASK_IPV4_STRING
-
SESSION_NETMASK_IPV6_STRING
-
SESSION_NETMASK_IPV4
public static byte[] SESSION_NETMASK_IPV4 -
SESSION_NETMASK_IPV6
public static byte[] SESSION_NETMASK_IPV6 -
TRUSTED_PROXIES
The IP addresses of trusted web proxies
-
-
Constructor Details
-
MCRFrontendUtil
public MCRFrontendUtil()
-
-
Method Details
-
getBaseURL
returns the base URL of the mycore system -
getHostIP
-
getBaseURL
returns the base URL of the mycore system. This method uses the request to 'calculate' the right baseURL. Generally it is sufficent to usegetBaseURL()
instead. -
prepareBaseURLs
-
configureSession
public static void configureSession(MCRSession session, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) -
getProperty
public static Optional<String> getProperty(jakarta.servlet.http.HttpServletRequest request, String name) - Parameters:
request
- current request to get property fromname
- of requestattribute
orparameter
- Returns:
- an Optional that is either empty or contains a trimmed non-empty String that is either
the value of the request attribute or a parameter (in that order) with the given
name
.
-
getRemoteAddr
Returns the IP address of the client that made the request. When a trusted proxy server was used, e. g. a local Apache mod_proxy in front of Tomcat, the value of the last entry in the HTTP header X_FORWARDED_FOR is returned, otherwise the REMOTE_ADDR is returned. The list of trusted proxy IPs can be configured using the property MCR.Request.TrustedProxies, which is a List of IP addresses separated by blanks and/or comma. -
getCurrentServletJob
Returns the instance saved for the current thread viaconfigureSession(MCRSession, HttpServletRequest, HttpServletResponse)
.- Returns:
Optional.empty()
if no servlet job is available for the currentMCRSession
-
writeCacheHeaders
public static void writeCacheHeaders(jakarta.servlet.http.HttpServletResponse response, long cacheTime, long lastModified, boolean useExpire) Sets cache-control, last-modified and expires parameter to the response header. Use this method when the client should cache the response data.- Parameters:
response
- the response data to cachecacheTime
- how long to cachelastModified
- when the data was last modifieduseExpire
- true if 'Expire' header should be set
-
getWebAppBaseDir
-
isIPAddrAllowed
Checks if thenewIP
address matches the session oflastIP
address. Usually this is onlytrue
if both addresses are equal byInetAddress.equals(Object)
. This method is called to detect if a session is stolen by a 3rd party. There are two properties (with their default value) to modify this behavior and specify netmasks:MCR.Servlet.Session.NetMask.IPv4=255.255.255.255 MCR.Servlet.Session.NetMask.IPv6=FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
- Parameters:
lastIP
- IP address from former requestnewIP
- IP address from current request- Returns:
- Throws:
UnknownHostException
- iflastIP
ornewIP
are not valid IP addresses.
-