The following examples show two ways of using the CIMClient class to connect to the CIM Object Manager.
In Example 4–2, the application takes all the default values. That is, it connects to the CIM Object Manager running on the local host (the same host the client application is running on), in the default namespace (root\cimv2), using the default user account and password, guest.
/* Connect to root\cimv2 namespace on the local host as user guest with password guest. */ cc = new CIMClient();
In Example 4–3, the application connects to the CIM Object Manager running on the local host, in the default namespace (root\cimv2). The application creates a UserPrincipal object for the root account, which has read and write access to all CIM objects in the default namespaces.
{ ... host as root. Create a namespace object initialized with two null strings that specify the default host (the local host) and the default namespace (root\cimv2).*/ CIMNameSpace cns = new CIMNameSpace("", ""); UserPrincipal up = new UserPrincipal("root"); PasswordCredential pc = new PasswordCredential("root_password"); /* Connect to the namespace as root with the root password. */ CIMClient cc = new CIMClient(cns, up, pc"); ... }
In Example 4–4, the application connects to namespace A on host happy. The application first creates an instance of a namespace to contain the string name of the namespace (A). Next the application uses the CIMClient class to connect to the CIM Object Manager, passing it the namespace object, user name, and host name.
{ ... /* Create a namespace object initialized with A (name of namespace) on host happy.*/ CIMNameSpace cns = new CIMNameSpace("happy", "A"); UserPrincipal up = new UserPrincipal("Mary"); PasswordCredential pc = new PasswordCredential("marys_password"); // Connect to the namespace as user Mary. cc = new CIMClient(cns, "Mary", "marys_password"); ... }
Authenticating a user's role identity requires using the SolarisUserPrincipal and SolarisPasswordCredential classes. The following examples authenticates as Mary and assumes the role Admin.
{ ... CIMNameSpace cns = new CIMNameSpace("happy", "A"); SolarisUserPrincipal sup = new SolarisUserPrincipal("Mary", "Admin"); SolarisPasswordCredential spc = new SolarisPasswordCredential("marys_password", "admins_password"); CIMClient cc = new CIMClient(cns, sup, spc);