Class BasicAuthenticationEntryPoint
java.lang.Object
org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, AuthenticationEntryPoint
public class BasicAuthenticationEntryPoint
extends Object
implements AuthenticationEntryPoint, org.springframework.beans.factory.InitializingBean
Used by the
ExceptionTranslationFilter to commence authentication via the
BasicAuthenticationFilter.
Once a user agent is authenticated using BASIC authentication, logout requires that the
browser be closed or an unauthorized (401) header be sent. The simplest way of
achieving the latter is to call the
commence(HttpServletRequest, HttpServletResponse, AuthenticationException)
method below. This will indicate to the browser its credentials are no longer
authorized, causing it to prompt the user to login again.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidcommence(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, AuthenticationException authException) Commences an authentication scheme.@Nullable StringvoidsetCharset(@Nullable Charset charset) Sets the charset to include in theWWW-Authenticateresponse header.voidsetRealmName(String realmName)
-
Constructor Details
-
BasicAuthenticationEntryPoint
public BasicAuthenticationEntryPoint()
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
commence
public void commence(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, AuthenticationException authException) throws IOException Description copied from interface:AuthenticationEntryPointCommences an authentication scheme.ExceptionTranslationFilterwill populate theHttpSessionattribute namedAbstractAuthenticationProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEYwith the requested target URL before calling this method.Implementations should modify the headers on the
ServletResponseas necessary to commence the authentication process.- Specified by:
commencein interfaceAuthenticationEntryPoint- Parameters:
request- that resulted in anAuthenticationExceptionresponse- so that the user agent can begin authenticationauthException- that caused the invocation- Throws:
IOException
-
getRealmName
-
setRealmName
-
setCharset
Sets the charset to include in theWWW-Authenticateresponse header. By default, it is set toStandardCharsets.UTF_8. Set tonullto omit the charset attribute from the header. As per RFC 7617, only UTF-8 is permitted.- Parameters:
charset- the charset to use (StandardCharsets.UTF_8is the only accepted value), ornullto remove the charset attribute- Since:
- 7.1
-