From: mallowlabs Date: Sat, 8 Sep 2012 15:00:01 +0000 (+0900) Subject: Fixed non admin user could not login with Redmine X-Git-Tag: v1.2.0~237^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1684e001f76fae8675defb81fc993efea766f110;p=gitblit.git Fixed non admin user could not login with Redmine --- diff --git a/src/com/gitblit/RedmineUserService.java b/src/com/gitblit/RedmineUserService.java index 47bb80a5..b890f21b 100644 --- a/src/com/gitblit/RedmineUserService.java +++ b/src/com/gitblit/RedmineUserService.java @@ -86,15 +86,20 @@ public class RedmineUserService extends GitblitUserService { RedmineCurrent current = new Gson().fromJson(jsonString, RedmineCurrent.class); String login = current.user.login; - if (username.equalsIgnoreCase(login)) { - UserModel userModel = new UserModel(login); - userModel.displayName = current.user.firstname + " " + current.user.lastname; - userModel.emailAddress = current.user.mail; - userModel.canAdmin = true; - userModel.cookie = StringUtils.getSHA1(userModel.username + new String(password)); - return userModel; + boolean canAdmin = true; + // non admin user can not get login name + if (StringUtils.isEmpty(login)) { + canAdmin = false; + login = current.user.mail; } + UserModel userModel = new UserModel(login); + userModel.canAdmin = canAdmin; + userModel.displayName = current.user.firstname + " " + current.user.lastname; + userModel.emailAddress = current.user.mail; + userModel.cookie = StringUtils.getSHA1(userModel.username + new String(password)); + + return userModel; } catch (IOException e) { logger.error("authenticate", e); } diff --git a/tests/com/gitblit/tests/RedmineUserServiceTest.java b/tests/com/gitblit/tests/RedmineUserServiceTest.java index 0ba58ec5..30a8fb20 100644 --- a/tests/com/gitblit/tests/RedmineUserServiceTest.java +++ b/tests/com/gitblit/tests/RedmineUserServiceTest.java @@ -19,6 +19,10 @@ public class RedmineUserServiceTest { + "\"last_login_on\":\"2012-09-06T23:59:26Z\",\"firstname\":\"baz\"," + "\"id\":4,\"login\":\"RedmineUserId\",\"mail\":\"baz@example.com\"}}"; + private static final String NOT_ADMIN_JSON = "{\"user\":{\"lastname\":\"foo\"," + + "\"last_login_on\":\"2012-09-08T13:59:01Z\",\"created_on\":\"2009-03-17T14:25:50Z\"," + + "\"mail\":\"baz@example.com\",\"id\":5,\"firstname\":\"baz\"}}"; + @Test public void testAuthenticate() throws Exception { RedmineUserService redmineUserService = new RedmineUserService(); @@ -29,15 +33,20 @@ public class RedmineUserServiceTest { assertThat(userModel.getDisplayName(), is("baz foo")); assertThat(userModel.emailAddress, is("baz@example.com")); assertNotNull(userModel.cookie); + assertThat(userModel.canAdmin, is(true)); } @Test - public void testAuthenticateWithWronId() throws Exception { + public void testAuthenticateNotAdminUser() throws Exception { RedmineUserService redmineUserService = new RedmineUserService(); redmineUserService.setup(new MemorySettings(new HashMap())); - redmineUserService.setTestingCurrentUserAsJson(JSON); - UserModel userModel = redmineUserService.authenticate("WrongRedmineUserId", "RedmineAPIKey".toCharArray()); - assertNull(userModel); + redmineUserService.setTestingCurrentUserAsJson(NOT_ADMIN_JSON); + UserModel userModel = redmineUserService.authenticate("RedmineUserId", "RedmineAPIKey".toCharArray()); + assertThat(userModel.getName(), is("baz@example.com")); + assertThat(userModel.getDisplayName(), is("baz foo")); + assertThat(userModel.emailAddress, is("baz@example.com")); + assertNotNull(userModel.cookie); + assertThat(userModel.canAdmin, is(false)); } }