Improved: General refactoring and code improvements, package
org.apache.ofbiz.common.authentication. (OFBIZ-9875) Thanks Julian Leichert for reporting and providing the patch. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1817751 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+27
-11
@@ -38,13 +38,18 @@ import org.apache.ofbiz.service.LocalDispatcher;
|
||||
public final class AuthHelper {
|
||||
|
||||
private static final String module = AuthHelper.class.getName();
|
||||
private static List<Authenticator> authenticators = new ArrayList<Authenticator>();
|
||||
private static List<Authenticator> authenticators = new ArrayList<>();
|
||||
private static boolean authenticatorsLoaded = false;
|
||||
|
||||
private AuthHelper() {}
|
||||
private AuthHelper() {
|
||||
}
|
||||
|
||||
public static boolean authenticate(String username, String password, boolean isServiceAuth) throws AuthenticatorException {
|
||||
if (!authenticatorsLoaded) throw new AuthenticatorException("Authenticators never loaded; be sure to call AuthHelper.loadAuthenticators()");
|
||||
public static boolean authenticate(String username, String password, boolean isServiceAuth)
|
||||
throws AuthenticatorException {
|
||||
if (!authenticatorsLoaded) {
|
||||
throw new AuthenticatorException(
|
||||
"Authenticators never loaded; be sure to call AuthHelper.loadAuthenticators()");
|
||||
}
|
||||
for (Authenticator auth : authenticators) {
|
||||
boolean pass = auth.authenticate(username, password, isServiceAuth);
|
||||
if (pass) {
|
||||
@@ -57,14 +62,20 @@ public final class AuthHelper {
|
||||
}
|
||||
|
||||
public static void logout(String username) throws AuthenticatorException {
|
||||
if (!authenticatorsLoaded) throw new AuthenticatorException("Authenticators never loaded; be sure to call AuthHelper.loadAuthenticators()");
|
||||
if (!authenticatorsLoaded) {
|
||||
throw new AuthenticatorException(
|
||||
"Authenticators never loaded; be sure to call AuthHelper.loadAuthenticators()");
|
||||
}
|
||||
for (Authenticator auth : authenticators) {
|
||||
auth.logout(username);
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncUser(String username) throws AuthenticatorException {
|
||||
if (!authenticatorsLoaded) throw new AuthenticatorException("Authenticators never loaded; be sure to call AuthHelper.loadAuthenticators()");
|
||||
if (!authenticatorsLoaded) {
|
||||
throw new AuthenticatorException(
|
||||
"Authenticators never loaded; be sure to call AuthHelper.loadAuthenticators()");
|
||||
}
|
||||
for (Authenticator auth : authenticators) {
|
||||
if (auth.isUserSynchronized()) {
|
||||
auth.syncUser(username);
|
||||
@@ -72,8 +83,12 @@ public final class AuthHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updatePassword(String username, String password, String newPassword) throws AuthenticatorException {
|
||||
if (!authenticatorsLoaded) throw new AuthenticatorException("Authenticators never loaded; be sure to call AuthHelper.loadAuthenticators()");
|
||||
public static void updatePassword(String username, String password, String newPassword)
|
||||
throws AuthenticatorException {
|
||||
if (!authenticatorsLoaded) {
|
||||
throw new AuthenticatorException(
|
||||
"Authenticators never loaded; be sure to call AuthHelper.loadAuthenticators()");
|
||||
}
|
||||
for (Authenticator auth : authenticators) {
|
||||
auth.updatePassword(username, password, newPassword);
|
||||
}
|
||||
@@ -109,9 +124,10 @@ public final class AuthHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/* Do not move this into a shared global util class; doing so
|
||||
* would mean the method would have to be public, and then it
|
||||
* could be called by any other non-secure source.
|
||||
/*
|
||||
* Do not move this into a shared global util class; doing so would mean the
|
||||
* method would have to be public, and then it could be called by any other
|
||||
* non-secure source.
|
||||
*/
|
||||
private static ClassLoader getContextClassLoader() {
|
||||
return AccessController.doPrivileged(
|
||||
|
||||
Reference in New Issue
Block a user