Commit 97f8b9ce authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Listen to properties change events and readjust current settings. JM-880

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5840 b35dd754-fafc-0310-a699-88a17e54d16e
parent cf215195
......@@ -16,6 +16,7 @@ import org.jivesoftware.wildfire.user.UserNotFoundException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
/**
* Authentication service.
......@@ -42,9 +43,44 @@ public class AuthFactory {
private static Blowfish cipher = null;
static {
// Create a message digest instance.
try {
digest = MessageDigest.getInstance("SHA");
}
catch (NoSuchAlgorithmException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
// Load an auth provider.
initProvider();
// Detect when a new auth provider class is set
PropertyEventListener propListener = new PropertyEventListener() {
public void propertySet(String property, Map params) {
//Ignore
}
public void propertyDeleted(String property, Map params) {
//Ignore
}
public void xmlPropertySet(String property, Map params) {
if ("provider.auth.className".equals(property)) {
initProvider();
}
}
public void xmlPropertyDeleted(String property, Map params) {
//Ignore
}
};
PropertyEventDispatcher.addListener(propListener);
}
private static void initProvider() {
String className = JiveGlobals.getXMLProperty("provider.auth.className",
"org.jivesoftware.wildfire.auth.DefaultAuthProvider");
// Check if we need to reset the auth provider class
if (authProvider == null || !className.equals(authProvider.getClass().getName())) {
try {
Class c = ClassUtils.forName(className);
authProvider = (AuthProvider)c.newInstance();
......@@ -53,12 +89,6 @@ public class AuthFactory {
Log.error("Error loading auth provider: " + className, e);
authProvider = new DefaultAuthProvider();
}
// Create a message digest instance.
try {
digest = MessageDigest.getInstance("SHA");
}
catch (NoSuchAlgorithmException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
......
......@@ -21,10 +21,7 @@ import org.jivesoftware.wildfire.event.UserEventDispatcher;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.*;
/**
* Manages users, including loading, creating and deleting.
......@@ -53,16 +50,29 @@ public class UserManager implements IQResultListener {
512 * 1024, JiveConstants.MINUTE*30);
CacheManager.initializeCache("Roster", "username2roster", 512 * 1024);
// Load a user provider.
String className = JiveGlobals.getXMLProperty("provider.user.className",
"org.jivesoftware.wildfire.user.DefaultUserProvider");
try {
Class c = ClassUtils.forName(className);
provider = (UserProvider)c.newInstance();
initProvider();
// Detect when a new auth provider class is set
PropertyEventListener propListener = new PropertyEventListener() {
public void propertySet(String property, Map params) {
//Ignore
}
catch (Exception e) {
Log.error("Error loading user provider: " + className, e);
provider = new DefaultUserProvider();
public void propertyDeleted(String property, Map params) {
//Ignore
}
public void xmlPropertySet(String property, Map params) {
if ("provider.user.className".equals(property)) {
initProvider();
}
}
public void xmlPropertyDeleted(String property, Map params) {
//Ignore
}
};
PropertyEventDispatcher.addListener(propListener);
}
/**
......@@ -96,6 +106,7 @@ public class UserManager implements IQResultListener {
*
* @param username the new and unique username for the account.
* @param password the password for the account (plain text).
* @param name the name of the user.
* @param email the email address to associate with the new account, which can
* be <tt>null</tt>.
* @return a new User.
......@@ -387,4 +398,21 @@ public class UserManager implements IQResultListener {
from.toBareJID().intern().notifyAll();
}
}
private static void initProvider() {
String className = JiveGlobals.getXMLProperty("provider.user.className",
"org.jivesoftware.wildfire.user.DefaultUserProvider");
// Check if we need to reset the provider class
if (provider == null || !className.equals(provider.getClass().getName())) {
try {
Class c = ClassUtils.forName(className);
provider = (UserProvider) c.newInstance();
}
catch (Exception e) {
Log.error("Error loading user provider: " + className, e);
provider = new DefaultUserProvider();
}
}
}
}
\ No newline at end of file
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