Express (Distributed operating systems), v8.0 > Secure applications and their environment > Authenticate users > Select a registry or repository > Manage realms in a federated repository > Virtual member manager > Develop with virtual member manager > Integrate virtual member manager into the application > Sample code


Sample code for extending the schema in an LDAP repository

Use the sample code snippet and data graphs to extend the schema in an LDAP repository.

The following sample code snippet and data graphs show how to extend the schema in an LDAP repository by using the propertySchema data object. The steps covered in this sample code snippet are:

  1. Add a virtual member manager property, contactNumber, to the PersonAccount entity type.
  2. Map the contactNumber property to the primaryOwnerContact attribute in the LDAP repository.


Prerequisites

Ensure that we have read the information and completed the steps described in the topic, Program prerequisites, including the section, Extend property schema, which has information about propertySchema and extensionPropertySchema data objects and lists the valid syntax for property data types.

We must have an LDAP repository configured in the federated repositories configuration. See the topic Configure LDAP in a federated repository in the WAS information center. In the following sample code the ID of the LDAP repository configured in the federated repositories configuration is LDAP1.


Sample code

Add the following code snippet to the application code and replace the variables with the actual values to use.

DataObject root = SDOHelper.createRootDataObject();
// Create a new "schema" object under root
// This object will contain the details of the schema modifications that need 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 values for the property viz. namespace URI, namespace prefix, property name propertySchema.setString(SchemaConstants.PROP_PROPERTY_NAME, "contactNumber");
propertySchema.setString(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
// Specify the property is not multi-valued (if it is multi-valued, its type must be List)
propertySchema.setBoolean(SchemaConstants.PROP_MULTI_VALUED, false);
// Specify the data type of the property // Data types can be simple like boolean, int, float, double, String // or special like Address, Person, Group, etc.
propertySchema.setString(SchemaConstants.PROP_DATA_TYPE, SchemaConstants.DATA_TYPE_STRING);
// Add entity types to the list of applicable entity types for this property // This will add the property for all the entity types in the list propertySchema.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES).add(Service.DO_PERSON_ACCOUNT);
// Map the new property to LDAP attribute, ‘primaryOwnerContact', for LDAP repository, "LDAP1", only.
// For other repositories it will be mapped to the same name.
DataObject metaDataDO = propertySchema.createDataObject(SchemaConstants.DO_META_DATA);
metaDataDO.set(SchemaConstants.PROP_REPOSITORY_ID, "LDAP1");
metaDataDO.set(SchemaConstants.PROP_NAME, SchemaConstants.META_REPOSITORY_PROPERTY_NAME);
metaDataDO.getList(SchemaConstants.PROP_VALUES).add("primaryOwnerContact");
// Invoke the create schema API to actually add the property definition to the schema model
DataObject outRoot = service.createSchema(root);
System.out.println("\nCLIENT: new property is created.");


Input and output data graphs

Input data graph for adding property:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:schema>
<wim:propertySchema nsURI="//www.ibm.com/websphere/wim" dataType="String"
          multiValued="false" propertyName="contactNumber">  
<wim:applicableEntityTypeNames>PersonAccount
</wim:applicableEntityTypeNames>  
<wim:metaData name="repositoryPropertyName" repositoryId="LDAP1">    
<wim:values>primaryOwnerContact
</wim:values>  
</wim:metaData>
</wim:propertySchema>
</wim:schema>
</wim:Root>
</sdo:datagraph> 

Output data graph after adding property:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:schema>
<wim:propertySchema nsURI="//www.ibm.com/websphere/wim" dataType="String"
          multiValued="false" propertyName="contactNumber">  
<wim:repositoryIds>LDAP1
</wim:repositoryIds>  
<wim:applicableEntityTypeNames>PersonAccount
</wim:applicableEntityTypeNames>  
<wim:metaData name="repositoryPropertyName" repositoryId="LDAP1">    
<wim:values>primaryOwnerContact
</wim:values>  
</wim:metaData>
</wim:propertySchema>
</wim:schema>
</wim:Root>
</sdo:datagraph> 

Parent topic: Sample code



+

Search Tips   |   Advanced Search