Websphere MQ Everyplace

com.ibm.mqe.attributes
Class MQeListCertificates

java.lang.Object
  |
  +--com.ibm.mqe.attributes.MQeListCertificates

public class MQeListCertificates
extends java.lang.Object

This class is used to list public certificates in a registry.

This class is a descendant of Object.


Constructor Summary
MQeListCertificates()
          Creates an object that requires the attributes to be set with the activate() method call.
MQeListCertificates(java.lang.String name, MQeFields regParams)
          Creates a object and automatically calls the activate() method.
 
Method Summary
 void activate(java.lang.String name, MQeFields regParams)
          Initializes the class and opens the registry.
 void close()
          Closes the registry and tidies up.
 java.lang.String getIssuer(java.lang.Object certificate)
          Returns the issuer field from a certificate.
 long getNotAfter(java.lang.Object certificate)
          This returns the not after date from the certificate.
 long getNotBefore(java.lang.Object certificate)
          This returns the not before date from the certificate.
 java.lang.String getSubject(java.lang.Object certificate)
          Returns the Subject field from a certificate.
 java.lang.Object getWTLSCertificate(MQeFields entry)
          Returns the certificate from a registry entry.
 MQeFields readAllEntries()
          Reads all the certificate entries in the registry.
 MQeFields readEntry(java.lang.String certName)
          Reads a specific certificate entry in the registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MQeListCertificates

public MQeListCertificates()

Creates an object that requires the attributes to be set with the activate() method call.


MQeListCertificates

public MQeListCertificates(java.lang.String name,
                           MQeFields regParams)
                    throws MQeException

Creates a object and automatically calls the activate() method.

Parameters:
name - The name associated with this registry.
regParams - An MQeFields object containing the initialization parameters for the registry:
Throws:
MQeException -
Example:
 MQeListCertificates list1;
 
 list1 = new MQeListCertificates();
 try {
     MQeListCertificates list2;
     MQeFields parms = new MQeFields();
 
     parms.putAscii(MQeRegistry.DirName, "Registry_Dir");
 
     list2 = new MQeListCertificates("Reg2", parms);
 } catch (Exception e) {// handle the exception here
 }
 
 
Method Detail

activate

public void activate(java.lang.String name,
                     MQeFields regParams)
              throws MQeException

Initializes the class and opens the registry.

Parameters:
name - The registry name
regParams - MQeFields object containing startup parameters as specified in the constructor detalis.
Returns:
void
Throws:
MQeException - as specified in the constructor details.
Example:
 try {
     MQeListCertificates list1;
     MQeFields parms = new MQeFields();
 
     parms.putAscii(MQeRegistry.DirName, "Registry_Dir");
 
     list1 = new MQeListCertificates();
     list1.activate("Reg1", parms);
 } catch (Exception e) {// handle the exception here
 }
 
 

readAllEntries

public MQeFields readAllEntries()
                         throws MQeException

Reads all the certificate entries in the registry.

This reads all the registry entries for certificates and returns them in an MQeFields object.

Returns:
An MQeFields object containing one field for each certificate in the registry.The name of a field is the name of the certificate and the value of the field is itself an MQeFields object containing the certificate. For example, if the registry contains two certificates, the MQeFields object contains two fields, each of which is an MQeFields object containing a certificate.
Throws:
MQeException -
  • Except_Closed : if the class has not been activated.
  • Other : if there is an error reading the registry Example.
Example:
 MQeFields certificates = null;
 
 try {
     MQeListCertificates list1;
     MQeFields parms = new MQeFields();
 
     parms.putAscii(MQeRegistry.DirName, "Registry_Dir");
 
     list1 = new MQeListCertificates("Reg1", parms);
     certificates = list1.readAllEntries();
 } catch (Exception e) {// Handle the exception here
 }
 return certificates;
 
 

readEntry

public MQeFields readEntry(java.lang.String certName)
                    throws MQeException

Reads a specific certificate entry in the registry.

This reads a specific certificate entry in the registry and returns it in a MQeFields object.

Parameters:
certName - The name of the certificate to be read.
Returns:
MQeFields object containing the registry entry for the certificate. This can be passed to the getWTLSCertificate() method.

If the certificate does not exist in the registry, null is returned.

Throws:
MQeException -
  • Except_Closed : if the class has not been activated.
  • Other : if there is an error reading the registry Example.
Example:
 MQeFields certificate = null;
 
 try {
     MQeListCertificates list1;
     MQeFields parms = new MQeFields();
 
     parms.putAscii(MQeRegistry.DirName, "Registry_Dir");
 
     list1 = new MQeListCertificates("Reg1", parms);
     certificate = list1.readEntry("Reg1");
 } catch (Exception e) {// Handle the exception here
 }
 return certificate;
 
 

getWTLSCertificate

public java.lang.Object getWTLSCertificate(MQeFields entry)

Returns the certificate from a registry entry.

Parameters:
entry - An MQeFields object containing the registry entry. This could be one of the embedded fields objects returned by readAllEntries(), or it could be a fields object returned by readEntry().
Returns:
An object representing the certificate in the registry entry. This can be passed to getSubject(), getIssuer(), getNotBefore(), and getNotAfter().

If the registry entry does not contain a certificate, null is returned.

Example:
 public Object USeGetWTLSCertificate(MQeFields entry) {
     Object cert = null;
 
     try {
         MQeListCertificates list1 = new MQeListCertificates("Reg1", entry);
         MQeFields certificates = list1.readAllEntries();
         Enumeration enum = certificates.fields();
 
         while (enum.hasMoreElements()) {
             //get the name of the certificate
             String entity = (String) enum.nextElement();
 
             //get the certificate's registry entry
             MQeFields certEntry = certificates.getFields(entity);
 
             //get the certificate object
             cert = list1.getWTLSCertificate(certEntry);
         }
     } catch (Exception e) {// Handle the exception here
     }
     return cert;
 }
 
 
 

getSubject

public java.lang.String getSubject(java.lang.Object certificate)

Returns the Subject field from a certificate.

This returns the subject string from the certificate.

Parameters:
certificate - An object representing a cetificate, as returned by getWTLSCertificate().
Returns:
This method retuns a string containing the subject field from the certificate. If the parameter is not a valid certificate object, null is returned.
Example:
 public String UseGetSubject(Object certificate) {
     String subject = null;
 
     try {
         MQeFields params = new MQeFields();
         MQeListCertificates list1 = new MQeListCertificates("Reg1", params);
         MQeFields certificates = list1.readAllEntries();
         Enumeration enum = certificates.fields();
 
         while (enum.hasMoreElements()) {
             //get the name of the certificate
             String entity = (String) enum.nextElement();
             //get the certificate's registry entry
             MQeFields certEntry = certificates.getFields(entity);
             //get the certificate object
             Object cert = list1.getWTLSCertificate(certEntry);
 
             subject = list1.getSubject(cert);
             System.out.println("certificate " + entity + "subject is " + subject);
         }
     } catch (Exception e) {// Handle the exception here
     }
     return subject;
     }
 

getIssuer

public java.lang.String getIssuer(java.lang.Object certificate)

Returns the issuer field from a certificate.

Parameters:
certificate - An object representing a cetificate, as returned by getWTLSCertificate().
Returns:
This method retuns a string containing the issuer field from the certificate. If the parameter is not a valid certificate object, null is returned.
Example:
 public String UseGetIssuer(Object certificate) {
     String issuer = null;
 
     try {
         MQeFields parms = new MQeFields();
         MQeListCertificates list1 = new MQeListCertificates("Reg1", parms);
         MQeFields certificates = list1.readAllEntries();
         Enumeration enum = certificates.fields();
 
         while (enum.hasMoreElements()) {
             //get the name of the certificate
             String entity = (String) enum.nextElement();
 
             //get the certificate's registry entry
             MQeFields certEntry = certificates.getFields(entity);
 
             //get the certificate object
             Object cert = list1.getWTLSCertificate(certEntry);
 
             issuer = list1.getSubject(cert);
             System.out.println("certificate " + entity + "issuer is " + issuer);
         }
     } catch (Exception e) {// Handle the exception here
     }
     return issuer;
     }
 

getNotBefore

public long getNotBefore(java.lang.Object certificate)

This returns the not before date from the certificate.

That is the date before which the certificate is invalid.

Parameters:
certificate - An object representing a cetificate, as returned by getWTLSCertificate().
Returns:
The date before which the certificate is invalid. The date is returned as a long containing the number of seconds since the midnight starting 1st January 1970 (the standard UNIX format for dates and times).

If there are any errors retrieving the date, -1 is returned.

Example:
 public long UseGetNotBefore(Object certificate) {
     long notBefore = 0L;
 
     try {
         MQeListCertificates list1 = new MQeListCertificates("MQeNode_PublicRegistry", null);
         MQeFields certEntry = list1.readEntry("myCert");
         //get the certificate object
         Object cert = list1.getWTLSCertificate(certEntry);
 
         notBefore = list1.getNotBefore(cert);
         System.out.println("certificate invalid before " + new Date(notBefore * 1000));
     } catch (Exception e) {// Handle the exception here
     }
     return notBefore;
     }
 

getNotAfter

public long getNotAfter(java.lang.Object certificate)

This returns the not after date from the certificate. That is the date after which the certificate is invalid.

Parameters:
certificate - An object representing a cetificate, as returned by getWTLSCertificate().
Returns:
The date after which the certificate is invalid. The date is returned as a long containing the number of seconds since the midnight starting 1st January 1970 (the standard UNIX format for dates and times).

If there are any errors retrieving the date, -1 is returned.

Example:
 public long UseGetNotAfter(Object certificate) {
     long notAfter = 0L;
 
     try {
         MQeListCertificates list1 = new MQeListCertificates("MQeNode_PublicRegistry", null);
         MQeFields certEntry = list1.readEntry("myCert");
         //get the certificate object
         Object cert = list1.getWTLSCertificate(certEntry);
 
         notAfter = list1.getNotBefore(cert);
         System.out.println("certificate invalid after " + new Date(notAfter * 1000));
     } catch (Exception e) {// Handle the exception here
     }
     return notAfter;
     }
 

close

public void close()

Closes the registry and tidies up.

This closes the registry and frees up resources.

Returns:
void
Example:
 try {
     MQeListCertificates list1 = new MQeListCertificates("MQeNode_PublicRegistry", null);
     MQeFields certEntry = list1.readEntry("myCert");
 
     //get the certificate object
     Object cert = list1.getWTLSCertificate(certEntry);
     long notBefore = list1.getNotBefore(cert);
 
     System.out.println("certificate invalid before " + new Date(notBefore * 1000));
     list1.close();
 } catch (Exception e) {// Handle the exception here
 }
 
 

Websphere MQ Everyplace