Class AltKerberosAuthenticationHandler
java.lang.Object
org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler
org.apache.hadoop.security.authentication.server.AltKerberosAuthenticationHandler
- All Implemented Interfaces:
AuthenticationHandler
- Direct Known Subclasses:
JWTRedirectAuthenticationHandler
The
AltKerberosAuthenticationHandler behaves exactly the same way as
the KerberosAuthenticationHandler, except that it allows for an
alternative form of authentication for browsers while still using Kerberos
for Java access. This is an abstract class that should be subclassed
to allow a developer to implement their own custom authentication for browser
access. The alternateAuthenticate method will be called whenever a request
comes from a browser.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstant for the configuration property that indicates which user agents are not considered browsers (comma separated)static final StringConstant that identifies the authentication mechanism.Fields inherited from class org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler
KEYTAB, LOG, NAME_RULES, PRINCIPAL, RULE_MECHANISMFields inherited from interface org.apache.hadoop.security.authentication.server.AuthenticationHandler
WWW_AUTHENTICATE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract AuthenticationTokenalternateAuthenticate(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Subclasses should implement this method to provide the custom authentication to be used for browsers.authenticate(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) It enforces the the Kerberos SPNEGO authentication sequence returning anAuthenticationTokenonly after the Kerberos SPNEGO sequence has completed successfully (in the case of Java access) and only after the custom authentication implemented by the subclass in alternateAuthenticate has completed successfully (in the case of browser access).getType()Returns the authentication type of the authentication handler, 'alt-kerberos'.voidinit(Properties config) Initializes the authentication handler instance.protected booleanThis method parses the User-Agent String and returns whether or not it refers to a browser.Methods inherited from class org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler
destroy, getKeytab, getPrincipals, managementOperation
-
Field Details
-
TYPE
Constant that identifies the authentication mechanism.- See Also:
-
NON_BROWSER_USER_AGENTS
Constant for the configuration property that indicates which user agents are not considered browsers (comma separated)- See Also:
-
-
Constructor Details
-
AltKerberosAuthenticationHandler
public AltKerberosAuthenticationHandler()
-
-
Method Details
-
getType
Returns the authentication type of the authentication handler, 'alt-kerberos'.- Specified by:
getTypein interfaceAuthenticationHandler- Overrides:
getTypein classKerberosAuthenticationHandler- Returns:
- the authentication type of the authentication handler, 'alt-kerberos'.
-
init
Description copied from class:KerberosAuthenticationHandlerInitializes the authentication handler instance.It creates a Kerberos context using the principal and keytab specified in the configuration.
This method is invoked by the
AuthenticationFilter.init(javax.servlet.FilterConfig)method.- Specified by:
initin interfaceAuthenticationHandler- Overrides:
initin classKerberosAuthenticationHandler- Parameters:
config- configuration properties to initialize the handler.- Throws:
javax.servlet.ServletException- thrown if the handler could not be initialized.
-
authenticate
public AuthenticationToken authenticate(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, AuthenticationException It enforces the the Kerberos SPNEGO authentication sequence returning anAuthenticationTokenonly after the Kerberos SPNEGO sequence has completed successfully (in the case of Java access) and only after the custom authentication implemented by the subclass in alternateAuthenticate has completed successfully (in the case of browser access).- Specified by:
authenticatein interfaceAuthenticationHandler- Overrides:
authenticatein classKerberosAuthenticationHandler- Parameters:
request- the HTTP client request.response- the HTTP client response.- Returns:
- an authentication token if the request is authorized or null
- Throws:
IOException- thrown if an IO error occurredAuthenticationException- thrown if an authentication error occurred
-
isBrowser
This method parses the User-Agent String and returns whether or not it refers to a browser. If its not a browser, then Kerberos authentication will be used; if it is a browser, alternateAuthenticate from the subclass will be used.A User-Agent String is considered to be a browser if it does not contain any of the values from alt-kerberos.non-browser.user-agents; the default behavior is to consider everything a browser unless it contains one of: "java", "curl", "wget", or "perl". Subclasses can optionally override this method to use different behavior.
- Parameters:
userAgent- The User-Agent String, or null if there isn't one- Returns:
- true if the User-Agent String refers to a browser, false if not
-
alternateAuthenticate
public abstract AuthenticationToken alternateAuthenticate(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, AuthenticationException Subclasses should implement this method to provide the custom authentication to be used for browsers.- Parameters:
request- the HTTP client request.response- the HTTP client response.- Returns:
- an authentication token if the request is authorized, or null
- Throws:
IOException- thrown if an IO error occursAuthenticationException- thrown if an authentication error occurs
-