Top Description Inners Fields Constructors Methods
org.apache.catalina.authenticator

public Class SpnegoAuthenticator

extends AuthenticatorBase
Class Inheritance
Imports
java.io.File, .IOException, java.security.Principal, .PrivilegedAction, .PrivilegedActionException, .PrivilegedExceptionAction, java.util.LinkedHashMap, java.util.regex.Pattern, javax.security.auth.Subject, javax.security.auth.login.LoginContext, .LoginException, jakarta.servlet.http.HttpServletResponse, org.apache.catalina.LifecycleException, .Realm, org.apache.catalina.connector.Request, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.buf.ByteChunk, .MessageBytes, org.apache.tomcat.util.codec.binary.Base64, org.apache.tomcat.util.compat.JreVendor, org.ietf.jgss.GSSContext, .GSSCredential, .GSSException, .GSSManager, .Oid

A SPNEGO authenticator that uses the SPNEGO/Kerberos support built in to Java 6. Successful Kerberos authentication depends on the correct configuration of multiple components. If the configuration is invalid, the error messages are often cryptic although a Google search will usually point you in the right direction.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
SpnegoAuthenticator.AcceptAction

This class gets a gss credential via a privileged action.

public static class
public static class
SpnegoAuthenticator.SpnegoTokenFixer

This class implements a hack around an incompatibility between the SPNEGO implementation in Windows and the SPNEGO implementation in Java 8 update 40 onwards.

Field Summary

Modifier and TypeField and Description
private boolean
private static final String
private final Log
private String
private Pattern
private boolean
Inherited from org.apache.catalina.authenticator.AuthenticatorBase:
alwaysUseSessionAUTH_HEADER_NAMEcachechangeSessionIdOnAuthenticationcontextdisableProxyCachingjaspicCallbackHandlerClassREALM_NAMEsecurePagesWithPragmasecureRandomAlgorithmsecureRandomClasssecureRandomProvidersendAuthInfoResponseHeaderssessionIdGeneratorsmsso

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean
doAuthenticate(Request
The request that triggered the authentication
request
,
HttpServletResponse
The response associated with the request
response
)

Implements abstract org.apache.catalina.authenticator.AuthenticatorBase.doAuthenticate.

Provided for sub-classes to implement their specific authentication mechanism.

public boolean
protected String
getAuthMethod()

Implements abstract org.apache.catalina.authenticator.AuthenticatorBase.getAuthMethod.

Return the authentication method, which is vendor-specific and not defined by HttpServletRequest.

public String
public String
protected void
initInternal()

Overrides org.apache.catalina.valves.ValveBase.initInternal.

Sub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.

protected boolean
isPreemptiveAuthPossible(Request
The request to check for credentials
request
)

Overrides org.apache.catalina.authenticator.AuthenticatorBase.isPreemptiveAuthPossible.

Can the authenticator perform preemptive authentication for the given request?

public boolean
public void
setApplyJava8u40Fix(boolean applyJava8u40Fix)

public void
setLoginConfigName(String loginConfigName)

public void
setNoKeepAliveUserAgents(String noKeepAliveUserAgents)

public void
setStoreDelegatedCredential(boolean storeDelegatedCredential)

Inherited from org.apache.catalina.authenticator.AuthenticatorBase:
allowCorsPreflightBypassassociateauthenticatechangeSessionIDcheckForCachedAuthenticationdoLogingetAllowCorsPreflightgetAlwaysUseSessiongetCachegetChangeSessionIdOnAuthenticationgetContainergetDisableProxyCachinggetJaspicCallbackHandlerClassgetRealmNamegetSecurePagesWithPragmagetSecureRandomAlgorithmgetSecureRandomClassgetSecureRandomProviderinvokeisContinuationRequiredisSendAuthInfoResponseHeadersloginlogoutnotifyreauthenticateFromSSOregisterregistersetAllowCorsPreflightsetAlwaysUseSessionsetCachesetChangeSessionIdOnAuthenticationsetContainersetDisableProxyCachingsetJaspicCallbackHandlerClasssetSecurePagesWithPragmasetSecureRandomAlgorithmsetSecureRandomClasssetSecureRandomProvidersetSendAuthInfoResponseHeadersstartInternalstopInternal

Field Detail

applyJava8u40Fixback to summary
private boolean applyJava8u40Fix
AUTH_HEADER_VALUE_NEGOTIATEback to summary
private static final String AUTH_HEADER_VALUE_NEGOTIATE
logback to summary
private final Log log

Hides org.apache.catalina.authenticator.AuthenticatorBase.log.

loginConfigNameback to summary
private String loginConfigName
noKeepAliveUserAgentsback to summary
private Pattern noKeepAliveUserAgents
storeDelegatedCredentialback to summary
private boolean storeDelegatedCredential

Constructor Detail

SpnegoAuthenticatorback to summary
public SpnegoAuthenticator()

Method Detail

doAuthenticateback to summary
protected boolean doAuthenticate(Request request, HttpServletResponse response) throws IOException

Implements abstract org.apache.catalina.authenticator.AuthenticatorBase.doAuthenticate.

Doc from org.apache.catalina.authenticator.AuthenticatorBase.doAuthenticate.

Provided for sub-classes to implement their specific authentication mechanism.

Parameters
request:Request

The request that triggered the authentication

response:HttpServletResponse

The response associated with the request

Returns:boolean

true if the the user was authenticated, otherwise false, in which case an authentication challenge will have been written to the response

Annotations
@Override
Exceptions
IOException:
If an I/O problem occurred during the authentication process
getApplyJava8u40Fixback to summary
public boolean getApplyJava8u40Fix()
getAuthMethodback to summary
protected String getAuthMethod()

Implements abstract org.apache.catalina.authenticator.AuthenticatorBase.getAuthMethod.

Doc from org.apache.catalina.authenticator.AuthenticatorBase.getAuthMethod.

Return the authentication method, which is vendor-specific and not defined by HttpServletRequest.

Returns:String

the authentication method, which is vendor-specific and not defined by HttpServletRequest.

Annotations
@Override
getLoginConfigNameback to summary
public String getLoginConfigName()
getNoKeepAliveUserAgentsback to summary
public String getNoKeepAliveUserAgents()
initInternalback to summary
protected void initInternal() throws LifecycleException

Overrides org.apache.catalina.valves.ValveBase.initInternal.

Doc from org.apache.catalina.util.LifecycleMBeanBase.initInternal.

Sub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.

Annotations
@Override
Exceptions
LifecycleException:

Doc from org.apache.catalina.util.LifecycleBase.initInternal.

If the initialisation fails

isPreemptiveAuthPossibleback to summary
protected boolean isPreemptiveAuthPossible(Request request)

Overrides org.apache.catalina.authenticator.AuthenticatorBase.isPreemptiveAuthPossible.

Doc from org.apache.catalina.authenticator.AuthenticatorBase.isPreemptiveAuthPossible.

Can the authenticator perform preemptive authentication for the given request?

Parameters
request:Request

The request to check for credentials

Returns:boolean

true if preemptive authentication is possible, otherwise false

Annotations
@Override
isStoreDelegatedCredentialback to summary
public boolean isStoreDelegatedCredential()
setApplyJava8u40Fixback to summary
public void setApplyJava8u40Fix(boolean applyJava8u40Fix)
setLoginConfigNameback to summary
public void setLoginConfigName(String loginConfigName)
setNoKeepAliveUserAgentsback to summary
public void setNoKeepAliveUserAgents(String noKeepAliveUserAgents)
setStoreDelegatedCredentialback to summary
public void setStoreDelegatedCredential(boolean storeDelegatedCredential)
org.apache.catalina.authenticator back to summary

public Class SpnegoAuthenticator.AcceptAction

extends Object
implements PrivilegedExceptionAction<byte[]>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.authenticator.SpnegoAuthenticator.AcceptAction
All Implemented Interfaces
java.security.PrivilegedExceptionAction

This class gets a gss credential via a privileged action.

Field Summary

Modifier and TypeField and Description
pack-priv byte[]
pack-priv GSSContext

Constructor Summary

AccessConstructor and Description
public
AcceptAction(GSSContext context, byte[] decodedToken)

Method Summary

Modifier and TypeMethod and Description
public byte[]
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decodedback to summary
pack-priv byte[] decoded
gssContextback to summary
pack-priv GSSContext gssContext

Constructor Detail

AcceptActionback to summary
public AcceptAction(GSSContext context, byte[] decodedToken)

Method Detail

runback to summary
public byte[] run() throws GSSException

Implements java.security.PrivilegedExceptionAction.run.

Doc from java.security.PrivilegedExceptionAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:byte[]

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedExceptionAction should document what (if anything) this value represents.

Annotations
@Override
org.apache.catalina.authenticator back to summary

public Class SpnegoAuthenticator.AuthenticateAction

extends Object
implements PrivilegedAction<Principal>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.authenticator.SpnegoAuthenticator.AuthenticateAction
All Implemented Interfaces
java.security.PrivilegedAction

Field Summary

Modifier and TypeField and Description
private final GSSContext
private final Realm
private final boolean

Constructor Summary

AccessConstructor and Description
public
AuthenticateAction(Realm realm, GSSContext gssContext, boolean storeDelegatedCredential)

Method Summary

Modifier and TypeMethod and Description
public Principal
run()

Implements java.security.PrivilegedAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

gssContextback to summary
private final GSSContext gssContext
realmback to summary
private final Realm realm
storeDelegatedCredentialback to summary
private final boolean storeDelegatedCredential

Constructor Detail

AuthenticateActionback to summary
public AuthenticateAction(Realm realm, GSSContext gssContext, boolean storeDelegatedCredential)

Method Detail

runback to summary
public Principal run()

Implements java.security.PrivilegedAction.run.

Doc from java.security.PrivilegedAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:Principal

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedAction should document what (if anything) this value represents.

Annotations
@Override
org.apache.catalina.authenticator back to summary

public Class SpnegoAuthenticator.SpnegoTokenFixer

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.authenticator.SpnegoAuthenticator.SpnegoTokenFixer

This class implements a hack around an incompatibility between the SPNEGO implementation in Windows and the SPNEGO implementation in Java 8 update 40 onwards. It was introduced by the change to fix this bug: https://bugs.openjdk.java.net/browse/JDK-8048194 (note: the change applied is not the one suggested in the bug report)

It is not clear to me if Windows, Java or Tomcat is at fault here. I think it is Java but I could be wrong.

This hack works by re-ordering the list of mechTypes in the NegTokenInit token.

Field Summary

Modifier and TypeField and Description
private int
private final byte[]

Constructor Summary

AccessConstructor and Description
private
SpnegoTokenFixer(byte[] token)

Method Summary

Modifier and TypeMethod and Description
public static void
fix(byte[] token)

private void
fix()

private boolean
private int
private boolean
oid(String expected)

private String
private boolean
tag(int expected)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

posback to summary
private int pos
tokenback to summary
private final byte[] token

Constructor Detail

SpnegoTokenFixerback to summary
private SpnegoTokenFixer(byte[] token)

Method Detail

fixback to summary
public static void fix(byte[] token)
fixback to summary
private void fix()
lengthback to summary
private boolean length()
lengthAsIntback to summary
private int lengthAsInt()
oidback to summary
private boolean oid(String expected)
oidAsStringback to summary
private String oidAsString()
tagback to summary
private boolean tag(int expected)