From 269c5043ab8f66f67d5719ac5149a436ca1baa2b Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Fri, 29 Nov 2013 11:05:51 -0500 Subject: [PATCH] Extract Federation, Gitblit and Services manager from GitBlit singleton --- src/main/java/com/gitblit/HtpasswdUserService.java | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/gitblit/HtpasswdUserService.java b/src/main/java/com/gitblit/HtpasswdUserService.java index 62198f4..ca5295c 100644 --- a/src/main/java/com/gitblit/HtpasswdUserService.java +++ b/src/main/java/com/gitblit/HtpasswdUserService.java @@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.Constants.AccountType; +import com.gitblit.manager.IRuntimeManager; import com.gitblit.models.UserModel; import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.StringUtils; @@ -40,7 +41,7 @@ /** * Implementation of a user service using an Apache htpasswd file for authentication. - * + * * This user service implement custom authentication using entries in a file created * by the 'htpasswd' program of an Apache web server. All possible output * options of the 'htpasswd' program version 2.2 are supported: @@ -48,7 +49,7 @@ * glibc crypt() (not on Windows and NetWare), * Apache MD5 (apr1), * unsalted SHA-1. - * + * * Configuration options: * realm.htpasswd.backingUserService - Specify the backing user service that is used * to keep the user data other than the password. @@ -59,7 +60,7 @@ * realm.htpasswd.overrideLocalAuthentication - Specify if local accounts are overwritten * when authentication matches for an * external account. - * + * * @author Florian Zschocke * */ @@ -79,6 +80,7 @@ private final boolean SUPPORT_PLAINTEXT_PWD; + private IRuntimeManager runtimeManager; private IStoredSettings settings; private File htpasswdFile; @@ -110,23 +112,24 @@ /** * Setup the user service. - * + * * The HtpasswdUserService extends the GitblitUserService and is thus * backed by the available user services provided by the GitblitUserService. * In addition the setup tries to read and parse the htpasswd file to be used * for authentication. - * - * @param settings - * @since 0.7.0 + * + * @param runtimeManager + * @since 1.4.0 */ @Override - public void setup(IStoredSettings settings) + public void setup(IRuntimeManager runtimeManager) { - this.settings = settings; + this.runtimeManager = runtimeManager; + this.settings = runtimeManager.getSettings(); // This is done in two steps in order to avoid calling GitBlit.getFileOrFolder(String, String) which will segfault for unit tests. String file = settings.getString(KEY_BACKING_US, DEFAULT_BACKING_US); - File realmFile = GitBlit.getFileOrFolder(file); + File realmFile = runtimeManager.getFileOrFolder(file); serviceImpl = createUserService(realmFile); logger.info("Htpasswd User Service backed by " + serviceImpl.toString()); @@ -238,9 +241,9 @@ /** * Determine if the account is to be treated as a local account. - * + * * This influences authentication. A local account will be authenticated - * by the backing user service while an external account will be handled + * by the backing user service while an external account will be handled * by this user service. * <br/> * The decision also depends on the setting of the key @@ -254,7 +257,8 @@ * If the key is set to false, then it is determined if the account is local * according to the logic of the GitblitUserService. */ - protected boolean isLocalAccount(String username) + @Override + protected boolean isLocalAccount(String username) { if ( settings.getBoolean(KEY_OVERRIDE_LOCALAUTH, DEFAULT_OVERRIDE_LOCALAUTH) ) { read(); @@ -270,7 +274,8 @@ * * @return AccountType.HTPASSWD */ - protected AccountType getAccountType() + @Override + public AccountType getAccountType() { return AccountType.HTPASSWD; } @@ -289,7 +294,7 @@ if ( !file.equals(htpasswdFilePath) ) { // The htpasswd file setting changed. Rediscover the file. this.htpasswdFilePath = file; - this.htpasswdFile = GitBlit.getFileOrFolder(file); + this.htpasswdFile = runtimeManager.getFileOrFolder(file); this.htUsers.clear(); this.forceReload = true; } -- Gitblit v1.9.1