Server

HOWTO: Add Custom LDAP Fields to the UI

Updated: March 18, 2024

To add a custom LDAP fields to the User interface you have to:

  1. Create a custom schema based on nuxeo's user.xsd schema with custom fields related to the fields in your LDAP system.

    schemas/myuser.xsd

     <?xml version="1.0"?>
     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:nxs="http://www.nuxeo.org/ecm/schemas/myuser"
        targetNamespace="http://www.nuxeo.org/ecm/schemas/myuser">
    
      <xs:include schemaLocation="base.xsd" />
    
      <xs:element name="username" type="xs:string" />
      <xs:element name="password" type="xs:string" />
      <xs:element name="email" type="xs:string" />
      <xs:element name="firstName" type="xs:string" />
      <xs:element name="lastName" type="xs:string" />
      <xs:element name="company" type="xs:string" />
      <!-- your custom telephone field -->
      <xs:element name="telephone" type="xs:string" />
    
      <xs:element name="groups" type="nxs:stringList" />
    
     </xs:schema>
    

  2. Add your schema via Nuxeo's extension system.

    OSGI-INF/schema-contrib.xml

     <?xml version="1.0"?>
     <component name="com.example.myproject.myuser.schema">
      <extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
        <schema name="myuser" src="schemas/myuser.xsd" />
      </extension>
     </component>
    
    

  3. Modify your LDAP configuration file in Nuxeo (default-ldap-users-directory-bundle.xml) to include:

    1. your custom schema,

      default-ldap-users-directory-bundle.xml

        <extension target="org.nuxeo.ecm.directory.ldap.LDAPDirectoryFactory"
          point="directories">
      
          <directory name="userDirectory">
            <server>default</server>
            <!-- association between your custom schema and the directory -->
            <schema>myuser</schema>
      
      

    2. mapping between your schema and your LDAP fields.

      default-ldap-users-directory-bundle.xml (continued)

            <fieldMapping name="username">uid</fieldMapping>
            <fieldMapping name="password">userPassword</fieldMapping>
            <fieldMapping name="firstName">givenName</fieldMapping>
            <fieldMapping name="lastName">sn</fieldMapping>
            <fieldMapping name="company">o</fieldMapping>
            <fieldMapping name="email">mail</fieldMapping>
            <fieldMapping name="telephone">telephoneNumber</fieldMapping>
      
      

  4. Modify the UI.

    1. Add your custom widget to the layout.

      default-ldap-users-directory-bundle.xml(continued)

       <extension target="org.nuxeo.ecm.platform.forms.layout.WebLayoutManager"
          point="layouts">
      
          <layout name="user">
            <templates>
              <template mode="any">/layouts/layout_default_template.xhtml</template>
            </templates>
            <rows>
              <row>
                <widget>username</widget>
              </row>
            <row>
            <!-- your custom telephone widget-->
                <widget>telephone</widget>
              </row>
      
      

    2. Define a new widget for your custom field to be used in the layout above.

      default-ldap-users-directory-bundle.xml(continued)

       <widget name="telephone" type="text">
       <labels>
       <label mode="any">telephone</label>
       </labels>
       <translated>true</translated>
       <fields>
       <field schema="myuser">telephone</field>
       </fields>
       <widgetModes>
       <mode value="editPassword">hidden</mode>
       </widgetModes>
       <properties widgetMode="edit">
       <property name="required">true</property>
       <property name="styleClass">dataInputText</property>
       </properties>
       </widget>