Commit 94e06b46 authored by Tom Evans's avatar Tom Evans

OF-750: Initial refactor to prepare for password hashing mechanism(s)

Deprecate AuthFactory.getAuthProvider() and remove references from core
classes
parent cf25c8cc
......@@ -115,11 +115,33 @@ public class AuthFactory {
* only provided for special-case logic.
*
* @return the current UserProvider.
* @deprecated Prefer using the corresponding factory method, rather than
* invoking methods on the provider directly
*/
public static AuthProvider getAuthProvider() {
return authProvider;
}
/**
* Returns whether the currently-installed AuthProvider is instance of a specific class.
* @param c the class to compare with
* @return true - if the currently-installed AuthProvider is instance of c, false otherwise.
*/
public static boolean isProviderInstanceOf(Class<?> c) {
return c.isInstance(authProvider);
}
/**
* Returns true if the currently installed {@link AuthProvider} supports password
* retrieval. Certain implementation utilize password hashes and other authentication
* mechanisms that do not require the original password.
*
* @return true if plain password retrieval is supported.
*/
public static boolean supportsPasswordRetrieval() {
return authProvider.supportsPasswordRetrieval();
}
/**
* Returns true if the currently installed {@link AuthProvider} supports authentication
* using plain-text passwords according to JEP-0078. Plain-text authentication is
......@@ -156,6 +178,21 @@ public class AuthFactory {
return authProvider.getPassword(username.toLowerCase());
}
/**
* Sets the users's password. This method should throw an UnsupportedOperationException
* if this operation is not supported by the backend user store.
*
* @param username the username of the user.
* @param password the new plaintext password for the user.
* @throws UserNotFoundException if the given user could not be loaded.
* @throws UnsupportedOperationException if the provider does not
* support the operation (this is an optional operation).
*/
public static void setPassword(String username, String password) throws UserNotFoundException,
UnsupportedOperationException, ConnectionException, InternalUnauthenticatedException {
authProvider.setPassword(username, password);
}
/**
* Authenticates a user with a username and plain text password and returns and
* AuthToken. If the username and password do not match the record of
......
......@@ -527,7 +527,7 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
* @return true if Clearspace is being used as the backend of Openfire.
*/
public static boolean isEnabled() {
return AuthFactory.getAuthProvider() instanceof ClearspaceAuthProvider;
return AuthFactory.isProviderInstanceOf(ClearspaceAuthProvider.class);
}
@Override
......
......@@ -90,7 +90,7 @@ public class AuthenticateUser extends AdHocCommand {
}
try {
AuthFactory.getAuthProvider().authenticate(user.getUsername(), password);
AuthFactory.authenticate(user.getUsername(), password);
}
catch (UnauthorizedException e) {
// Auth failed
......
......@@ -756,7 +756,7 @@ public class SASLAuthentication {
if (mech.equals("CRAM-MD5") || mech.equals("DIGEST-MD5")) {
// Check if the user provider in use supports passwords retrieval. Accessing
// to the users passwords will be required by the CallbackHandler
if (!AuthFactory.getAuthProvider().supportsPasswordRetrieval()) {
if (!AuthFactory.supportsPasswordRetrieval()) {
it.remove();
}
}
......
......@@ -40,6 +40,8 @@ import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.AuthFactory;
import org.jivesoftware.openfire.auth.ConnectionException;
import org.jivesoftware.openfire.auth.InternalUnauthenticatedException;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.util.StringUtils;
......@@ -181,7 +183,7 @@ public class User implements Cacheable, Externalizable, Result {
}
try {
AuthFactory.getAuthProvider().setPassword(username, password);
AuthFactory.setPassword(username, password);
// Fire event.
Map<String,Object> params = new HashMap<String,Object>();
......@@ -189,9 +191,13 @@ public class User implements Cacheable, Externalizable, Result {
UserEventDispatcher.dispatchEvent(this, UserEventDispatcher.EventType.user_modified,
params);
}
catch (UserNotFoundException unfe) {
Log.error(unfe.getMessage(), unfe);
}
catch (UserNotFoundException e) {
Log.error(e.getMessage(), e);
} catch (ConnectionException e) {
Log.error(e.getMessage(), e);
} catch (InternalUnauthenticatedException e) {
Log.error(e.getMessage(), e);
}
}
public String getName() {
......
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