Creating a Callback

A ProviderFactory.Callback is an interface through which user credentials are requested from the client by the VersionVault WAN server API Provider when they are needed to access a product repository. There is also a subinterface, StpProvider.StpCallback which is specialized for HCL VersionVault.

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 the provider has unsuccessfully attempted to authenticate.

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.

Note: The domain may be part of a user name. An HCL VersionVault login requires a domain as part of the user identity for servers on Windows®.

In a client application, the authentication callback can open a login dialog box to collect the login-name and password from the user. The realm argument can be presented to the user in the dialog box, 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 an API Provider.