Class LocalRedirectStrategy
java.lang.Object
org.broadleafcommerce.common.security.LocalRedirectStrategy
- All Implemented Interfaces:
org.springframework.security.web.RedirectStrategy
public class LocalRedirectStrategy
extends Object
implements org.springframework.security.web.RedirectStrategy
This class insures that if using the successUrl or failureUrl request
parameter, then the urls are valid and are local to the application
(preventing a user modifying to go somewhere else on login success/failure)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcalculateRedirectUrl(String contextPath, String url) Create the redirect urlvoidsendRedirect(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String url) voidsetContextRelative(boolean contextRelative) Set whether or not the context should be included in the redirect path.voidsetEnforcePortMatch(boolean enforcePortMatch) This forces the redirect url port to match the request port.protected voidvalidateRedirectUrl(String contextPath, String url, String requestServerName, int requestServerPort) Insure the url is valid (must begin with http or https) and local to the application
-
Constructor Details
-
LocalRedirectStrategy
public LocalRedirectStrategy()
-
-
Method Details
-
sendRedirect
public void sendRedirect(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String url) throws IOException - Specified by:
sendRedirectin interfaceorg.springframework.security.web.RedirectStrategy- Throws:
IOException
-
calculateRedirectUrl
Create the redirect url- Parameters:
contextPath-url-- Returns:
-
validateRedirectUrl
protected void validateRedirectUrl(String contextPath, String url, String requestServerName, int requestServerPort) throws MalformedURLException Insure the url is valid (must begin with http or https) and local to the application- Parameters:
contextPath- the application context pathurl- the url to validaterequestServerName- the server name of the requestrequestServerPort- the port of the request- Throws:
MalformedURLException- if the url is invalid
-
setEnforcePortMatch
public void setEnforcePortMatch(boolean enforcePortMatch) This forces the redirect url port to match the request port. This could be problematic when switching between secure and non-secure (e.g. http://localhost:8080 to https://localhost:8443)- Parameters:
enforcePortMatch-
-
setContextRelative
public void setContextRelative(boolean contextRelative) Set whether or not the context should be included in the redirect path. If true, the context is excluded from the generated path, otherwise it is included.- Parameters:
contextRelative-
-