Commit 3da93c8d authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

1) VCard mapping is now allowing multiple fields. JM-885

2) Loaded vcards are now updated when LDAP mapping is modified. JM-886

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5899 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2d47858b
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<module version="4" relativePaths="true" type="JAVA_MODULE"> <module version="4" relativePaths="true" type="JAVA_MODULE">
<component name="ModuleRootManager" /> <component name="ModuleRootManager" />
<component name="NewModuleRootManager" inherit-compiler-output="false"> <component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" /> <output url="file://$MODULE_DIR$/work/classes" />
<exclude-output /> <exclude-output />
<exclude-exploded /> <exclude-exploded />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
...@@ -148,10 +148,10 @@ ...@@ -148,10 +148,10 @@
<CLASSES> <CLASSES>
<root url="jar://$MODULE_DIR$/build/lib/merge/dom4j.jar!/" /> <root url="jar://$MODULE_DIR$/build/lib/merge/dom4j.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC />
<root url="http://www.dom4j.org/apidocs/" /> <SOURCES>
</JAVADOC> <root url="file://$MODULE_DIR$/../../java/dom4j-1.6.1/src/java" />
<SOURCES /> </SOURCES>
</library> </library>
</orderEntry> </orderEntry>
<orderEntry type="module-library" exported=""> <orderEntry type="module-library" exported="">
...@@ -334,6 +334,15 @@ ...@@ -334,6 +334,15 @@
<SOURCES /> <SOURCES />
</library> </library>
</orderEntry> </orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../Documents and Settings/gato/.IntelliJIdea60/config/plugins/Clover_for_IDEA_2848.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntryProperties /> <orderEntryProperties />
</component> </component>
</module> </module>
......
...@@ -300,7 +300,8 @@ ...@@ -300,7 +300,8 @@
<module fileurl="file://$PROJECT_DIR$/Wildfire.iml" filepath="$PROJECT_DIR$/Wildfire.iml" /> <module fileurl="file://$PROJECT_DIR$/Wildfire.iml" filepath="$PROJECT_DIR$/Wildfire.iml" />
</modules> </modules>
</component> </component>
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="JDK 1.5.0" /> <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="JDK 1.5.0" project-jdk-type="JavaSDK" />
<component name="ProjectRunConfigurationManager" />
<component name="ProjectRunConfigurationManager" /> <component name="ProjectRunConfigurationManager" />
<component name="RmicSettings"> <component name="RmicSettings">
<option name="IS_EANABLED" value="false" /> <option name="IS_EANABLED" value="false" />
......
...@@ -470,8 +470,8 @@ public class LdapUserProfile { ...@@ -470,8 +470,8 @@ public class LdapUserProfile {
JiveGlobals.setXMLProperty("provider.vcard.className", LdapVCardProvider.class.getName()); JiveGlobals.setXMLProperty("provider.vcard.className", LdapVCardProvider.class.getName());
// Save duplicated fields in LdapManager (should be removed in the future) // Save duplicated fields in LdapManager (should be removed in the future)
LdapManager.getInstance().setNameField(name.replaceAll("(\\{)([\\d\\D]+)(})", "$2")); LdapManager.getInstance().setNameField(name.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));
LdapManager.getInstance().setEmailField(email.replaceAll("(\\{)([\\d\\D]+)(})", "$2")); LdapManager.getInstance().setEmailField(email.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));
} }
/** /**
......
...@@ -282,10 +282,9 @@ public class LdapUserTester { ...@@ -282,10 +282,9 @@ public class LdapUserTester {
public PropertyMapping(String displayFormat) { public PropertyMapping(String displayFormat) {
this.displayFormat = displayFormat; this.displayFormat = displayFormat;
for (String field : displayFormat.trim().split(",")) { StringTokenizer st = new StringTokenizer(displayFormat.trim(), ", //{}");
if (field.trim().startsWith("{")) { while (st.hasMoreTokens()) {
fields.add(field.trim().replaceAll("(\\{)([\\d\\D]+)(})", "$2")); fields.add(st.nextToken().replaceFirst("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));
}
} }
} }
......
...@@ -14,20 +14,14 @@ import org.dom4j.Document; ...@@ -14,20 +14,14 @@ import org.dom4j.Document;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.Node; import org.dom4j.Node;
import org.jivesoftware.util.AlreadyExistsException; import org.jivesoftware.util.*;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.wildfire.vcard.VCardManager;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.wildfire.vcard.VCardProvider; import org.jivesoftware.wildfire.vcard.VCardProvider;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import javax.naming.directory.Attributes; import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext; import javax.naming.directory.DirContext;
import java.text.MessageFormat; import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/** /**
* Read-only LDAP provider for vCards.Configuration consists of adding a provider:<p/> * Read-only LDAP provider for vCards.Configuration consists of adding a provider:<p/>
...@@ -103,13 +97,19 @@ import java.util.Set; ...@@ -103,13 +97,19 @@ import java.util.Set;
* *
* @author rkelly * @author rkelly
*/ */
public class LdapVCardProvider implements VCardProvider { public class LdapVCardProvider implements VCardProvider, PropertyEventListener {
private LdapManager manager; private LdapManager manager;
private VCardTemplate template; private VCardTemplate template;
public LdapVCardProvider() { public LdapVCardProvider() {
manager = LdapManager.getInstance(); manager = LdapManager.getInstance();
initTemplate();
// Listen to property events so that the template is always up to date
PropertyEventDispatcher.addListener(this);
}
private void initTemplate() {
String property = JiveGlobals.getXMLProperty("ldap.vcard-mapping"); String property = JiveGlobals.getXMLProperty("ldap.vcard-mapping");
Log.debug("Found vcard mapping: '" + property); Log.debug("Found vcard mapping: '" + property);
try { try {
...@@ -143,8 +143,7 @@ public class LdapVCardProvider implements VCardProvider { ...@@ -143,8 +143,7 @@ public class LdapVCardProvider implements VCardProvider {
javax.naming.directory.Attribute attr = attrs.get(attribute); javax.naming.directory.Attribute attr = attrs.get(attribute);
String value; String value;
if (attr == null) { if (attr == null) {
Log.debug("No ldap value found for attribute '" + attribute Log.debug("No ldap value found for attribute '" + attribute + "'");
+ "'");
value = ""; value = "";
} }
else { else {
...@@ -197,6 +196,27 @@ public class LdapVCardProvider implements VCardProvider { ...@@ -197,6 +196,27 @@ public class LdapVCardProvider implements VCardProvider {
return true; return true;
} }
public void propertySet(String property, Map params) {
//Ignore
}
public void propertyDeleted(String property, Map params) {
//Ignore
}
public void xmlPropertySet(String property, Map params) {
if ("ldap.vcard-mapping".equals(property)) {
initTemplate();
// Reset cache of vCards
VCardManager.getInstance().reset();
}
}
public void xmlPropertyDeleted(String property, Map params) {
//Ignore
}
/** /**
* Class to hold a <code>Document</code> representation of a vcard mapping * Class to hold a <code>Document</code> representation of a vcard mapping
* and unique attribute placeholders. Used by <code>VCard</code> to apply * and unique attribute placeholders. Used by <code>VCard</code> to apply
...@@ -231,10 +251,11 @@ public class LdapVCardProvider implements VCardProvider { ...@@ -231,10 +251,11 @@ public class LdapVCardProvider implements VCardProvider {
Node node = element.node(i); Node node = element.node(i);
if (node instanceof Element) { if (node instanceof Element) {
Element emement = (Element) node; Element emement = (Element) node;
String[] attrs = emement.getTextTrim().split(",");
for (String string : attrs) { StringTokenizer st = new StringTokenizer(emement.getTextTrim(), ", //{}");
while (st.hasMoreTokens()) {
// Remove enclosing {} // Remove enclosing {}
string = string.replaceAll("(\\{)([\\d\\D]+)(})", "$2"); String string = st.nextToken().replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2");
Log.debug("VCardTemplate: found attribute " + string); Log.debug("VCardTemplate: found attribute " + string);
set.add(string); set.add(string);
} }
...@@ -267,16 +288,20 @@ public class LdapVCardProvider implements VCardProvider { ...@@ -267,16 +288,20 @@ public class LdapVCardProvider implements VCardProvider {
if (node instanceof Element) { if (node instanceof Element) {
Element emement = (Element) node; Element emement = (Element) node;
String[] attrs = emement.getTextTrim().split(","); String elementText = emement.getTextTrim();
Object[] values = new String[attrs.length]; if (elementText != null && !"".equals(elementText)) {
String format = emement.getStringValue(); String format = emement.getStringValue();
for (int j = 0; j < attrs.length; j++) {
StringTokenizer st = new StringTokenizer(elementText, ", //{}");
while (st.hasMoreTokens()) {
// Remove enclosing {} // Remove enclosing {}
String attrib = attrs[j].replaceAll("(\\{)([\\d\\D]+)(})", "$2"); String field = st.nextToken();
values[j] = map.get(attrib); String attrib = field.replaceAll("(\\{)(" + field + ")(})", "$2");
format = format.replaceFirst("(\\{)([\\d\\D]+)(})", "$1" + j + "$3"); String value = map.get(attrib);
format = format.replaceFirst("(\\{)(" + field + ")(})", value);
}
emement.setText(format);
} }
emement.setText(MessageFormat.format(format, values));
treeWalk(emement, map); treeWalk(emement, map);
} }
} }
......
...@@ -286,6 +286,13 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider ...@@ -286,6 +286,13 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
UserEventDispatcher.removeListener(eventHandler); UserEventDispatcher.removeListener(eventHandler);
} }
/**
* Resets the manager state. The cache where loaded vCards are stored will be flushed.
*/
public void reset() {
vcardCache.clear();
}
public Iterator<String> getFeatures() { public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>(); ArrayList<String> features = new ArrayList<String>();
features.add("vcard-temp"); features.add("vcard-temp");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment