@InterfaceAudience.Private @InterfaceStability.Unstable public class AuthenticationFilter extends Object implements javax.servlet.Filter
AuthenticationFilter enables protecting web application
 resources with different (pluggable)
 authentication mechanisms and signer secret providers.
 
 Additional authentication mechanisms are supported via the AuthenticationHandler interface.
 
 This filter delegates to the configured authentication handler for authentication and once it obtains an
 AuthenticationToken from it, sets a signed HTTP cookie with the token. For client requests
 that provide the signed HTTP cookie, it verifies the validity of the cookie, extracts the user information
 and lets the request proceed to the target resource.
 
 The rest of the configuration properties are specific to the AuthenticationHandler implementation and the
 AuthenticationFilter will take all the properties that start with the prefix #PREFIX#, it will remove
 the prefix from it and it will pass them to the the authentication handler for initialization. Properties that do
 not start with the prefix will not be passed to the authentication handler initialization.
 
Details of the configurations are listed on Configuration Page
 The "zookeeper" implementation has additional configuration properties that
 must be specified; see ZKSignerSecretProvider for details.
| Modifier and Type | Field and Description | 
|---|---|
| static String | AUTH_TOKEN_MAX_INACTIVE_INTERVALConstant for the configuration property
 that indicates the max inactive interval of the generated token. | 
| static String | AUTH_TOKEN_VALIDITYConstant for the configuration property that indicates the validity of the generated token. | 
| static String | AUTH_TYPEConstant for the property that specifies the authentication handler to use. | 
| static String | CONFIG_PREFIXConstant for the property that specifies the configuration prefix. | 
| static String | COOKIE_DOMAINConstant for the configuration property that indicates the domain to use in the HTTP cookie. | 
| static String | COOKIE_PATHConstant for the configuration property that indicates the path to use in the HTTP cookie. | 
| static String | COOKIE_PERSISTENTConstant for the configuration property
 that indicates the persistence of the HTTP cookie. | 
| static String | SIGNATURE_SECRETConstant for the property that specifies the secret to use for signing the HTTP Cookies. | 
| static String | SIGNATURE_SECRET_FILE | 
| static String | SIGNER_SECRET_PROVIDERConstant for the configuration property that indicates the name of the
 SignerSecretProvider class to use. | 
| static String | SIGNER_SECRET_PROVIDER_ATTRIBUTEConstant for the ServletContext attribute that can be used for providing a
 custom implementation of the SignerSecretProvider. | 
| Constructor and Description | 
|---|
| AuthenticationFilter() | 
| Modifier and Type | Method and Description | 
|---|---|
| static SignerSecretProvider | constructSecretProvider(javax.servlet.ServletContext ctx,
                       Properties config,
                       boolean disallowFallbackToRandomSecretProvider) | 
| static void | createAuthCookie(javax.servlet.http.HttpServletResponse resp,
                String token,
                String domain,
                String path,
                long expires,
                boolean isCookiePersistent,
                boolean isSecure)Creates the Hadoop authentication HTTP cookie. | 
| void | destroy()Destroys the filter. | 
| protected void | doFilter(javax.servlet.FilterChain filterChain,
        javax.servlet.http.HttpServletRequest request,
        javax.servlet.http.HttpServletResponse response)Delegates call to the servlet filter chain. | 
| void | doFilter(javax.servlet.ServletRequest request,
        javax.servlet.ServletResponse response,
        javax.servlet.FilterChain filterChain)If the request has a valid authentication token it allows the request to continue to the target resource,
 otherwise it triggers an authentication sequence using the configured  AuthenticationHandler. | 
| protected AuthenticationHandler | getAuthenticationHandler()Returns the authentication handler being used. | 
| protected Properties | getConfiguration()Returns the configuration properties of the  AuthenticationFilterwithout the prefix. | 
| protected Properties | getConfiguration(String configPrefix,
                javax.servlet.FilterConfig filterConfig)Returns the filtered configuration (only properties starting with the specified prefix). | 
| protected String | getCookieDomain()Returns the cookie domain to use for the HTTP cookie. | 
| protected String | getCookiePath()Returns the cookie path to use for the HTTP cookie. | 
| protected long | getMaxInactiveInterval()Returns the max inactive interval time of the generated tokens. | 
| protected String | getRequestURL(javax.servlet.http.HttpServletRequest request)Returns the full URL of the request including the query string. | 
| protected AuthenticationToken | getToken(javax.servlet.http.HttpServletRequest request)Returns the  AuthenticationTokenfor the request. | 
| protected long | getValidity()Returns the validity time of the generated tokens. | 
| void | init(javax.servlet.FilterConfig filterConfig)Initializes the authentication filter and signer secret provider. | 
| protected void | initializeAuthHandler(String authHandlerClassName,
                     javax.servlet.FilterConfig filterConfig) | 
| protected void | initializeSecretProvider(javax.servlet.FilterConfig filterConfig) | 
| protected boolean | isCookiePersistent()Returns the cookie persistence to use for the HTTP cookie. | 
| protected boolean | isCustomSignerSecretProvider()Returns if a custom implementation of a SignerSecretProvider is being used. | 
| protected boolean | isRandomSecret()Returns if a random secret is being used. | 
| protected boolean | verifyTokenType(AuthenticationHandler handler,
               AuthenticationToken token)This method verifies if the specified token type matches one of the the
 token types supported by a specified  AuthenticationHandler. | 
public static final String CONFIG_PREFIX
public static final String AUTH_TYPE
public static final String SIGNATURE_SECRET
public static final String SIGNATURE_SECRET_FILE
public static final String AUTH_TOKEN_MAX_INACTIVE_INTERVAL
public static final String AUTH_TOKEN_VALIDITY
public static final String COOKIE_DOMAIN
public static final String COOKIE_PATH
public static final String COOKIE_PERSISTENT
public static final String SIGNER_SECRET_PROVIDER
public static final String SIGNER_SECRET_PROVIDER_ATTRIBUTE
public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Initializes the authentication filter and signer secret provider.
It instantiates and initializes the specifiedAuthenticationHandler.init in interface javax.servlet.FilterfilterConfig - filter configuration.javax.servlet.ServletException - thrown if the filter or the authentication handler could not be initialized properly.protected void initializeAuthHandler(String authHandlerClassName, javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
javax.servlet.ServletExceptionprotected void initializeSecretProvider(javax.servlet.FilterConfig filterConfig)
                                 throws javax.servlet.ServletException
javax.servlet.ServletExceptionpublic static SignerSecretProvider constructSecretProvider(javax.servlet.ServletContext ctx, Properties config, boolean disallowFallbackToRandomSecretProvider) throws Exception
Exceptionprotected Properties getConfiguration()
AuthenticationFilter
 without the prefix. The returned properties are the same that the
 getConfiguration(String, FilterConfig) method returned.protected AuthenticationHandler getAuthenticationHandler()
protected boolean isRandomSecret()
protected boolean isCustomSignerSecretProvider()
protected long getMaxInactiveInterval()
protected long getValidity()
protected String getCookieDomain()
protected String getCookiePath()
protected boolean isCookiePersistent()
public void destroy()
 It invokes the AuthenticationHandler.destroy() method to release any resources it may hold.
destroy in interface javax.servlet.Filterprotected Properties getConfiguration(String configPrefix, javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
Properties object is used to initialized the
 AuthenticationHandler.
 This method can be overriden by subclasses to obtain the configuration from other configuration source than the web.xml file.
configPrefix - configuration prefix to use for extracting configuration properties.filterConfig - filter configuration objectAuthenticationHandler instance.javax.servlet.ServletException - thrown if the configuration could not be created.protected String getRequestURL(javax.servlet.http.HttpServletRequest request)
Used as a convenience method for logging purposes.
request - the request object.protected AuthenticationToken getToken(javax.servlet.http.HttpServletRequest request) throws IOException, AuthenticationException
AuthenticationToken for the request.
 
 It looks at the received HTTP cookies and extracts the value of the AuthenticatedURL.AUTH_COOKIE
 if present. It verifies the signature and if correct it creates the AuthenticationToken and returns
 it.
 
 If this method returns null the filter will invoke the configured AuthenticationHandler
 to perform user authentication.
request - request object.null otherwise.IOException - thrown if an IO error occurred.AuthenticationException - thrown if the token is invalid or if it has expired.protected boolean verifyTokenType(AuthenticationHandler handler, AuthenticationToken token)
AuthenticationHandler. This
 method is specifically designed to work with
 CompositeAuthenticationHandler implementation which supports
 multiple authentication schemes while the AuthenticationHandler
 interface supports a single type via
 AuthenticationHandler.getType() method.handler - The authentication handler whose supported token types
                should be used for verification.token - The token whose type needs to be verified.public void doFilter(javax.servlet.ServletRequest request,
            javax.servlet.ServletResponse response,
            javax.servlet.FilterChain filterChain)
              throws IOException,
                     javax.servlet.ServletException
AuthenticationHandler.doFilter in interface javax.servlet.Filterrequest - the request object.response - the response object.filterChain - the filter chain object.IOException - thrown if an IO error occurred.javax.servlet.ServletException - thrown if a processing error occurred.protected void doFilter(javax.servlet.FilterChain filterChain,
            javax.servlet.http.HttpServletRequest request,
            javax.servlet.http.HttpServletResponse response)
                 throws IOException,
                        javax.servlet.ServletException
filterChain - the filter chain object.request - the request object.response - the response object.IOException - thrown if an IO error occurred.javax.servlet.ServletException - thrown if a processing error occurred.public static void createAuthCookie(javax.servlet.http.HttpServletResponse resp,
                    String token,
                    String domain,
                    String path,
                    long expires,
                    boolean isCookiePersistent,
                    boolean isSecure)
resp - the response object.token - authentication token for the cookie.domain - the cookie domain.path - the cookie path.expires - UNIX timestamp that indicates the expire date of the
                cookie. It has no effect if its value < 0.isSecure - is the cookie secure?isCookiePersistent - whether the cookie is persistent or not.
 XXX the following code duplicate some logic in Jetty / Servlet API,
 because of the fact that Hadoop is stuck at servlet 2.5 and jetty 6
 right now.Copyright © 2022 Apache Software Foundation. All rights reserved.