Solaris WBEM Developer's Guide

Opening a Client Connection

To open a client connection, you use the CIMClient class to connect to the CIM Object Manager. The CIMClient class takes four arguments:


Example 4–1 Connecting to the Root Account

In this example, the application connects to the CIM Object Manager running on the local host in the default name space. The application creates a UserPrincipal object for the root account, which has read and write access to all CIM objects in the default name space.

{
   ...

   /* Create a name space object initialized with two null strings
   that specify the default host (the local host) and the default 
   name space (root\cimv2).*/
 
   CIMNameSpace cns = new CIMNameSpace("", "");

   UserPrincipal up = new UserPrincipal("root");
   PasswordCredential pc = new PasswordCredential("root-password"); 
   /* Connect to the name space as root with the root password. */
 
   CIMClient cc = new CIMClient(cns, up, pc);
   ...
}


Example 4–2 Connecting to a User Account

In this example, the application first creates an instance of a CIMNameSpace, UserPrincipal, and PasswordCredential object. Then, the application uses the CIMClient class to pass the host name, name space, user name, and password credential in order to create a connection to the CIMOM.

{
    ...
    /* Create a name space object initialized with A 
    (name of name space) on host happy.*/
    CIMNameSpace cns = new CIMNameSpace("happy", "A");
    UserPrincipal up = new UserPrincipal("Mary");
    PasswordCredential pc = new PasswordCredential("marys-password");
    CIMClient cc = new CIMClient(cns, up, pc);
    ...
} 


Example 4–3 Authenticating as an RBAC Role Identity

You use the SolarisUserPrincipal and SolarisPasswordCredential classes to authenticate a user's role identity. This example authenticates as Mary and assumes the role Admin.

{
...
CIMNameSpaceRole cns = new CIMNameSpace("happy", "A");
SolarisUserPrincipal sup = new SolarisUserRolePrincipal("Mary", "Admin");
SolarisPswdCredential spc = new
        SolarisPswdCredential("marys-password", "admins-password");
CIMClient cc = new CIMClient(cns, sup, spc);