2.2. Provider Authentication

Before you can request anything of the provider, you will need to authenticate yourself. The provider uses BASIC HTTP authentication for this process.

[Note]Note

A username and password must be configured and provided from the upstream BELTS before you will be able to access the system. You may need to contact your upstream provider for this information or refer to the setup instructions in the BELTS setup guide at the BELTS SourceForge site.

The mechanism for providing username and password fields varies depending on the language you are writing your application in. For Java, you write code similar to the following to supply your username and password to the Provider:

String username="my-username";
String password="my-password";

Authenticator.setDefault (new BasicAuthenticator(username, password));
        

In this listing, BasicAuthenticator is a Java class that provides the username and password when requested. It is written as follows:

import java.net.Authenticator;
import java.net.PasswordAuthentication;
            
public class BasicAuthenticator extends Authenticator
{
    String _username;
    String _password;
            
    public BasicAuthenticator(String username, String password)
    {
        _username = username;
        _password = password;
    }
            
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication(_username, _password.toCharArray());
    }
}