Class LoginUrlAuthenticationEntryPoint
- java.lang.Object
-
- org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint
-
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean,AuthenticationEntryPoint
public class LoginUrlAuthenticationEntryPoint extends java.lang.Object implements AuthenticationEntryPoint, org.springframework.beans.factory.InitializingBean
Used by theExceptionTranslationFilterto commence a form login authentication via theUsernamePasswordAuthenticationFilter.Holds the location of the login form in the
loginFormUrlproperty, and uses that to build a redirect URL to the login page. Alternatively, an absolute URL can be set in this property and that will be used exclusively.When using a relative URL, you can set the
forceHttpsproperty to true, to force the protocol used for the login form to beHTTPS, even if the original intercepted request for a resource used theHTTPprotocol. When this happens, after a successful login (via HTTPS), the original resource will still be accessed as HTTP, via the original request URL. For the forced HTTPS feature to work, thePortMapperis consulted to determine the HTTP:HTTPS pairs. The value offorceHttpswill have no effect if an absolute URL is used.- Since:
- 3.0
-
-
Constructor Summary
Constructors Constructor Description LoginUrlAuthenticationEntryPoint(java.lang.String loginFormUrl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()protected java.lang.StringbuildHttpsRedirectUrlForRequest(javax.servlet.http.HttpServletRequest request)Builds a URL to redirect the supplied request to HTTPS.protected java.lang.StringbuildRedirectUrlToLoginPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException authException)voidcommence(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException authException)Performs the redirect (or forward) to the login form URL.protected java.lang.StringdetermineUrlToUseForThisRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException exception)Allows subclasses to modify the login form URL that should be applicable for a given request.java.lang.StringgetLoginFormUrl()protected PortMappergetPortMapper()protected PortResolvergetPortResolver()protected booleanisForceHttps()protected booleanisUseForward()voidsetForceHttps(boolean forceHttps)Set to true to force login form access to be via https.voidsetPortMapper(PortMapper portMapper)voidsetPortResolver(PortResolver portResolver)voidsetUseForward(boolean useForward)Tells if we are to do a forward to theloginFormUrlusing theRequestDispatcher, instead of a 302 redirect.
-
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
determineUrlToUseForThisRequest
protected java.lang.String determineUrlToUseForThisRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException exception)Allows subclasses to modify the login form URL that should be applicable for a given request.- Parameters:
request- the requestresponse- the responseexception- the exception- Returns:
- the URL (cannot be null or empty; defaults to
getLoginFormUrl())
-
commence
public void commence(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException authException) throws java.io.IOException, javax.servlet.ServletExceptionPerforms the redirect (or forward) to the login form URL.- Specified by:
commencein interfaceAuthenticationEntryPoint- Parameters:
request- that resulted in anAuthenticationExceptionresponse- so that the user agent can begin authenticationauthException- that caused the invocation- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
buildRedirectUrlToLoginPage
protected java.lang.String buildRedirectUrlToLoginPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException authException)
-
buildHttpsRedirectUrlForRequest
protected java.lang.String buildHttpsRedirectUrlForRequest(javax.servlet.http.HttpServletRequest request) throws java.io.IOException, javax.servlet.ServletExceptionBuilds a URL to redirect the supplied request to HTTPS. Used to redirect the current request to HTTPS, before doing a forward to the login page.- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
setForceHttps
public void setForceHttps(boolean forceHttps)
Set to true to force login form access to be via https. If this value is true (the default is false), and the incoming request for the protected resource which triggered the interceptor was not alreadyhttps, then the client will first be redirected to an https URL, even if serverSideRedirect is set to true.
-
isForceHttps
protected boolean isForceHttps()
-
getLoginFormUrl
public java.lang.String getLoginFormUrl()
-
setPortMapper
public void setPortMapper(PortMapper portMapper)
-
getPortMapper
protected PortMapper getPortMapper()
-
setPortResolver
public void setPortResolver(PortResolver portResolver)
-
getPortResolver
protected PortResolver getPortResolver()
-
setUseForward
public void setUseForward(boolean useForward)
Tells if we are to do a forward to theloginFormUrlusing theRequestDispatcher, instead of a 302 redirect.- Parameters:
useForward- true if a forward to the login page should be used. Must be false (the default) ifloginFormUrlis set to an absolute value.
-
isUseForward
protected boolean isUseForward()
-
-