public abstract class BasicChallengeHandler extends ChallengeHandler
create()
, and registered
at a location using DispatchChallengeHandler.register(String, ChallengeHandler)
.
In addition, one can install general and realm-specific LoginHandler
objects onto this
BasicChallengeHandler
to assist in handling challenges associated
with any or specific realms. This can be achieved using setLoginHandler(LoginHandler)
and
setRealmLoginHandler(String, LoginHandler)
methods.
The following example loads an instance of a BasicChallengeHandler
, sets a login
handler onto it and registers the basic handler at a URI location. In this way, all attempts to access
that URI for which the server issues "Basic" challenges are handled by the registered BasicChallengeHandler
.
LoginHandler loginHandler = new LoginHandler() {
public PasswordAuthentication getCredentials() {
return new PasswordAuthentication("global", "credentials".toCharArray());
}
};
BasicChallengeHandler bch = BasicChallengeHandler.create();
DispatchChallengeHandler dch = DispatchChallengeHandler.create();
WebSocketFactory wsFactory = WebSocketFactory.createWebSocketFactory();
wsFactory.setDefaultChallengeHandler(dch.register("ws://localhost:8001", bch.setLoginHandler(loginHandler)));
Constructor and Description |
---|
BasicChallengeHandler() |
Modifier and Type | Method and Description |
---|---|
static BasicChallengeHandler |
create()
Creates a new instance of
BasicChallengeHandler using the
ServiceLoader API with the implementation specified under
META-INF/services. |
static BasicChallengeHandler |
create(ClassLoader classLoader)
Creates a new instance of
BasicChallengeHandler with the
specified ClassLoader using the ServiceLoader API with
the implementation specified under META-INF/services. |
abstract LoginHandler |
getLoginHandler()
Get the general (non-realm-specific) login handler associated with this challenge handler.
|
abstract BasicChallengeHandler |
setLoginHandler(LoginHandler loginHandler)
Provide a general (non-realm-specific) login handler to be used in association with this challenge handler.
|
abstract void |
setRealmLoginHandler(String realm,
LoginHandler loginHandler)
Set a Login Handler to be used if and only if a challenge request has
a realm parameter matching the provided realm.
|
canHandle, create, create, handle
public static BasicChallengeHandler create()
BasicChallengeHandler
using the
ServiceLoader
API with the implementation specified under
META-INF/services.public static BasicChallengeHandler create(ClassLoader classLoader)
BasicChallengeHandler
with the
specified ClassLoader
using the ServiceLoader
API with
the implementation specified under META-INF/services.classLoader
- ClassLoader to be used to instantiatepublic abstract void setRealmLoginHandler(String realm, LoginHandler loginHandler)
realm
- the realm upon which to apply the loginHandler
.loginHandler
- the login handler to use for the provided realm.public abstract BasicChallengeHandler setLoginHandler(LoginHandler loginHandler)
loginHandler
- a login handler for credentials.public abstract LoginHandler getLoginHandler()
null
if none has been established yet.Copyright © 2014. All Rights Reserved.