Skip to content
Snippets Groups Projects
Commit dcf81458 authored by William Enright's avatar William Enright Committed by Larbi Gharib
Browse files

PUT method for updating jami user reads body for parameters

Change-Id: I093df5607aee255c5977158246ae59c3ba512d2b
parent 61f81da2
No related branches found
No related tags found
No related merge requests found
......@@ -99,34 +99,31 @@ public class UserServlet extends HttpServlet {
user.setSalt(Base64.encodeBase64String(salt));
user.setRealm("LOCAL");
user.setUserType(AuthenticationSourceType.LOCAL);
if(userAuthenticationModule.createUser(user.getUserType(),user.getRealm(),nameServer,user)){
if(userAuthenticationModule.createUser(user.getUserType(),user.getRealm(),nameServer,user)) {
HashMap<String,String> statusInfo = new HashMap<>();
statusInfo.put("password", pw);
resp.getOutputStream().write(JsonStream.serialize(statusInfo).getBytes());
resp.setStatus(200);
return;
}
}
resp.sendError(500,"Could not create a user successfully!");
}
//Update user data.
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String username = req.getParameter("username");
final JSONObject obj = new JSONObject(req.getReader().lines().collect(Collectors.joining(System.lineSeparator())));
String pw = obj.getString("password");
String username = obj.getString("username");
//Check if he is AD/LDAP - then return a 403, because we can't set such password.
if(dataStore.getUserDao().getObjects(null).get(0).getUserType() != AuthenticationSourceType.LOCAL){
resp.sendError(500,"The user is not a local user, therefore we cannot change his data!");
return;
}
StatementList update = new StatementList();
StatementElement st0 = new StatementElement("password","=",PasswordUtil.hashPassword(req.getParameter("password"), Base64.decodeBase64(dataStore.getUserDao().getObjects(null).get(0).getSalt())),"");
StatementElement st0 = new StatementElement("password","=",PasswordUtil.hashPassword(pw, Base64.decodeBase64(dataStore.getUserDao().getObjects(null).get(0).getSalt())),"");
update.addStatement(st0);
StatementList constraint = new StatementList();
StatementElement st1 = new StatementElement("username","=",username,"");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment