diff options
author | James Moger <james.moger@gitblit.com> | 2013-06-19 08:06:38 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-06-19 08:06:38 -0400 |
commit | 15cb305fbd441f0d7b3e7261d956472db3718417 (patch) | |
tree | fdf50a3f00574deb38b2139cc0cc7c5c3b175839 /src/main/java/com/gitblit/GitBlit.java | |
parent | 067a2fcb2cda0aef4357cf9fdaaf35538b3d926e (diff) | |
download | gitblit-15cb305fbd441f0d7b3e7261d956472db3718417.tar.gz gitblit-15cb305fbd441f0d7b3e7261d956472db3718417.zip |
Support (%40|@) username (en|de)coding for repository urls and authentication
Diffstat (limited to 'src/main/java/com/gitblit/GitBlit.java')
-rw-r--r-- | src/main/java/com/gitblit/GitBlit.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index ecd4662c..3aaa8c6d 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -509,7 +509,7 @@ public class GitBlit implements ServletContextListener { if (user == null) { user = UserModel.ANONYMOUS; } - String username = UserModel.ANONYMOUS.equals(user) ? "" : user.username; + String username = encodeUsername(UserModel.ANONYMOUS.equals(user) ? "" : user.username); List<RepositoryUrl> list = new ArrayList<RepositoryUrl>(); // http/https url @@ -735,6 +735,7 @@ public class GitBlit implements ServletContextListener { // can not authenticate empty username return null; } + String usernameDecoded = decodeUsername(username); String pw = new String(password); if (StringUtils.isEmpty(pw)) { // can not authenticate empty password @@ -743,7 +744,7 @@ public class GitBlit implements ServletContextListener { // check to see if this is the federation user if (canFederate()) { - if (username.equalsIgnoreCase(Constants.FEDERATION_USER)) { + if (usernameDecoded.equalsIgnoreCase(Constants.FEDERATION_USER)) { List<String> tokens = getFederationTokens(); if (tokens.contains(pw)) { // the federation user is an administrator @@ -758,7 +759,7 @@ public class GitBlit implements ServletContextListener { if (userService == null) { return null; } - return userService.authenticate(username, password); + return userService.authenticate(usernameDecoded, password); } /** @@ -966,6 +967,14 @@ public class GitBlit implements ServletContextListener { userService.logout(user); } + protected String encodeUsername(String name) { + return name.replace("@", "%40"); + } + + protected String decodeUsername(String name) { + return name.replace("%40", "@"); + } + /** * Returns the list of all users available to the login service. * @@ -999,7 +1008,8 @@ public class GitBlit implements ServletContextListener { if (StringUtils.isEmpty(username)) { return false; } - return userService.deleteUser(username); + String usernameDecoded = decodeUsername(username); + return userService.deleteUser(usernameDecoded); } /** @@ -1013,7 +1023,8 @@ public class GitBlit implements ServletContextListener { if (StringUtils.isEmpty(username)) { return null; } - UserModel user = userService.getUserModel(username); + String usernameDecoded = decodeUsername(username); + UserModel user = userService.getUserModel(usernameDecoded); return user; } |