Writing a Client Program
This chapter explains how to use the Solaris WBEM SDK client APIs (javax.wbem.client) to write client programs, and includes the following topics:
Note - For detailed information on the WBEM client APIs (javax.wbem.client), see file:/usr/sadm/lib/wbem/doc/index.html.
Overview
WBEM client applications use the javax.wbem.client APIs to manipulate Common Information Model (CIM) objects. A client application uses the CIM API to construct an object (for example, a class, instance, or namespace) and then initializes, or instantiates, that object. The application uses the client APIs to pass the object to the CIM Object Manager and request a WBEM operation, such as creating a CIM class, instance, or namespace.
Sequence of a Client Application
Client applications typically follow this sequence:
Connect to the CIM Object Manager using CIMClient. A client application connects to the CIM Object Manager each time it needs to perform a WBEM operation, such as creating a CIM class or updating a CIM instance. See "Opening and Closing a Client Connection".
Use the client APIs to request operations and perform programming tasks. The application's feature set determines which operations it needs to request. The tasks that most programs perform include creating, deleting and updating instances; enumerating objects; calling methods; retrieving class definitions; and handling errors. Client programs can also create and delete classes, and create and delete namespaces, and use qualifiers. See "Performing Basic Client Operations".
Close the client connection to the CIM Object Manager using CIMClient, to free the server resources used by the client session. See "Opening and Closing a Client Connection".
Opening and Closing a Client Connection
A client application must first establish a connection with the CIM Object Manager before it can perform WBEM operations such as adding, modifying, or deleting a CIM class, CIM instance, or CIM qualifier type. The client application and CIM Object Manager can run on the same host or on different hosts. In addition, multiple clients can establish connections to the same CIM Object Manager.
About Namespaces
When an application connects to the CIM Object Manager, it must also connect to a namespace, where all subsequent operations occur. A namespace is a directory-like structure that contains classes, instances, and qualifier types. The names of all objects within a namespace must be unique. When you install the Solaris WBEM SDK, four namespaces are created:
root\cimv2 - The default namespace. Contains the CIM classes that represent objects on the system on which Solaris WBEM Services is installed.
root\security - Contains the security classes.
root\snmp- Contains the SNMP adapter classes.
root\system- Contains the classes that manage the CIM Object Manager.
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:
name - Required. An instance of a CIMNameSpace object that contains the name of the host and the namespace used for the client connection. The default is root\cimv2 on the local host (the local host is the same host in which the client application is running). Once connected to the CIM Object Manager, all subsequent CIMClient operations occur within the specified namespace.
principal - Required. An instance of a UserPrincipal object that contains the name of a valid Solaris user account. The CIM Object Manager checks the access privileges for the user name to determine the type of access allowed to CIM objects.
credential - Required. An instance of a PasswordCredential object that contains a valid password for the UserPrincipal Solaris account.
protocol - Optional (string). Protocol used for sending messages to the CIM Object Manager; either RMI (the default), or HTTP.
Example 3-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 namespace. The application creates a UserPrincipal object for the root account, which has read and write access to all CIM objects in the default namespace.
{ ... /* 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); ... } |
Example 3-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 connect to the CIM Object Manager and pass the host name, namespace , user name, and password credential to the CIM Object Manager.
{ ... /* 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"); CIMClient cc = new CIMClient(cns, up, pc); ... ... } |
Example 3-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); |