Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
3.  Writing a Client Program Performing Basic Client Operations Creating a Namespace  Previous   Contents   Next 
   
 

Deleting a Namespace

Use the deleteNameSpace method to delete a namespace.

Creating a Base Class


Note - You can also create a base class using the MOF language. If you are familiar with MOF syntax, use a text editor to create a MOF file and then use the MOF Compiler to compile the file into Java classes. See Chapter 2, Creating JavaBeans Using the MOF Compiler.


Use the CIMClass class to create a Java class representing a CIM class. To declare the most basic class, you need only specify the class name and a key property or an abstract qualifier. However, most classes include properties that describe the data of the class. To declare a property, include the property's data type, name, and an optional default value. The property data type must be an instance of CIMDataType.

A property can have a key qualifier, which identifies it as a key property. A key property uniquely defines the instances of the class. Only keyed classes can have instances. Therefore, if you do not define a key property in a class, the class can only be used as an abstract class. If you define a key property in a class in a new namespace, you must first compile the core MOF files into the namespace. The core MOF files contain the declarations of the standard CIM qualifiers, such as the key qualifier.

Class definitions can be more complicated, including such features as aliases, qualifiers, and qualifier flavors.

Deleting a Class

Use the CIMClient deleteClass method to delete a class. Deleting a class removes the class and throws a CIMException.


Note - You must first remove any existing subclasses or instances before deleting a base class.



Example 3-18 Deleting a Class

This example uses the deleteClass method to delete a class in the default namespace root\cimv2. This program takes four required string arguments (hostname, classname, username, and password). The user running this program must specify the username and password for an account that has write permission to the root\cimv2 namespace.

 
import javax.wbem.cim.CIMClass;
import javax.wbem.cim.CIMException;
import javax.wbem.cim.CIMNameSpace;
import javax.wbem.cim.CIMObjectPath;
import javax.wbem.client.CIMClient;
import javax.wbem.client.UserPrincipal;
import javax.wbem.client.PasswordCredential;

import java.rmi.*;
import java.util.Enumeration;

/**
 * Deletes the class specified in the command line. Works in the default
 * namespace root/cimv2.
 */
public class DeleteClass {
    public static void main(String args[]) throws CIMException {
       CIMClient cc = null;
       // if not four arguments, show usage and exit
       if (args.length != 4) {
           System.out.println("Usage: DeleteClass host className " +
                              "username password"); 
           System.exit(1);
       }
       try {
          // args[0] contains the hostname. We create a CIMNameSpace 
          // (cns) pointing to the default namespace on the specified host
          CIMNameSpace cns = new CIMNameSpace(args[0]);

          // args[2] and args[3] contain the username and password.
          // We create a UserPrincipal (up) using the username and
          // a PasswordCredential using the password.
          UserPrincipal up = new UserPrincipal(args[2]);
          PasswordCredential pc = new PasswordCredential(args[3]);

          cc = new CIMClient(cns, up, pc);

          // Get the class name (args[4]) and create a CIMObjectPath
          CIMObjectPath cop = new CIMObjectPath(args[1]);
          // delete the class
          cc.deleteClass(cop);
   }
   catch (Exception e) {
          System.out.println("Exception: "+e);
   }
   if (cc != null) {
       cc.close();
       }
    }
}

Setting Access Control

You can set access control on a per-user or namespace basis. The following access control classes are stored in the root\security namespace:

  • Solaris_Acl - Base class for Solaris Access Control Lists (ACL). This class defines the string property capability and sets its default value to r (read only).

  • Solaris_UserAcl - Represents the access control that a user has to the CIM objects within the specified namespace.

  • Solaris_NamespaceAcl - Represents the access control on a namespace.

You can set access control for individual users to the CIM objects within a namespace by creating an instance of the Solaris_UserACL class and then changing the access rights for that instance. Similarly, you can set access control for a namespace by creating an instance of the Solaris_NameSpaceACL class and then using the createInstance method to set the access rights for that instance.

An effective way to combine the use of these two classes is to use the Solaris_NameSpaceACL class first, to restrict access to all users to the objects in a namespace. Then, you can use the Solaris_UserACL class to grant selected users access to the namespace.

The Solaris_UserAcl Class

The Solaris_UserAcl class extends the Solaris_Acl base class, from which it inherits the string property capability with a default value of r (read only). You can set the capability property to any one of the following values for access privileges.

Access Right

Description

r

Read

rw

Read and Write

w

Write

none

No access

The Solaris_UserAcl class defines the following key properties. Only one instance of the namespace and user name ACL pair can exist in a namespace.

Property

Data Type

Purpose

nspace

string

Identifies the namespace to which the ACL applies.

username

string

Identifies the user to which the ACL applies.

To Set Access Control for a User

  1. Create an instance of the Solaris_UserAcl 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_UserAcl class 
    cimclass = cc.getClass(new CIMObjectPath("Solaris_UserAcl");
    
    // Create a new instance of the Solaris_UserAcl
    class ci = cimclass.newInstance();
    ...

  2. Set the capability property to the desired access rights. For example:
    ...
    /* Change the access rights (capability) to read/write for user Guest
    on objects in the root\molly namespace.*/
    ci.setProperty("capability", new CIMValue(new String("rw")); 
    ci.setProperty("nspace", new CIMValue(new String("root\molly")); 
    ci.setProperty("username", new CIMValue(new String("guest"));
    ...

  3. Update the instance. For example:
    ...
    // Pass the updated instance to the CIM Object Manager 
    cc.createInstance(new CIMObjectPath(), ci);
    ...  

 
 
 
  Previous   Contents   Next