Mustercode für die Erstellung eines neuen erweiterten Entitätstyps im Standardnamespace

Mit dem Mustercode-Snippet und den Datengraphen können Sie einen Entitätstyp erstellen, der einen integrierten Entitätstyp im Standardnamespace erweitert.

Dieses Mustercode-Snippet deckt die folgenden Schritte ab:

  1. Es wird ein Schema im Standardnamespace für einen neuen Entitätstyp PersonAccountExt erstellt, der den integrierten Entitätstyp "PersonAccount" erweitert.
  2. Es wird eine Entität person1 des Entitätstyps PersonAccountExt erstellt.
  3. Es wird ein neues Mermal namens HomePhone zum neu erstellten Entitätstyp PersonAccountExt hinzugefügt. Das neue Merkmal HomePhone wird dem LDAP-Attribut primaryOwnerContact zugeordnet.
  4. Das Merkmal HomePhone wird mit einem Wert zur Entität person1 hinzugefügt.
  5. Es wird geprüft, ob das Merkmal HomePhone zur Entität person1 hinzugefügt wurde.

Voraussetzungen

Stellen Sie sicher, dass Sie die Informationen gelesen und die Schritte ausgeführt haben, die im Thema Voraussetzungen für die Programmierung beschrieben sind. Hierzu gehört auch der Abschnitt Merkmalschema erweitern, in dem Informationen zu Datenobjekten "propertySchema" und "extensionPropertySchema" enthalten sind und die gültige Syntax für Merkmalsdatentypen aufgeführt ist.

Fügen Sie die folgende Importanweisung ebenfalls zu Ihrer Klasse hinzu:
import com.ibm.websphere.wim.exception.SchemaAlreadyExistException;

Stellen Sie sicher, dass in Ihrer Konfiguration mit föderierten Repositorys ein LDAP-Repository konfiguriert ist. Weitere Informationen enthält das Thema über das Konfigurieren von LDAP in einer Konfiguration mit föderierten Repositorys im Information Center von WebSphere Application Server.

Mustercode

Fügen Sie das folgende Code-Snippet zu Ihrem Anwendungscode hinzu und ersetzen Sie die Variablen durch die tatsächlichen Werte, die Sie verwenden wollen.

/**
 * This method uses the schema extension API to add a new entity
 * extending from an existing virtual member manager entity.
 */
public static void testRunTimeAddNewEntity() 
{
    // Create schema for new entity type
    addEntityPersonAccountExt();
    // Create entity of new entity type
    createPersonAccountExt();
    // Add a property 'HomePhone' to 'PersonAccountExt' and 
    // map it to 'primaryOwnerContact' attribute in LDAP
    addPropertyToPersonAccountExt();
    // Add 'HomePhone' to 'person1'
    addHomePhoneForPersonAccountExt();
    // Search for the person
    searchPersonAcctExt();
}

/**
 * Method to create the schema for 'PersonAccountExt' in the default namespace
 */
@SuppressWarnings("unchecked")
private static void addEntityPersonAccountExt() 
{
    try 
    {
        System.out.println("\nCLIENT: Creating schema for 'PersonAccountExt' . . . ");
        DataObject root = SDOHelper.createRootDataObject();
        // Create a schema object under root
        DataObject dynaSchemaDO = root.createDataObject(SchemaConstants.DO_SCHEMA);
        // Create new entity type schema object. This object will hold the schema definition for the
        // 'PersonAccountExt' entity type that we want to create.
        DataObject entitySchemaDO = dynaSchemaDO.createDataObject(SchemaConstants.DO_ENTITY_SCHEMA);
        // Set the namespace for new entity type
        entitySchemaDO.setString(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
        // Set the entity type name
        entitySchemaDO.set(SchemaConstants.PROP_ENTITY_NAME, "PersonAccountExt");
        // Set the parent entity type name.
        entitySchemaDO.set(SchemaConstants.PROP_PARENT_ENTITY_NAME, Service.DO_PERSON_ACCOUNT);
        // Create an entity configuration data object
        // This data object defines repository details
        DataObject entConfigDO = entitySchemaDO.createDataObject(SchemaConstants.DO_ENTITY_CONFIGURATION);
        // Set the default parent to the base entry of the configured LDAP.
        entConfigDO.set(SchemaConstants.PROP_DEFAULT_PARENT, "dc=yourco,dc=com");
        // Set the RDN (login) property to uid.
        entConfigDO.set(SchemaConstants.PROP_RDN_PROPERTY, "uid");
        // Set the repository id.
        DataObject reposConfigInfo1DO = entConfigDO.createDataObject(SchemaConstants.DO_META_DATA);
        reposConfigInfo1DO.set(SchemaConstants.PROP_NAME, ConfigService.CONFIG_DO_OBJECTCLASSES);
        reposConfigInfo1DO.set(SchemaConstants.PROP_REPOSITORY_ID, "LDAP1");
        // Set the object classes for the added object. These classes are from the LDAP schema.
        List objReadValues = reposConfigInfo1DO.getList(SchemaConstants.PROP_VALUES);
        objReadValues.add("inetorgperson");
        objReadValues.add("organizationalperson");
        objReadValues.add("person");
        // Set the RDN property for the repository
        DataObject reposConfigInfo3DO = entConfigDO.createDataObject(SchemaConstants.DO_META_DATA);
        reposConfigInfo3DO.set(SchemaConstants.PROP_NAME, ConfigService.CONFIG_DO_RDN_ATTRIBUTES);
        reposConfigInfo3DO.set(SchemaConstants.PROP_REPOSITORY_ID, "LDAP1");
        List values = reposConfigInfo3DO.getList(SchemaConstants.PROP_VALUES);
        values.add("uid");
        System.out.println("Create Schema input datagraph -> " + printDO(root));
        // Invoke the create schema API
        DataObject outRoot = service.createSchema(root);
        System.out.println("Create Schema output datagraph -> " + printDO(outRoot));
        System.out.println("\nCLIENT: new entity type is created.");
    }
    catch (SchemaAlreadyExistException e) 
    {
        System.out.println("CLIENT: entity type already exists.\n\n");
    }
    catch(Exception e) 
    {
        e.printStackTrace();
    }
}

/**
 *  Method to create an entity of the 'PersonAccountExt' entity type.
 */
private static void createPersonAccountExt() 
{
    //Create Person 1
    try 
    {
        System.out.println("\nCLIENT: Creating Person 1 . . .");
        //Gets an empty data graph of Person from WIM Service.
        DataObject root = SDOHelper.createRootDataObject();
        // Create a "PersonAccount" entity type data object under root
        DataObject person = root.createDataObject(SchemaConstants.DO_ENTITIES, 
                Service.WIM_NS_URI, "PersonAccountExt");
        // Set the values for required attributes, uid, cn and sn
        person.set("uid", "person1");
        person.set("cn", "Person 1");
        person.set("sn", "Person1LastName");
        System.out.println("Create PersonAccountExt input datagraph -> " + printDO(root));
        // Invoke the create API to create the person account entity defined previously
        root = service.create(root);
        System.out.println("Create PersonAccountExt output datagraph -> " + printDO(root));
        System.out.println("CLIENT: Person 1 has been created. \n\n");
    }
    catch(Exception e) 
    {
        e.printStackTrace();
    }
}

/**
 *  Method to add a property 'HomePhone' to 'PersonAccountExt' entity type
 *  and map it to 'primaryOwnerContact' attribute in LDAP
 */
@SuppressWarnings("unchecked")
private static void addPropertyToPersonAccountExt() 
    {
    try 
    {
        DataObject root = SDOHelper.createRootDataObject();
        // Create a new "schema" object under root
        // This object will contain the details of the schema modifications that have to be made
        DataObject schema = root.createDataObject(SchemaConstants.DO_SCHEMA);
        // Create a property schema data object under the schema object created earlier
        DataObject propertySchema = schema.createDataObject(SchemaConstants.DO_PROPERTY_SCHEMA);
        // Set the property name
        propertySchema.setString(SchemaConstants.PROP_PROPERTY_NAME, "HomePhone");
        // Set the property namespace as the default namespace
        propertySchema.setString(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
        // Specify that the property is not multi-valued
        propertySchema.setBoolean(SchemaConstants.PROP_MULTI_VALUED, false);
        // Specify the data type of the property as String
        propertySchema.setString(SchemaConstants.PROP_DATA_TYPE, SchemaConstants.DATA_TYPE_STRING);
        // Specify the applicable entity types for this property
        // The property will be added for all entity type names specified in the list
        propertySchema.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES)
                .add("PersonAccountExt");
        System.out.println("Add property input datagraph " + printDO(root));
        // Invoke the create schema API
        root = service.createSchema(root);
        System.out.println("Add property output datagraph " + printDO(root));
        // Map the 'HomePhone' property created previously to the 'primaryOwnerContact' LDAP attribute
        Hashtable configData = new Hashtable();
        // Specify the repository for which this property needs to be mapped
        configData.put(DynamicConfigConstants.DYNA_CONFIG_KEY_REPOS_ID, "LDAP1");
        DataObject configProvider = SDOHelper.createConfigProviderDataObject();
        // Specify the repository type as "Ldap"
        DataObject ldapRepos = SDOHelper.createConfigRepositoryDataObject(configProvider, 
                ConfigConstants.CONFIG_DO_LDAP_REPOSITORY_TYPE);
        // Give the property name and attribute name that need to be mapped to each other
        DataObject attrConfig = ldapRepos.createDataObject(ConfigConstants.CONFIG_DO_ATTRIBUTE_CONFIGUARTION);
        DataObject attr = attrConfig.createDataObject(ConfigConstants.CONFIG_DO_ATTRIBUTES);
        attr.setString(ConfigConstants.CONFIG_PROP_PROPERTY_NAME, "HomePhone");
        attr.setString(ConfigConstants.CONFIG_PROP_NAME, "primaryOwnerContact");
        configData.put(DynamicConfigConstants.DYNA_CONFIG_KEY_PROP_CONFIG, attr);
        // Call the dynamic config update
        // This API updates the mapping for this session only, this mapping is not persistent
        service.dynamicUpdateConfig(DynamicConfigConstants.DYNA_CONFIG_EVENT_ADD_PROPERTY_CONFIG, 
                configData);
    }
    catch(Exception e) 
    {
		    e.printStackTrace();
    }
}  

/**
  * Add 'HomePhone' to 'person1' entity created in LDAP earlier
  */
private static void addHomePhoneForPersonAccountExt() 
{
    try 
    {
    DataObject root = SDOHelper.createRootDataObject();
    DataObject entity = SDOHelper.createEntityDataObject(root, null, "PersonAccountExt");
    // Set the unique name for the object to which the 'HomePhone' value needs to be set
    entity.createDataObject(SchemaConstants.DO_IDENTIFIER).set(SchemaConstants.PROP_UNIQUE_NAME, 
            "uid=person1,dc=yourco,dc=com");
    // Specify the value of 'HomePhone'
    entity.set("HomePhone", "020-2341123");
    System.out.println("Set property input datagraph -> " + printDO(root));
    // Invoke the VMM update API
    root = service.update(root);
    System.out.println("Set property output datagraph -> " + printDO(root));
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}

/**
  * Search for 'PersonAccountExt' 
  */
@SuppressWarnings("unchecked")
private static void searchPersonAcctExt() 
{
    try 
    {
        DataObject root = SDOHelper.createRootDataObject();
        // Create a search control data object
        DataObject searchCtrl = SDOHelper.createControlDataObject(root, null, 
                SchemaConstants.DO_SEARCH_CONTROL);
        // Specify the properties that need to be fetched for all matching entries
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("uid");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("sn");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("cn");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("HomePhone");
        // Specify the matching criteria as the search expression
        searchCtrl.setString(SchemaConstants.PROP_SEARCH_EXPRESSION, "@xsi:type='PersonAccountExt'");
        // Invoke the search API
        root = service.search(root);
        System.out.println("Output datagraph -> " + printDO(root));
        // Iterate over the search results
        printIdentifiers(root);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}
Anmerkung: Im Mustercode wird die API "dynamicUpdateConfig()" zum Hinzufügen einer Merkmalkonfiguration für die Zuordnung eines Virtual Member Manager-Merkmals zu einem LDAP-Attribut verwendet. Wenn zur Laufzeit mit der API "dynamicUpdateConfig()" Konfigurationsaktualisierungen vorgenommen werden, wird nur die Konfiguration im Arbeitsspeicher, nicht jedoch die Konfigurationsdatei aktualisiert, so dass Änderungen nicht auf Platte gespeichert werden. Damit Konfigurationsänderung auf Platte gespeichert werden, verwenden Sie den wsadmin-Befehl "addIdMgrLDAPAttr", um LDAP-Attribute zu Virtual Member Manager-Merkmalen zuzuordnen. Weitere Informationen enthält das Thema über die Befehlsgruppe "IdMgrRepositoryConfig" für das Objekt "AdminTask" im Information Center von WebSphere Application Server. Alternativ können Sie zum Zuordnen von LDAP-Attributen zu Virtual Member Manager-Merkmalen auch die Administrationskonsole verwenden. Dies ist in den folgenden Schritten beschrieben:
  1. Klicken Sie in der Administrationskonsole von WebSphere Application Server auf Sicherheit > Globale Sicherheit.
  2. Wählen Sie unter "Repository für Benutzeraccounts" im Feld "Verfügbare Realm-Definitionen" die Option Zusammengefasste Repositorys aus, und klicken Sie auf Konfigurieren.
    Anmerkung: Klicken Sie zum Konfigurieren einer bestimmten Domäne in einer Umgebung mit mehreren Sicherheitsdomänen auf Sicherheitsdomänen > Domänenname. Erweitern Sie unter "Sicherheitsattribute" den Eintrag Benutzerrealm, und klicken Sie auf Für diese Domäne anpassen. Wählen Sie den Realmtyp Zusammengefasste Repositorys aus, und klicken Sie dann auf Konfigurieren.
  3. Klicken Sie unter "Zugehörige Elemente" auf Repositorys verwalten > Repository-Name.
  4. Klicken Sie unter "Weitere Eigenschaften" auf LDAP-Attribute.
  5. Klicken Sie auf Hinzufügen und wählen Sie im Dropdown-Menü die Option Unterstützt aus.
  6. Geben Sie den Namen des LDAP-Attributs im Feld Name, den Namen des Virtual Member Manager-Merkmals im Feld Eigenschaftsname und den Entitätstyp, für den die Attributzuordnung gilt, im Feld Entitätstypen ein. Für das obige Beispiel müssen Sie die folgenden Werte eingeben:
    • Name: HomePhone
    • Eigenschaft: primaryOwnerContact
    • Entitätstypen: PersonAccountExt

Eingabe- und Ausgabedatengraphen

Eingabedatengraph für die Erstellung des neuen erweiterten Entitätstyps:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:schema>
      <wim:entitySchema nsURI="http://www.ibm.com/websphere/wim"
          entityName="PersonAccountExt" parentEntityName="PersonAccount">
        <wim:entityConfiguration defaultParent="dc=yourco,dc=com" rdnProperty="uid">
          <wim:metaData name="objectClasses" repositoryId="LDAP1">
            <wim:values>inetorgperson</wim:values>
            <wim:values>organizationalperson</wim:values>
            <wim:values>person</wim:values>
          </wim:metaData>
          <wim:metaData name="rdnAttributes" repositoryId="LDAP1">
            <wim:values>uid</wim:values>
          </wim:metaData>
        </wim:entityConfiguration>
      </wim:entitySchema>
    </wim:schema>
  </wim:Root>
</sdo:datagraph>

Ausgabedatengraph nach der Erstellung des neuen erweiterten Entitätstyps:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:schema>
      <wim:entitySchema nsURI="http://www.ibm.com/websphere/wim"
          entityName="PersonAccountExt" parentEntityName="PersonAccount">
        <wim:repositoryIds>LDAP1</wim:repositoryIds>
        <wim:entityConfiguration defaultParent="dc=yourco,dc=com" rdnProperty="uid">
          <wim:metaData name="objectClasses" repositoryId="LDAP1">
            <wim:values>inetorgperson</wim:values>
            <wim:values>organizationalperson</wim:values>
            <wim:values>person</wim:values>
          </wim:metaData>
          </wim:metaData>
          <wim:metaData name="rdnAttributes" repositoryId="LDAP1">
            <wim:values>uid</wim:values>
          </wim:metaData>
        </wim:entityConfiguration>
      </wim:entitySchema>
    </wim:schema>
  </wim:Root>
</sdo:datagraph>

Eingabedatengraph für die Erstellung einer Entität des neuen Entitätstyps:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo" xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:entities xsi:type="wim:PersonAccountExt">
      <wim:uid>person1</wim:uid>
      <wim:cn>Person 1</wim:cn>
      <wim:sn>Person1LastName</wim:sn>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>

Ausgabedatengraph nach der Erstellung einer Entität des neuen Entitätstyps:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo" xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:entities xsi:type="wim:PersonAccountExt">
      <wim:identifier externalName="uid=person1,dc=yourco,dc=com" repositoryId="LDAP1"
          uniqueId="cb1ea321-8673-4012-9750-c917d4e7f2f6" uniqueName="uid=person1,dc=yourco,dc=com"/>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>

Eingabedatengraph für die Erstellung eines neuen Merkmals für den neuen Entitätstyp:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:schema>
      <wim:propertySchema nsURI="http://www.ibm.com/websphere/wim" dataType="String"
          multiValued="false" propertyName="HomePhone">
        <wim:applicableEntityTypeNames>wim:PersonAccountExt</wim:applicableEntityTypeNames>
      </wim:propertySchema>
    </wim:schema>
  </wim:Root>
</sdo:datagraph>

Ausgabedatengraph nach der Erstellung eines Merkmals für den neuen Entitätstyp:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:schema>
      <wim:propertySchema nsURI="http://www.ibm.com/websphere/wim" dataType="String"
          multiValued="false" propertyName="HomePhone">
        <wim:repositoryIds>LDAP1</wim:repositoryIds>
        <wim:applicableEntityTypeNames>wim:PersonAccountExt</wim:applicableEntityTypeNames>
      </wim:propertySchema>
    </wim:schema>
  </wim:Root>
</sdo:datagraph>

Eingabedatengraph für das Hinzufügen eines Merkmals mit einem Wert zur Entität:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo" xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:entities xsi:type="wim:PersonAccountExt">
      <wim:identifier uniqueName="uid=person1,dc=yourco,dc=com"/>
      <wim:HomePhone>020-2341123</wim:HomePhone>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>

Ausgabedatengraph nach dem Hinzufügen eines Merkmals mit einem Wert zur Entität:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo" xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:entities xsi:type="wim:PersonAccountExt">
      <wim:identifier externalName="uid=person1,dc=yourco,dc=com" repositoryId="LDAP1"
          uniqueId="cb1ea321-8673-4012-9750-c917d4e7f2f6" uniqueName="uid=person1,dc=yourco,dc=com"/>
      <wim:HomePhone>020-2341123</wim:HomePhone>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>

Eingabedatengraph für die Suche nach dem erweiterten Merkmal:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo" xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:controls xsi:type="wim:SearchControl" expression="@xsi:type='wim:PersonAccountExt'">
      <wim:properties>uid</wim:properties>
      <wim:properties>sn</wim:properties>
      <wim:properties>cn</wim:properties>
      <wim:properties>wim:HomePhone</wim:properties>
    </wim:controls>
  </wim:Root>
</sdo:datagraph>

Ausgabedatengraph nach der Suche nach dem erweiterten Merkmal:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo" xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:entities xsi:type="wim:PersonAccountExt">
      <wim:identifier externalName="uid=person1,dc=yourco,dc=com" repositoryId="LDAP1"
          uniqueId="cb1ea321-8673-4012-9750-c917d4e7f2f6" uniqueName="uid=person1,dc=yourco,dc=com"/>
      <wim:uid>person1</wim:uid>
      <wim:cn>Person 1</wim:cn>
      <wim:sn>Person1LastName</wim:sn>
      <wim:HomePhone>020-2341123</wim:HomePhone>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>


Rechtliche Hinweise | Feedback