Class LdapVCardProvider

  • All Implemented Interfaces:
    VCardProvider, PropertyEventListener

    public class LdapVCardProvider
    extends Object
    implements VCardProvider, PropertyEventListener
    Read-only LDAP provider for vCards.Configuration consists of adding a provider:

    provider.vcard.className = org.jivesoftware.openfire.ldap.LdapVCardProvider

    and an xml vcard-mapping in the system properties.

    The vcard attributes can be configured by adding an attrs="attr1,attr2" attribute to the vcard elements.

    Arbitrary text can be used for the element values as well as MessageFormat style placeholders for the ldap attributes. For example, if you wanted to map the LDAP attribute displayName to the vcard element FN, the xml nippet would be:


    <FN attrs="displayName">{0}</FN>

    The vCard XML must be escaped in CDATA and must also be well formed. It is the exact XML this provider will send to a client after after stripping attr attributes and populating the placeholders with the data retrieved from LDAP. This system should be flexible enough to handle any client's vCard format. An example mapping follows.

    ldap.vcard-mapping = &lt;![CDATA[ &lt;vCard xmlns='vcard-temp'&gt; &lt;FN attrs=&quot;displayName&quot;&gt;{0}&lt;/FN&gt; &lt;NICKNAME attrs=&quot;uid&quot;&gt;{0}&lt;/NICKNAME&gt; &lt;BDAY attrs=&quot;dob&quot;&gt;{0}&lt;/BDAY&gt; &lt;ADR&gt; &lt;HOME/&gt; &lt;EXTADR&gt;Ste 500&lt;/EXTADR&gt; &lt;STREET&gt;317 SW Alder St&lt;/STREET&gt; &lt;LOCALITY&gt;Portland&lt;/LOCALITY&gt; &lt;REGION&gt;Oregon&lt;/REGION&gt; &lt;PCODE&gt;97204&lt;/PCODE&gt; &lt;CTRY&gt;USA&lt;/CTRY&gt; &lt;/ADR&gt; &lt;TEL&gt; &lt;HOME/&gt; &lt;VOICE/&gt; &lt;NUMBER attrs=&quot;telephoneNumber&quot;&gt;{0}&lt;/NUMBER&gt; &lt;/TEL&gt; &lt;EMAIL&gt; &lt;INTERNET/&gt; &lt;USERID attrs=&quot;mail&quot;&gt;{0}&lt;/USERID&gt; &lt;/EMAIL&gt; &lt;TITLE attrs=&quot;title&quot;&gt;{0}&lt;/TITLE&gt; &lt;ROLE attrs=&quot;&quot;&gt;{0}&lt;/ROLE&gt; &lt;ORG&gt; &lt;ORGNAME attrs=&quot;o&quot;&gt;{0}&lt;/ORGNAME&gt; &lt;ORGUNIT attrs=&quot;&quot;&gt;{0}&lt;/ORGUNIT&gt; &lt;/ORG&gt; &lt;URL attrs=&quot;labeledURI&quot;&gt;{0}&lt;/URL&gt; &lt;DESC attrs=&quot;uidNumber,homeDirectory,loginShell&quot;&gt; uid: {0} home: {1} shell: {2} &lt;/DESC&gt; &lt;/vCard&gt; ]]&gt;

    An easy way to get the vcard format your client needs, assuming you've been using the database store, is to do a SELECT value FROM ofVCard WHERE username='some_user' in your favorite sql querier and paste the result into the vcard-mapping (don't forget the CDATA).

    Author:
    rkelly
    • Field Detail

      • PATTERN

        public static final Pattern PATTERN
        A regular expression that matches values enclosed in { and }, applying a group to the value that's surrounded.
    • Constructor Detail

      • LdapVCardProvider

        public LdapVCardProvider()
    • Method Detail

      • loadVCard

        public org.dom4j.Element loadVCard​(String username)
        Loads the avatar from LDAP, based off the vcard template. If enabled, will replace a blank PHOTO element with one from a DB stored vcard.
        Specified by:
        loadVCard in interface VCardProvider
        Parameters:
        username - User we are loading the vcard for.
        Returns:
        The loaded vcard element, or null if none found.
      • updateVCard

        public org.dom4j.Element updateVCard​(String username,
                                             org.dom4j.Element vCardElement)
                                      throws UnsupportedOperationException
        Handles when a user updates their vcard.
        Specified by:
        updateVCard in interface VCardProvider
        Parameters:
        username - User that updated their vcard.
        vCardElement - vCard element containing the new vcard.
        Returns:
        vCard as it is after the provider has a chance to adjust it.
        Throws:
        UnsupportedOperationException - If an invalid field is changed or we are in readonly mode.
      • isReadOnly

        public boolean isReadOnly()
        Description copied from interface: VCardProvider
        Returns true if this VCardProvider is read-only. When read-only, vcards can not be created, deleted, or modified.
        Specified by:
        isReadOnly in interface VCardProvider
        Returns:
        true if the vcard provider is read-only.
      • propertySet

        public void propertySet​(String property,
                                Map params)
        Description copied from interface: PropertyEventListener
        A property was set. The parameter map params will contain the the value of the property under the key value.
        Specified by:
        propertySet in interface PropertyEventListener
        Parameters:
        property - the name of the property.
        params - event parameters.
      • xmlPropertySet

        public void xmlPropertySet​(String property,
                                   Map params)
        Description copied from interface: PropertyEventListener
        An XML property was set. The parameter map params will contain the the value of the property under the key value.
        Specified by:
        xmlPropertySet in interface PropertyEventListener
        Parameters:
        property - the name of the property.
        params - event parameters.