Service Registry 3.1 Developer's Guide

Authenticating with the Registry

The Registry uses certificate authentication, so to submit data to the Registry you must have a certificate. You must also use the User Registration Wizard of the Web Console to create a user who can submit data to the Registry. See Getting Access to the Registry for details.

Before a client can submit data, the client must send its certificate to the Registry in a set of credentials. The following code fragment shows how to perform this task. You need to specify the following required values to obtain credentials:

Typically, you would retrieve the four required values from property settings, and you would encapsulate much of the code in a method.

String keystorePath = "myKeystorePath";
String storepass = "myStorepass";
String alias = "myAlias";
String keypass = myKeypass";

Set credentials = new HashSet();
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(new BufferedInputStream(
    new FileInputStream(keystorePath)),
     storepass.toCharArray());
X509Certificate cert = (X509Certificate)
     keyStore.getCertificate(alias);
PrivateKey privateKey =
     (PrivateKey) keyStore.getKey(alias, keypass.toCharArray());
credentials.add(new X500PrivateCredential(cert, privateKey,
    alias));
connection.setCredentials(credentials);

If the setCredentials method succeeds, you are logged in to the Registry and can publish objects.

The sample programs that authenticate with the Registry all call a method named getCredentialsFromKeystore that contains this code. The method is defined in the file INSTALL/registry-samples/common/src/RegistryCredentials.java.


Note –

The method in RegistryCredentials.java contains commented-out lines that display the values of the keystore file, the keystore password, the user alias, and the user password. If you get an error the first time you try to publish an object, remove the comment characters from these lines to make sure that these properties are set correctly as described in To Edit the Security Settings of the build.properties File.