Specify the authentication credentials

You can specify and store your authentication credentials using the utilws web service so that the credentials are sent automatically with each request to the BlackBerry® Administration API. To log in, you can use any of the authenticator methods supported by your BlackBerry Administration Service. For example, you can use the internal authenticator to log in using the user account credentials stored by the BlackBerry Administration Service, or you can use an external authenticator, such as Microsoft® Active Directory®.
Before you begin: Retrieve the following strings:
  • userName string for the user account you want to use to log in to the BlackBerry Administration API
  • password string for the user account you want to use to log in to the BlackBerry Administration API
  1. Specify the encodeUsername() parameters. The following code sample uses the internal authenticator. To use an external authenticator, use the AUTHENTICATOR_TYPE_PLUG_IN enumeration and specify a string for the domain you want to use, and an integer for the identifier of the external authenticator. For example, for an Active Directory authenticator, specify the Active Directory domain name and the indentifer 111.To view the external authenticators available on your BlackBerry Administration Service, use the findAuthenticators() method in the utilws web service.
    ExternalAuthenticatorTypesEnum authenticator = new ExternalAuthenticatorTypesEnum();
    authenticator.@enum = ExternalAuthenticatorTypesEnumType.AUTHENTICATOR_TYPE_INTERNAL;
    authenticator.enumSpecified = true;
    encodeUsername encodeUsernameRequest = new encodeUsername();
    encodeUsernameRequest.domain = null; 
    encodeUsernameRequest.type = authenticator;
    encodeUsernameRequest.identifier = 0;
    encodeUsernameRequest.credentialType = "0"; 
    encodeUsernameRequest.username = userName;
  2. Invoke encodeUsername().
    encodeUsernameResponse encodeUsernameResponse = utilWebService.encodeUsername(encodeUsernameRequest);
    String encodedUser = encodeUsernameResponse.returnValue;
  3. Store the encoded credentials in each web service that you use. You do not need to attach the credentials to the utilws web service.
    coreWebService.Credentials = new NetworkCredential(encodedUser, password);
    coreWebService.PreAuthenticate = true;
    dispatcherWebService.Credentials = new NetworkCredential(encodedUser, password);
    dispatcherWebService.PreAuthenticate = true;
    emailExchangeWebService.Credentials = new NetworkCredential(encodedUser, password);
    emailExchangeWebService.PreAuthenticate = true;
Next topic: Handling errors

Was this information helpful? Send us your comments.