Commit 808f91f3 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Slightly modified version of vcard changes. Pending Daniel review.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9672 b35dd754-fafc-0310-a699-88a17e54d16e
parent c32604d0
...@@ -507,7 +507,7 @@ public class LdapUserProfile { ...@@ -507,7 +507,7 @@ public class LdapUserProfile {
LdapManager.getInstance().setEmailField(email.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2")); LdapManager.getInstance().setEmailField(email.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));
// Store the DB storage variable in the actual database. // Store the DB storage variable in the actual database.
JiveGlobals.setProperty("ldap.avatarDBStorage", avatarStoredInDB.toString()); JiveGlobals.setProperty("ldap.override.avatar", avatarStoredInDB.toString());
} }
/** /**
...@@ -633,7 +633,7 @@ public class LdapUserProfile { ...@@ -633,7 +633,7 @@ public class LdapUserProfile {
businessDepartment = element.elementTextTrim("ORGUNIT"); businessDepartment = element.elementTextTrim("ORGUNIT");
} }
} }
avatarStoredInDB = JiveGlobals.getBooleanProperty("ldap.avatarDBStorage", false); avatarStoredInDB = JiveGlobals.getBooleanProperty("ldap.override.avatar", false);
} }
catch (DocumentException e) { catch (DocumentException e) {
Log.error("Error loading vcard mappings from property", e); Log.error("Error loading vcard mappings from property", e);
......
...@@ -105,7 +105,8 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener { ...@@ -105,7 +105,8 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener {
private Boolean dbStorageEnabled = false; private Boolean dbStorageEnabled = false;
/** /**
* The default vCard provider is used to handle the vCard in the database. * The default vCard provider is used to handle the vCard in the database. vCard
* fields that can be overriden are stored in the database.
* *
* This is used/created only if we are storing avatars in the database. * This is used/created only if we are storing avatars in the database.
*/ */
...@@ -116,11 +117,10 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener { ...@@ -116,11 +117,10 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener {
initTemplate(); initTemplate();
// Listen to property events so that the template is always up to date // Listen to property events so that the template is always up to date
PropertyEventDispatcher.addListener(this); PropertyEventDispatcher.addListener(this);
// If avatars will be loaded from the database, load the DefaultVCardProvider // DB vcard provider used for loading properties overwritten in the DB
if (JiveGlobals.getBooleanProperty("ldap.avatarDBStorage", false)) { defaultProvider = new DefaultVCardProvider();
defaultProvider = new DefaultVCardProvider(); // Check of avatars can be overwritten (and stored in the database)
dbStorageEnabled = true; dbStorageEnabled = JiveGlobals.getBooleanProperty("ldap.override.avatar", false);
}
} }
/** /**
...@@ -251,18 +251,9 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener { ...@@ -251,18 +251,9 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener {
* @param vCardElement vCard element containing the new vcard. * @param vCardElement vCard element containing the new vcard.
* @throws UnsupportedOperationException If an invalid field is changed or we are in readonly mode. * @throws UnsupportedOperationException If an invalid field is changed or we are in readonly mode.
*/ */
public void createVCard(String username, Element vCardElement) throws UnsupportedOperationException { public void createVCard(String username, Element vCardElement)
if (dbStorageEnabled && defaultProvider != null) { throws UnsupportedOperationException, AlreadyExistsException {
if (isValidVCardChange(username, vCardElement)) { throw new UnsupportedOperationException("LdapVCardProvider: VCard changes not allowed.");
updateOrCreateVCard(username, vCardElement);
}
else {
throw new UnsupportedOperationException("LdapVCardProvider: Invalid vcard changes.");
}
}
else {
throw new UnsupportedOperationException("LdapVCardProvider: VCard changes not allowed.");
}
} }
/** /**
...@@ -275,7 +266,15 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener { ...@@ -275,7 +266,15 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener {
public void updateVCard(String username, Element vCardElement) throws UnsupportedOperationException { public void updateVCard(String username, Element vCardElement) throws UnsupportedOperationException {
if (dbStorageEnabled && defaultProvider != null) { if (dbStorageEnabled && defaultProvider != null) {
if (isValidVCardChange(username, vCardElement)) { if (isValidVCardChange(username, vCardElement)) {
updateOrCreateVCard(username, vCardElement); try {
defaultProvider.updateVCard(username, vCardElement);
} catch (NotFoundException e) {
try {
defaultProvider.createVCard(username, vCardElement);
} catch (AlreadyExistsException e1) {
// Ignore
}
}
} }
else { else {
throw new UnsupportedOperationException("LdapVCardProvider: Invalid vcard changes."); throw new UnsupportedOperationException("LdapVCardProvider: Invalid vcard changes.");
...@@ -293,41 +292,7 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener { ...@@ -293,41 +292,7 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener {
* @throws UnsupportedOperationException If an invalid field is changed or we are in readonly mode. * @throws UnsupportedOperationException If an invalid field is changed or we are in readonly mode.
*/ */
public void deleteVCard(String username) throws UnsupportedOperationException { public void deleteVCard(String username) throws UnsupportedOperationException {
if (dbStorageEnabled && defaultProvider != null) { throw new UnsupportedOperationException("LdapVCardProvider: Attempted to delete vcard in read-only mode.");
defaultProvider.deleteVCard(username);
}
else {
throw new UnsupportedOperationException("LdapVCardProvider: Attempted to delete vcard in read-only mode.");
}
}
/**
* Updates or creates a local copy of the passed vcard.
*
* @param username User we are setting the vcard for.
* @param vCardElement vCard element we are storing.
*/
private void updateOrCreateVCard(String username, Element vCardElement) {
Element vcard = vCardElement.createCopy();
// Trim away everything but the PHOTO element
for (Object obj : vcard.elements()) {
Element elem = (Element)obj;
if (!elem.getName().equals("PHOTO")) {
vcard.remove(elem);
}
}
// If the vcard exists, update it, otherwise create it.
try {
defaultProvider.createVCard(username, vcard);
}
catch (AlreadyExistsException e) {
try {
defaultProvider.updateVCard(username, vcard);
}
catch (NotFoundException ee) {
Log.error("LdapVCardProvider: Unable to find vcard, despite having been told it existed.");
}
}
} }
/** /**
...@@ -538,29 +503,14 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener { ...@@ -538,29 +503,14 @@ public class LdapVCardProvider implements VCardProvider, PropertyEventListener {
} }
public void propertySet(String property, Map params) { public void propertySet(String property, Map params) {
if ("ldap.vcardDBStorage".equals(property)) { if ("ldap.override.avatar".equals(property)) {
Boolean enabled = Boolean.parseBoolean((String)params.get("value")); dbStorageEnabled = Boolean.parseBoolean((String)params.get("value"));
if (enabled) {
if (defaultProvider == null) {
defaultProvider = new DefaultVCardProvider();
dbStorageEnabled = true;
}
}
else {
if (defaultProvider != null) {
dbStorageEnabled = false;
defaultProvider = null;
}
}
} }
} }
public void propertyDeleted(String property, Map params) { public void propertyDeleted(String property, Map params) {
if ("ldap.vcardDBStorage".equals(property)) { if ("ldap.override.avatar".equals(property)) {
if (defaultProvider != null) { dbStorageEnabled = false;
dbStorageEnabled = false;
defaultProvider = null;
}
} }
} }
......
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
// Store the vcard db setting for later saving. // Store the vcard db setting for later saving.
Map<String,String> xmppSettings = (Map<String,String>)session.getAttribute("xmppSettings"); Map<String,String> xmppSettings = (Map<String,String>)session.getAttribute("xmppSettings");
if (xmppSettings != null) { if (xmppSettings != null) {
xmppSettings.put("ldap.avatarDBStorage", vcardBean.getAvatarStoredInDB().toString()); xmppSettings.put("ldap.override.avatar", vcardBean.getAvatarStoredInDB().toString());
session.setAttribute("xmppSettings", xmppSettings); session.setAttribute("xmppSettings", xmppSettings);
} }
......
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