The Solaris_NamespaceAcl Class
The Solaris_NamespaceAcl extends the Solaris_Acl base class, from which it inherits the string property capability with a default value r (read-only for all users). The Solaris_NamespaceAcl class defines this key property.
Property | Data Type | Purpose |
---|---|---|
nspace | string | Identifies the namespace to which the access control list applies. Only one instance of the namespace ACL can exist in a namespace. |
Create an instance of the Solaris_namespaceAcl class. For example:
... /* Create a namespace object initialized with root\security (name of namespace) on the local host. */ CIMNameSpace cns = new CIMNameSpace("", "root\security"); // Connect to the root\security namespace as root. cc = new CIMClient(cns, user, user_passwd); // Get the Solaris_namespaceAcl class cimclass = cc.getClass(new CIMObjectPath("Solaris_namespaceAcl"); // Create a new instance of the Solaris_namespaceAcl class ci = cimclass.newInstance(); ...
Set the capability property to the desired access rights. For example:
... /* Change the access rights (capability) to read/write to the root\molly namespace. */ ci.setProperty("capability", new CIMValue(new String("rw")); ci.setProperty("nspace", new CIMValue(new String("root\molly")); ...
Update the instance. For example:
// Pass the updated instance to the CIM Object Manager cc.createInstance(new CIMObjectPath(), ci);
To Set Access Control for a Namespace
Working with Qualifiers and Qualifier Types
A CIM qualifier is an element that characterizes a CIM class, instance, property, method, or parameter. Qualifiers have the following attributes:
Type
Value
Name
In MOF syntax, each CIM qualifier must have a CIM qualifier type defined. Qualifiers do not have a scope attribute, which indicates the CIM elements that can use the qualifier. You can only define scope in the qualifier type declaration. You cannot change scope in a qualifier.
The following sample code shows the MOF syntax for a CIM qualifier type declaration. This statement defines a qualifier type named key, with a Boolean data type (default value false), which can describe only a property and a reference to an object. The DisableOverride flavor means that key qualifiers cannot change their value.
Qualifier Key : boolean = false, Scope(property, reference), Flavor(DisableOverride); |
The following sample code shows the MOF syntax for a CIM qualifier. In this sample MOF file, key and description are qualifiers for the property a. The property data type is an integer with the property name a.
{ [key, Description("test")] int a; }; |
Getting and Setting CIM Qualifiers
A qualifier flavor is a flag that governs the use of a qualifier. Flavors describe rules that specify whether a qualifier can be propagated to derived classes and instances and whether or not a derived class or instance can override the qualifier's original value.
Example 3-19 Setting CIM Qualifiers
This example sets a list of CIM qualifiers for a new class to the qualifiers in its superclass.
{ try { cimSuperClass = cimClient.getClass(new CIMObjectPath(scName)); Vector v = new Vector(); for (Enumeration e = cimSuperClass.getQualifiers().elements(); e.hasMoreElements();) { CIMQualifier qual = (CIMQualifier)((CIMQualifier)e.nextElement()).clone(); v.addElement(qual); } cimClass.setQualifiers(v); } catch (CIMException exc) { return; } } } ... |
Batching Client Requests
You can batch multiple CIMClient API calls into a single remote call to reduce the delay introduced by multiple remote message exchanges. You use an instance of the BatchCIMClient class to build the list of operations that you want to execute in a batch request. Then use the performBatchOperations method of the CIMClient class to send the list of operations to the CIM Object Manager.
Note - A batch operation does not imply a single transaction. Each operation is independent of the other operations included in the batch and has no dependencies on the success or failure of the preceding operations.
The BatchCIMClient class contains methods that enable you to perform the same CIM operations as in non-batch mode. These methods are similar to CIMClient methods except that the BatchCIMClient methods do not return the same types as their equivalents in the CIMClient class because the values are returned as a list after the batch operation is complete. The methods return an integer operation ID which you can use to get the result of the operation later. As methods of BatchCIMClient are invoked, the BatchCIMClient object builds a list of CIMOperationobjects that will be executed later.
When the client executes the batch operation list by invoking CIMClient's performBatchOperations method, a BatchResult object is returned that contains the results of the batch operation. Clients can then pass the operation ID to the getResult method of the BatchResult class to get the results of the operations. If an operation on the list generates an exception, an exception object is embedded in the BatchResult object. When you invoke the getResult method with the ID of the operation that failed, the exception is thrown by the getResult method.
Example 3-20 Batching Example
The following example shows how you can use the batching API to perform multiple operations in one remote call. In this example, three operations - enumerateInstanceNames, getClass, and enumerateInstances are performed as a single batch operation.
import java.util.Enumeration; import java.util.ArrayList; import java.util.Vector; import java.lang.String; import javax.wbem.cim.*; import javax.wbem.client.*; import javax.wbem.client.UserPrincipal; import javax.wbem.client.PasswordCredential; public class TestBatch { public static void main(String args[]) throws CIMException { CIMClient cc = null; CIMObjectPath cop = null; String protocol = CIMClient.CIM_RMI; if (args.length < 4) { System.out.println("Usage: TestBatch host user passwd classname " + "[rmi|http]"); System.exit(1); } try { CIMNameSpace cns = new CIMNameSpace(args[0]); UserPrincipal up = new UserPrincipal(args[1]); PasswordCredential pc = new PasswordCredential(args[2]); if (args.length == 5 && args[4].equalsIgnoreCase("http")) { protocol = CIMClient.CIM_XML; } cc = new CIMClient(cns, up, pc, protocol); CIMObjectPath op = new CIMObjectPath(args[3]); BatchCIMClient bc = new BatchCIMClient(); int[] ids = new int[3]; ids[0] = bc.enumerateInstanceNames(op); ids[1] = bc.getClass(op, false, true, true, null); ids[2] = bc.enumerateInstances(op, true, false, false, false, null); BatchResult br = cc.performBatchOperations(bc); Enumeration instanceNames = (Enumeration)br.getResult (ids[0]); CIMClass cl = (CIMClass)br.getResult(ids[1]); Enumeration instances = (Enumeration)br.getResult(ids[2]); while (instanceNames.hasMoreElements()) { System.out.println((CIMObjectPath)instanceNames. nextElement()); } System.out.println(cl.toMOF()); while (instances.hasMoreElements()) { System.out.println((CIMInstance)instances. nextElement()); } } catch (Exception e) { e.printStackTrace(); System.out.println("Exception: "+e); } // close session. if (cc != null) { cc.close(); } } } |