Class LdapVCardProvider
- All Implemented Interfaces:
VCardProvider
,PropertyEventListener
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 =
<![CDATA[
<vCard xmlns='vcard-temp'>
<FN attrs="displayName">{0}</FN>
<NICKNAME attrs="uid">{0}</NICKNAME>
<BDAY attrs="dob">{0}</BDAY>
<ADR>
<HOME/>
<EXTADR>Ste 500</EXTADR>
<STREET>317 SW Alder St</STREET>
<LOCALITY>Portland</LOCALITY>
<REGION>Oregon</REGION>
<PCODE>97204</PCODE>
<CTRY>USA</CTRY>
</ADR>
<TEL>
<HOME/>
<VOICE/>
<NUMBER attrs="telephoneNumber">{0}</NUMBER>
</TEL>
<EMAIL>
<INTERNET/>
<USERID attrs="mail">{0}</USERID>
</EMAIL>
<TITLE attrs="title">{0}</TITLE>
<ROLE attrs="">{0}</ROLE>
<ORG>
<ORGNAME attrs="o">{0}</ORGNAME>
<ORGUNIT attrs="">{0}</ORGUNIT>
</ORG>
<URL attrs="labeledURI">{0}</URL>
<DESC attrs="uidNumber,homeDirectory,loginShell">
uid: {0} home: {1} shell: {2}
</DESC>
</vCard>
]]>
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Pattern
A regular expression that matches values enclosed in { and }, applying a group to the value that's surrounded.static final SystemProperty<Boolean>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.dom4j.Element
createVCard
(String username, org.dom4j.Element vCardElement) Handles when a user creates a new vcard.void
deleteVCard
(String username) Handles when a user deletes their vcard.boolean
Returns true if this VCardProvider is read-only.org.dom4j.Element
Loads the avatar from LDAP, based off the vcard template.void
propertyDeleted
(String property, Map<String, Object> params) A property was deleted.void
propertySet
(String property, Map<String, Object> params) A property was set.org.dom4j.Element
updateVCard
(String username, org.dom4j.Element vCardElement) Handles when a user updates their vcard.void
xmlPropertyDeleted
(String property, Map<String, Object> params) An XML property was deleted.void
xmlPropertySet
(String property, Map<String, Object> params) An XML property was set.
-
Field Details
-
STORE_AVATAR_IN_DB
-
PATTERN
A regular expression that matches values enclosed in { and }, applying a group to the value that's surrounded.
-
-
Constructor Details
-
LdapVCardProvider
public LdapVCardProvider()
-
-
Method Details
-
loadVCard
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 interfaceVCardProvider
- Parameters:
username
- User we are loading the vcard for.- Returns:
- The loaded vcard element, or null if none found.
-
createVCard
public org.dom4j.Element createVCard(String username, org.dom4j.Element vCardElement) throws UnsupportedOperationException, AlreadyExistsException Handles when a user creates a new vcard.- Specified by:
createVCard
in interfaceVCardProvider
- Parameters:
username
- User that created a new 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.AlreadyExistsException
- if the user already has a vCard.
-
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 interfaceVCardProvider
- 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.
-
deleteVCard
Handles when a user deletes their vcard.- Specified by:
deleteVCard
in interfaceVCardProvider
- Parameters:
username
- User that deketed their vcard.- 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 interfaceVCardProvider
- Returns:
- true if the vcard provider is read-only.
-
propertySet
Description copied from interface:PropertyEventListener
A property was set. The parameter mapparams
will contain the the value of the property under the keyvalue
.- Specified by:
propertySet
in interfacePropertyEventListener
- Parameters:
property
- the name of the property.params
- event parameters.
-
propertyDeleted
Description copied from interface:PropertyEventListener
A property was deleted.- Specified by:
propertyDeleted
in interfacePropertyEventListener
- Parameters:
property
- the name of the property deleted.params
- event parameters.
-
xmlPropertySet
Description copied from interface:PropertyEventListener
An XML property was set. The parameter mapparams
will contain the the value of the property under the keyvalue
.- Specified by:
xmlPropertySet
in interfacePropertyEventListener
- Parameters:
property
- the name of the property.params
- event parameters.
-
xmlPropertyDeleted
Description copied from interface:PropertyEventListener
An XML property was deleted.- Specified by:
xmlPropertyDeleted
in interfacePropertyEventListener
- Parameters:
property
- the name of the property.params
- event parameters.
-