]> source.dussan.org Git - gitblit.git/commitdiff
Fixed non admin user could not login with Redmine 34/head
authormallowlabs <mallowlabs@gmail.com>
Sat, 8 Sep 2012 15:00:01 +0000 (00:00 +0900)
committermallowlabs <mallowlabs@gmail.com>
Sat, 8 Sep 2012 15:00:03 +0000 (00:00 +0900)
src/com/gitblit/RedmineUserService.java
tests/com/gitblit/tests/RedmineUserServiceTest.java

index 47bb80a55dc676aa65eeaa10fb7d953510d9839c..b890f21b45b2befe3071a369cb422cc26ccc81c1 100644 (file)
@@ -86,15 +86,20 @@ public class RedmineUserService extends GitblitUserService {
             RedmineCurrent current = new Gson().fromJson(jsonString, RedmineCurrent.class);\r
             String login = current.user.login;\r
 \r
-            if (username.equalsIgnoreCase(login)) {\r
-                UserModel userModel = new UserModel(login);\r
-                userModel.displayName = current.user.firstname + " " + current.user.lastname;\r
-                userModel.emailAddress = current.user.mail;\r
-                userModel.canAdmin = true;\r
-                userModel.cookie = StringUtils.getSHA1(userModel.username + new String(password));\r
-                return userModel;\r
+            boolean canAdmin = true;\r
+            // non admin user can not get login name\r
+            if (StringUtils.isEmpty(login)) {\r
+                canAdmin = false;\r
+                login = current.user.mail;\r
             }\r
 \r
+            UserModel userModel = new UserModel(login);\r
+            userModel.canAdmin = canAdmin;\r
+            userModel.displayName = current.user.firstname + " " + current.user.lastname;\r
+            userModel.emailAddress = current.user.mail;\r
+            userModel.cookie = StringUtils.getSHA1(userModel.username + new String(password));\r
+\r
+            return userModel;\r
         } catch (IOException e) {\r
             logger.error("authenticate", e);\r
         }\r
index 0ba58ec59e64465f1c210bebc9cd8b75eb02d37f..30a8fb2085d0e78f5ecab742af8ad2415179b14e 100644 (file)
@@ -19,6 +19,10 @@ public class RedmineUserServiceTest {
         + "\"last_login_on\":\"2012-09-06T23:59:26Z\",\"firstname\":\"baz\","\r
         + "\"id\":4,\"login\":\"RedmineUserId\",\"mail\":\"baz@example.com\"}}";\r
 \r
+    private static final String NOT_ADMIN_JSON = "{\"user\":{\"lastname\":\"foo\","\r
+        + "\"last_login_on\":\"2012-09-08T13:59:01Z\",\"created_on\":\"2009-03-17T14:25:50Z\","\r
+        + "\"mail\":\"baz@example.com\",\"id\":5,\"firstname\":\"baz\"}}";\r
+\r
     @Test\r
     public void testAuthenticate() throws Exception {\r
         RedmineUserService redmineUserService = new RedmineUserService();\r
@@ -29,15 +33,20 @@ public class RedmineUserServiceTest {
         assertThat(userModel.getDisplayName(), is("baz foo"));\r
         assertThat(userModel.emailAddress, is("baz@example.com"));\r
         assertNotNull(userModel.cookie);\r
+        assertThat(userModel.canAdmin, is(true));\r
     }\r
 \r
     @Test\r
-    public void testAuthenticateWithWronId() throws Exception {\r
+    public void testAuthenticateNotAdminUser() throws Exception {\r
         RedmineUserService redmineUserService = new RedmineUserService();\r
         redmineUserService.setup(new MemorySettings(new HashMap<String, Object>()));\r
-        redmineUserService.setTestingCurrentUserAsJson(JSON);\r
-        UserModel userModel = redmineUserService.authenticate("WrongRedmineUserId", "RedmineAPIKey".toCharArray());\r
-        assertNull(userModel);\r
+        redmineUserService.setTestingCurrentUserAsJson(NOT_ADMIN_JSON);\r
+        UserModel userModel = redmineUserService.authenticate("RedmineUserId", "RedmineAPIKey".toCharArray());\r
+        assertThat(userModel.getName(), is("baz@example.com"));\r
+        assertThat(userModel.getDisplayName(), is("baz foo"));\r
+        assertThat(userModel.emailAddress, is("baz@example.com"));\r
+        assertNotNull(userModel.cookie);\r
+        assertThat(userModel.canAdmin, is(false));\r
     }\r
 \r
 }\r