Top Description Inners Fields Constructors Methods
org.eclipse.jetty.client

public Class SPNEGOAuthentication

extends AbstractAuthentication
Class Inheritance
Imports
java.io.IOException, java.net.URI, java.nio.file.Path, java.util.Arrays, .Base64, .HashMap, .Map, java.util.concurrent.Callable, javax.security.auth.Subject, javax.security.auth.callback.Callback, .CallbackHandler, .PasswordCallback, javax.security.auth.login.AppConfigurationEntry, .Configuration, .LoginContext, .LoginException, org.eclipse.jetty.http.HttpHeader, org.eclipse.jetty.util.Attributes, org.eclipse.jetty.util.security.SecurityUtils, org.ietf.jgss.GSSContext, .GSSException, .GSSManager, .GSSName, .Oid, org.slf4j.Logger, .LoggerFactory

Implementation of the SPNEGO (or "Negotiate") authentication defined in RFC 4559.

A user is logged in via JAAS (either via userName/password or via userName/keyTab) once only.

For every request that needs authentication, a GSSContext is initiated and later established after reading the response from the server.

Applications should create objects of this class and add them to the AuthenticationStore retrieved from the HttpClient via HttpClient#getAuthenticationStore().

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private static class
public static class

Field Summary

Modifier and TypeField and Description
private final GSSManager
private static final Logger
private static final String
private boolean
private String
private Path
private Path
private String
private String
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Authentication.Result
authenticate(Request
the request to execute the authentication mechanism for
request
,
ContentResponse
the 401 response obtained in the previous attempt to request the protected resource
response
,
Authentication.HeaderInfo
the WWW-Authenticate (or Proxy-Authenticate) header chosen for this authentication (among the many that the response may contain)
headerInfo
,
Attributes
the conversation context in case the authentication needs multiple exchanges to be completed and information needs to be stored across exchanges
context
)

Implements org.eclipse.jetty.client.Authentication.authenticate.

Executes the authentication mechanism for the given request, returning a Result that can be used to actually authenticate the request via Authentication.Result#apply(Request).

public String

Returns:

the name of the service to use
getServiceName
()

Get the name of the service to use.

public Path

Returns:

the path of the ticket cache file
getTicketCachePath
()

Get the path of the ticket cache file.

public String
public Path

Returns:

the path of the keyTab file with the user credentials
getUserKeyTabPath
()

Get the path of the keyTab file with the user credentials.

public String

Returns:

the user name of the user to login
getUserName
()

Get the user name of the user to login.

public String

Returns:

the password of the user to login
getUserPassword
()

Get the password of the user to login.

private Callable<byte[]>
initGSSContext(SPNEGOAuthentication.SPNEGOContext spnegoContext, String host, byte[] bytes)

public boolean
isRenewTGT()

Returns: whether to renew the ticket granting ticket

public boolean
isUseTicketCache()

Returns: whether to use the ticket cache during login

private SPNEGOAuthentication.SPNEGOContext
public void
setRenewTGT(boolean
whether to renew the ticket granting ticket
renewTGT
)

Set whether to renew the ticket granting ticket.

public void
setServiceName(String
the name of the service to use
serviceName
)

Set the name of the service to use.

public void
setTicketCachePath(Path
the path of the ticket cache file
ticketCachePath
)

public void
setUserKeyTabPath(Path
the path of the keyTab file with the user credentials
userKeyTabPath
)

public void
setUserName(String
user name of the user to login
userName
)

Set user name of the user to login.

public void
setUserPassword(String
the password of the user to login
userPassword
)

public void
setUseTicketCache(boolean
whether to use the ticket cache during login
useTicketCache
)

Inherited from org.eclipse.jetty.client.AbstractAuthentication:
getRealmgetURImatchesmatchesURI

Field Detail

gssManagerback to summary
private final GSSManager gssManager
LOGback to summary
private static final Logger LOG
NEGOTIATEback to summary
private static final String NEGOTIATE
renewTGTback to summary
private boolean renewTGT
serviceNameback to summary
private String serviceName
ticketCachePathback to summary
private Path ticketCachePath
userKeyTabPathback to summary
private Path userKeyTabPath
userNameback to summary
private String userName
userPasswordback to summary
private String userPassword
useTicketCacheback to summary
private boolean useTicketCache

Constructor Detail

SPNEGOAuthenticationback to summary
public SPNEGOAuthentication(URI uri)

Method Detail

authenticateback to summary
public Authentication.Result authenticate(Request request, ContentResponse response, Authentication.HeaderInfo headerInfo, Attributes context)

Implements org.eclipse.jetty.client.Authentication.authenticate.

Doc from org.eclipse.jetty.client.Authentication.authenticate.

Executes the authentication mechanism for the given request, returning a Result that can be used to actually authenticate the request via Authentication.Result#apply(Request).

If a request for "/secure" returns a Result, then the result may be used for other requests such as "/secure/foo" or "/secure/bar", unless those resources are protected by other realms.

Parameters
request:Request

the request to execute the authentication mechanism for

response:ContentResponse

the 401 response obtained in the previous attempt to request the protected resource

headerInfo:Authentication.HeaderInfo

the WWW-Authenticate (or Proxy-Authenticate) header chosen for this authentication (among the many that the response may contain)

context:Attributes

the conversation context in case the authentication needs multiple exchanges to be completed and information needs to be stored across exchanges

Returns:Authentication.Result

the authentication result, or null if the authentication could not be performed

Annotations
@Override
getServiceNameback to summary
public String getServiceName()

Get the name of the service to use.

Returns:String

the name of the service to use

getTicketCachePathback to summary
public Path getTicketCachePath()

Get the path of the ticket cache file.

Returns:Path

the path of the ticket cache file

getTypeback to summary
public String getType()

Implements abstract org.eclipse.jetty.client.AbstractAuthentication.getType.

Annotations
@Override
getUserKeyTabPathback to summary
public Path getUserKeyTabPath()

Get the path of the keyTab file with the user credentials.

Returns:Path

the path of the keyTab file with the user credentials

getUserNameback to summary
public String getUserName()

Get the user name of the user to login.

Returns:String

the user name of the user to login

getUserPasswordback to summary
public String getUserPassword()

Get the password of the user to login.

Returns:String

the password of the user to login

initGSSContextback to summary
private Callable<byte[]> initGSSContext(SPNEGOAuthentication.SPNEGOContext spnegoContext, String host, byte[] bytes)
isRenewTGTback to summary
public boolean isRenewTGT()
Returns:boolean

whether to renew the ticket granting ticket

isUseTicketCacheback to summary
public boolean isUseTicketCache()
Returns:boolean

whether to use the ticket cache during login

loginback to summary
private SPNEGOAuthentication.SPNEGOContext login()
setRenewTGTback to summary
public void setRenewTGT(boolean renewTGT)

Set whether to renew the ticket granting ticket.

Parameters
renewTGT:boolean

whether to renew the ticket granting ticket

setServiceNameback to summary
public void setServiceName(String serviceName)

Set the name of the service to use.

Parameters
serviceName:String

the name of the service to use

setTicketCachePathback to summary
public void setTicketCachePath(Path ticketCachePath)
Parameters
ticketCachePath:Path

the path of the ticket cache file

See Also
setUseTicketCache(boolean)
setUserKeyTabPathback to summary
public void setUserKeyTabPath(Path userKeyTabPath)
Parameters
userKeyTabPath:Path

the path of the keyTab file with the user credentials

See Also
setUserPassword(String)
setUserNameback to summary
public void setUserName(String userName)

Set user name of the user to login.

Parameters
userName:String

user name of the user to login

setUserPasswordback to summary
public void setUserPassword(String userPassword)
Parameters
userPassword:String

the password of the user to login

See Also
setUserKeyTabPath(Path)
setUseTicketCacheback to summary
public void setUseTicketCache(boolean useTicketCache)
Parameters
useTicketCache:boolean

whether to use the ticket cache during login

See Also
setTicketCachePath(Path)
org.eclipse.jetty.client back to summary

private Class SPNEGOAuthentication.PasswordCallbackHandler

extends Object
implements CallbackHandler
Class Inheritance
  • java.lang.Object
  • org.eclipse.jetty.client.SPNEGOAuthentication.PasswordCallbackHandler
All Implemented Interfaces
javax.security.auth.callback.CallbackHandler

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
handle(Callback[]
an array of Callback objects provided by an underlying security service which contains the information requested to be retrieved or displayed.
callbacks
)

Implements javax.security.auth.callback.CallbackHandler.handle.

Retrieve or display the information requested in the provided Callbacks.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PasswordCallbackHandlerback to summary
private PasswordCallbackHandler()

Method Detail

handleback to summary
public void handle(Callback[] callbacks) throws IOException

Implements javax.security.auth.callback.CallbackHandler.handle.

Doc from javax.security.auth.callback.CallbackHandler.handle.

Retrieve or display the information requested in the provided Callbacks.

The handle method implementation checks the instance(s) of the Callback object(s) passed in to retrieve or display the requested information. The following example is provided to help demonstrate what an handle method implementation might look like. This example code is for guidance only. Many details, including proper error handling, are left out for simplicity.

public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {

  for (int i = 0; i < callbacks.length; i++) {
     if (callbacks[i] instanceof TextOutputCallback) {

         // display the message according to the specified type
         TextOutputCallback toc = (TextOutputCallback)callbacks[i];
         switch (toc.getMessageType()) {
         case TextOutputCallback.INFORMATION:
             System.out.println(toc.getMessage());
             break;
         case TextOutputCallback.ERROR:
             System.out.println("ERROR: " + toc.getMessage());
             break;
         case TextOutputCallback.WARNING:
             System.out.println("WARNING: " + toc.getMessage());
             break;
         default:
             throw new IOException("Unsupported message type: " +
                                 toc.getMessageType());
         }

     } else if (callbacks[i] instanceof NameCallback) {

         // prompt the user for a username
         NameCallback nc = (NameCallback)callbacks[i];

         // ignore the provided defaultName
         System.err.print(nc.getPrompt());
         System.err.flush();
         nc.setName((new BufferedReader
                 (new InputStreamReader(
                         System.in,
                         System.getProperty("stdin.encoding")))).readLine());

     } else if (callbacks[i] instanceof PasswordCallback) {

         // prompt the user for sensitive information
         PasswordCallback pc = (PasswordCallback)callbacks[i];
         System.err.print(pc.getPrompt());
         System.err.flush();
         pc.setPassword(readPassword(System.in));

     } else {
         throw new UnsupportedCallbackException
                 (callbacks[i], "Unrecognized Callback");
     }
  }
}

// Reads user password from given input stream.
private char[] readPassword(InputStream in) throws IOException {
   // insert code to read a user password from the input stream
}
Parameters
callbacks:Callback[]

an array of Callback objects provided by an underlying security service which contains the information requested to be retrieved or displayed.

Annotations
@Override
Exceptions
IOException:
if an input or output error occurs.
org.eclipse.jetty.client back to summary

private Class SPNEGOAuthentication.SPNEGOConfiguration

extends Configuration
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public AppConfigurationEntry[]
getAppConfigurationEntry(String
the name used to index the Configuration.
name
)

Implements abstract javax.security.auth.login.Configuration.getAppConfigurationEntry.

Retrieve the AppConfigurationEntries for the specified name from this Configuration.

Inherited from javax.security.auth.login.Configuration:
getConfigurationgetInstancegetInstancegetInstancegetParametersgetProvidergetTyperefreshsetConfiguration

Constructor Detail

SPNEGOConfigurationback to summary
private SPNEGOConfiguration()

Method Detail

getAppConfigurationEntryback to summary
public AppConfigurationEntry[] getAppConfigurationEntry(String name)

Implements abstract javax.security.auth.login.Configuration.getAppConfigurationEntry.

Doc from javax.security.auth.login.Configuration.getAppConfigurationEntry.

Retrieve the AppConfigurationEntries for the specified name from this Configuration.

Parameters
name:String

the name used to index the Configuration.

Returns:AppConfigurationEntry[]

an array of AppConfigurationEntries for the specified name from this Configuration, or null if there are no entries for the specified name

Annotations
@Override
org.eclipse.jetty.client back to summary

private Class SPNEGOAuthentication.SPNEGOContext

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final String
private GSSContext
private Subject

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ATTRIBUTEback to summary
private static final String ATTRIBUTE
gssContextback to summary
private GSSContext gssContext
subjectback to summary
private Subject subject

Constructor Detail

SPNEGOContextback to summary
private SPNEGOContext()

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jetty.client back to summary

public Class SPNEGOAuthentication.SPNEGOResult

extends Object
implements Result
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.client.Authentication.Result

Field Summary

Modifier and TypeField and Description
private final HttpHeader
private final URI
private final String

Constructor Summary

AccessConstructor and Description
public
SPNEGOResult(URI uri, String token)

public
SPNEGOResult(URI uri, HttpHeader header, String token)

Method Summary

Modifier and TypeMethod and Description
public void
apply(Request
the request to authenticate
request
)

Implements org.eclipse.jetty.client.Authentication.Result.apply.

Applies the authentication result to the given request.

public URI
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

headerback to summary
private final HttpHeader header
uriback to summary
private final URI uri
valueback to summary
private final String value

Constructor Detail

SPNEGOResultback to summary
public SPNEGOResult(URI uri, String token)
SPNEGOResultback to summary
public SPNEGOResult(URI uri, HttpHeader header, String token)

Method Detail

applyback to summary
public void apply(Request request)

Implements org.eclipse.jetty.client.Authentication.Result.apply.

Doc from org.eclipse.jetty.client.Authentication.Result.apply.

Applies the authentication result to the given request. Typically, a Authorization header is added to the request, with the right information to successfully authenticate at the server.

Parameters
request:Request

the request to authenticate

Annotations
@Override
getURIback to summary
public URI getURI()

Implements org.eclipse.jetty.client.Authentication.Result.getURI.

Returns:URI

Doc from org.eclipse.jetty.client.Authentication.Result.getURI.

the URI of the request that has been used to generate this Result

Annotations
@Override