Creating a Callback
A ProviderFactory.Callback
is an interface through which user
credentials are requested from the client by the HCL Compass CM API Provider when needed to access a
product repository. There is also a subprovider interface, StpProvider.StpCallback
which is specialized for HCL Compass.
The following MyCallback()
class creates user
authentication information (domain, user login name and password)
and returns to the provider.
// Callback class, needed to create a provider.
private static class MyCallback implements Callback
{
// Get a WVCM Authentication object.
// This implementation of the authentication
// callback returns the specified username and password.
// The Provider calls getAuthentication to authenticate the current user.
public Authentication getAuthentication(final String realm, int retryCount)
{
if (retryCount>0)
throw UnsupportedOperationException("Bad credentials");
return new Authentication()
{
public String loginName() { return "<the_domain>\\<the_username>"; }
public String password() { return "<the_password>"; }
};
}
}
Each Provider instance is given one Provider.Callback
object
that is used to obtain credentials for any repository that the client
accesses through that Provider instance.
The realm
argument is a string that identifies
the context for which authentication is being requested (for example,
a server URL or repository name). The format for the string varies
from subprovider to subprovider and is intended for display to the
user as a mnemonic.
The retryCount
specifies the number of times to
attempt authenticating to the repository.
In this example, the realm
and retryCount
arguments
are not used. However, client applications should limit the retryCount
attempts
to a small number because there is no limit on authentication retry
attempts and a provider will repeatedly try to get authentication
after a failure unless a retryCount
is set or the getAuthentication method
throws an exception.
In a client application, the authentication callback can open a
login window to collect the user login name and password. The realm
argument
can be presented in a window to show which product repository the
user is logging in to (for example, a server URL or a user database).
This option can be helpful if users have different user names and
passwords for different product repositories.
The Callback is called for each different realm that the client makes requests to while it is
using the Provider. See the Javadoc information for the
StpProvider
class for details about the requirements on the
Callback passed to a HCL Compass CM API
Provider.