]> source.dussan.org Git - gitblit.git/commitdiff
Centralize cookie creation
authorJames Moger <james.moger@gitblit.com>
Wed, 11 Dec 2013 14:08:26 +0000 (09:08 -0500)
committerJames Moger <james.moger@gitblit.com>
Wed, 11 Dec 2013 14:08:26 +0000 (09:08 -0500)
Change-Id: I1a17416121764f33a8d05a88c80cece0c03ac41d

src/main/java/com/gitblit/auth/AuthenticationProvider.java
src/main/java/com/gitblit/auth/HtpasswdAuthProvider.java
src/main/java/com/gitblit/auth/LdapAuthProvider.java
src/main/java/com/gitblit/auth/PAMAuthProvider.java
src/main/java/com/gitblit/auth/RedmineAuthProvider.java
src/main/java/com/gitblit/auth/SalesforceAuthProvider.java
src/main/java/com/gitblit/auth/WindowsAuthProvider.java

index cb970cc6e72d067077d3a2ee5539dfe58a7c5507..f7b75fa34e55db6573863857cd4cc30a634ec4e3 100644 (file)
@@ -26,6 +26,8 @@ import com.gitblit.manager.IRuntimeManager;
 import com.gitblit.manager.IUserManager;
 import com.gitblit.models.TeamModel;
 import com.gitblit.models.UserModel;
+import com.gitblit.utils.ArrayUtils;
+import com.gitblit.utils.StringUtils;
 
 public abstract class AuthenticationProvider {
 
@@ -68,6 +70,13 @@ public abstract class AuthenticationProvider {
                return serviceName;
        }
 
+       protected void setCookie(UserModel user, char [] password) {
+               // create a user cookie
+               if (StringUtils.isEmpty(user.cookie) && !ArrayUtils.isEmpty(password)) {
+                       user.cookie = StringUtils.getSHA1(user.username + new String(password));
+               }
+       }
+
        protected void updateUser(UserModel userModel) {
                // TODO implement user model change detection
                // account for new user and revised user
index 559a0fa0d9aab6d2e956bc24b0ef3dcf59f42aac..5ffb6930b3a4f758e7c2e74b1d3f98cecb4f300a 100644 (file)
@@ -35,8 +35,6 @@ import com.gitblit.Constants.AccountType;
 import com.gitblit.Keys;
 import com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider;
 import com.gitblit.models.UserModel;
-import com.gitblit.utils.ArrayUtils;
-import com.gitblit.utils.StringUtils;
 
 
 /**
@@ -186,9 +184,7 @@ public class HtpasswdAuthProvider extends UsernamePasswordAuthenticationProvider
                 }
 
                 // create a user cookie
-                if (StringUtils.isEmpty(user.cookie) && !ArrayUtils.isEmpty(password)) {
-                    user.cookie = StringUtils.getSHA1(user.username + passwd);
-                }
+                setCookie(user, password);
 
                 // Set user attributes, hide password from backing user service.
                 user.password = Constants.EXTERNAL_ACCOUNT;
index 6a2dd43755da71897fd2b3ce4330e692e280d238..8fef620d5b66569ecd62e99a290aca400d1cd115 100644 (file)
@@ -295,9 +295,7 @@ public class LdapAuthProvider extends UsernamePasswordAuthenticationProvider {
                                                        }
 
                                                        // create a user cookie
-                                                       if (StringUtils.isEmpty(user.cookie) && !ArrayUtils.isEmpty(password)) {
-                                                               user.cookie = StringUtils.getSHA1(user.username + new String(password));
-                                                       }
+                                                       setCookie(user, password);
 
                                                        if (!supportsTeamMembershipChanges()) {
                                                                getTeamsFromLdap(ldapConnection, simpleUsername, loggingInUser, user);
index bbc82d84adfbb3ed625b7942cd081e6c8df08545..7e82bc6363381605648bd79b6f3247d5e73a98cc 100644 (file)
@@ -26,8 +26,6 @@ import com.gitblit.Constants.AccountType;
 import com.gitblit.Keys;
 import com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider;
 import com.gitblit.models.UserModel;
-import com.gitblit.utils.ArrayUtils;
-import com.gitblit.utils.StringUtils;
 
 /**
  * Implementation of PAM authentication for Linux/Unix/MacOSX.
@@ -104,13 +102,13 @@ public class PAMAuthProvider extends UsernamePasswordAuthenticationProvider {
                }
 
         UserModel user = userManager.getUserModel(username);
-        if (user == null)      // create user object for new authenticated user
+        if (user == null) {
+               // create user object for new authenticated user
                user = new UserModel(username.toLowerCase());
+        }
 
         // create a user cookie
-        if (StringUtils.isEmpty(user.cookie) && !ArrayUtils.isEmpty(password)) {
-               user.cookie = StringUtils.getSHA1(user.username + new String(password));
-        }
+        setCookie(user, password);
 
         // update user attributes from UnixUser
         user.accountType = getAccountType();
index 176c576b5c48732ed7e15fda8138e1fd21c91020..04adc459fb3272d7ff12e7d5c5db912618fc0e1a 100644 (file)
@@ -26,7 +26,6 @@ import com.gitblit.Constants.AccountType;
 import com.gitblit.Keys;
 import com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider;
 import com.gitblit.models.UserModel;
-import com.gitblit.utils.ArrayUtils;
 import com.gitblit.utils.ConnectionUtils;
 import com.gitblit.utils.StringUtils;
 import com.google.gson.Gson;
@@ -122,13 +121,13 @@ public class RedmineAuthProvider extends UsernamePasswordAuthenticationProvider
         }
 
         UserModel user = userManager.getUserModel(username);
-        if (user == null)      // create user object for new authenticated user
+        if (user == null) {
+               // create user object for new authenticated user
                user = new UserModel(username.toLowerCase());
+        }
 
         // create a user cookie
-        if (StringUtils.isEmpty(user.cookie) && !ArrayUtils.isEmpty(password)) {
-               user.cookie = StringUtils.getSHA1(user.username + new String(password));
-        }
+        setCookie(user, password);
 
         // update user attributes from Redmine
         user.accountType = getAccountType();
index fdda32afcff2c7cd749ebff7c7b638d684b27a73..e4273ff626e6ad03485215e2d914236d0a321ab9 100644 (file)
@@ -5,8 +5,6 @@ import com.gitblit.Constants.AccountType;
 import com.gitblit.Keys;
 import com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider;
 import com.gitblit.models.UserModel;
-import com.gitblit.utils.ArrayUtils;
-import com.gitblit.utils.StringUtils;
 import com.sforce.soap.partner.Connector;
 import com.sforce.soap.partner.GetUserInfoResult;
 import com.sforce.soap.partner.PartnerConnection;
@@ -62,15 +60,11 @@ public class SalesforceAuthProvider extends UsernamePasswordAuthenticationProvid
                        UserModel user = null;
                        synchronized (this) {
                                user = userManager.getUserModel(simpleUsername);
-                               if (user == null)
+                               if (user == null) {
                                        user = new UserModel(simpleUsername);
-
-                               if (StringUtils.isEmpty(user.cookie)
-                                               && !ArrayUtils.isEmpty(password)) {
-                                       user.cookie = StringUtils.getSHA1(user.username
-                                                       + new String(password));
                                }
 
+                               setCookie(user, password);
                                setUserAttributes(user, info);
 
                                updateUser(user);
index d455d58fd40c5d75e0ebca19171d10900b1f259f..93cae046d5b225de10d06ce68dc9a434e4674eaa 100644 (file)
@@ -29,7 +29,6 @@ import com.gitblit.Constants.AccountType;
 import com.gitblit.Keys;
 import com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider;
 import com.gitblit.models.UserModel;
-import com.gitblit.utils.ArrayUtils;
 import com.gitblit.utils.StringUtils;
 import com.sun.jna.platform.win32.Win32Exception;
 
@@ -136,13 +135,13 @@ public class WindowsAuthProvider extends UsernamePasswordAuthenticationProvider
                }
 
         UserModel user = userManager.getUserModel(username);
-        if (user == null)      // create user object for new authenticated user
+        if (user == null) {
+               // create user object for new authenticated user
                user = new UserModel(username.toLowerCase());
+        }
 
         // create a user cookie
-        if (StringUtils.isEmpty(user.cookie) && !ArrayUtils.isEmpty(password)) {
-               user.cookie = StringUtils.getSHA1(user.username + new String(password));
-        }
+        setCookie(user, password);
 
         // update user attributes from Windows identity
         user.accountType = getAccountType();