private static final String DISPLAYNAME = "displayName";\r
\r
private static final String EMAILADDRESS = "emailAddress";\r
+ \r
+ private static final String COOKIE = "cookie";\r
\r
private static final String REPOSITORY = "repository";\r
\r
* @return cookie value\r
*/\r
@Override\r
- public char[] getCookie(UserModel model) {\r
+ public String getCookie(UserModel model) {\r
+ if (!StringUtils.isEmpty(model.cookie)) {\r
+ return model.cookie;\r
+ }\r
read();\r
UserModel storedModel = users.get(model.username.toLowerCase());\r
- String cookie = StringUtils.getSHA1(model.username + storedModel.password);\r
- return cookie.toCharArray();\r
+ return storedModel.cookie;\r
}\r
\r
/**\r
if (!StringUtils.isEmpty(model.password)) {\r
config.setString(USER, model.username, PASSWORD, model.password);\r
}\r
+ if (!StringUtils.isEmpty(model.cookie)) {\r
+ config.setString(USER, model.username, COOKIE, model.cookie);\r
+ }\r
if (!StringUtils.isEmpty(model.displayName)) {\r
config.setString(USER, model.username, DISPLAYNAME, model.displayName);\r
}\r
user.password = config.getString(USER, username, PASSWORD); \r
user.displayName = config.getString(USER, username, DISPLAYNAME);\r
user.emailAddress = config.getString(USER, username, EMAILADDRESS);\r
+ user.cookie = config.getString(USER, username, COOKIE);\r
+ if (StringUtils.isEmpty(user.cookie) && !StringUtils.isEmpty(user.password)) {\r
+ user.cookie = StringUtils.getSHA1(user.username + user.password);\r
+ }\r
\r
// user roles\r
Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(\r
\r
// update cache\r
users.put(user.username, user);\r
- cookies.put(StringUtils.getSHA1(user.username + user.password), user);\r
+ if (!StringUtils.isEmpty(user.cookie)) {\r
+ cookies.put(user.cookie, user);\r
+ }\r
}\r
\r
// load the teams\r
* @return cookie value\r
*/\r
@Override\r
- public char[] getCookie(UserModel model) {\r
+ public String getCookie(UserModel model) {\r
+ if (!StringUtils.isEmpty(model.cookie)) {\r
+ return model.cookie;\r
+ }\r
Properties allUsers = super.read();\r
String value = allUsers.getProperty(model.username);\r
String[] roles = value.split(",");\r
String password = roles[0];\r
String cookie = StringUtils.getSHA1(model.username + password);\r
- return cookie.toCharArray();\r
+ return cookie;\r
}\r
\r
/**\r
userCookie = new Cookie(Constants.NAME, "");\r
} else {\r
// set cookie for login\r
- char[] cookie = userService.getCookie(user);\r
- userCookie = new Cookie(Constants.NAME, new String(cookie));\r
- userCookie.setMaxAge(Integer.MAX_VALUE);\r
+ String cookie = userService.getCookie(user);\r
+ if (StringUtils.isEmpty(cookie)) {\r
+ // create empty cookie\r
+ userCookie = new Cookie(Constants.NAME, "");\r
+ } else {\r
+ // create real cookie\r
+ userCookie = new Cookie(Constants.NAME, cookie);\r
+ userCookie.setMaxAge(Integer.MAX_VALUE);\r
+ }\r
}\r
userCookie.setPath("/");\r
response.addCookie(userCookie);\r
}\r
\r
@Override\r
- public char[] getCookie(UserModel model) {\r
+ public String getCookie(UserModel model) {\r
return serviceImpl.getCookie(model);\r
}\r
\r
* @param model\r
* @return cookie value\r
*/\r
- char[] getCookie(UserModel model);\r
+ String getCookie(UserModel model);\r
\r
/**\r
* Authenticate a user based on their cookie.\r
\r
import com.gitblit.models.TeamModel;\r
import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.unboundid.ldap.sdk.Attribute;\r
import com.unboundid.ldap.sdk.LDAPConnection;\r
return !settings.getBoolean(Keys.realm.ldap.maintainTeams, false);\r
}\r
\r
- /**\r
- * Does the user service support cookie authentication?\r
- * \r
- * @return true or false\r
- */\r
- @Override\r
- public boolean supportsCookies() {\r
- // TODO cookies need to be reviewed\r
- return false;\r
- }\r
-\r
@Override\r
public UserModel authenticate(String username, char[] password) {\r
String simpleUsername = getSimpleUsername(username);\r
UserModel user = getUserModel(simpleUsername);\r
if (user == null) // create user object for new authenticated user\r
user = new UserModel(simpleUsername);\r
- \r
- \r
+\r
+ // create a user cookie\r
+ if (StringUtils.isEmpty(user.cookie) && !ArrayUtils.isEmpty(password)) {\r
+ user.cookie = StringUtils.getSHA1(user.username + new String(password));\r
+ }\r
\r
if (!supportsTeamMembershipChanges())\r
getTeamsFromLdap(ldapConnection, simpleUsername, loggingInUser, user);\r
public static boolean isEmpty(byte [] array) {\r
return array == null || array.length == 0;\r
}\r
- \r
+\r
+ public static boolean isEmpty(char [] array) {\r
+ return array == null || array.length == 0;\r
+ }\r
+\r
public static boolean isEmpty(Object [] array) {\r
return array == null || array.length == 0;\r
}\r