Update UserConfig with salt value while changing roles 74/5374/1
authorSapan Shah <sapshah@cisco.com>
Tue, 18 Feb 2014 01:31:20 +0000 (17:31 -0800)
committerSapan Shah <sapshah@cisco.com>
Tue, 18 Feb 2014 01:31:20 +0000 (17:31 -0800)
Change-Id: If99955c69cbf374e891db37c7a7f584f37acc047
Signed-off-by: Sapan Shah <sapshah@cisco.com>
opendaylight/usermanager/api/src/main/java/org/opendaylight/controller/usermanager/UserConfig.java
opendaylight/web/root/src/main/java/org/opendaylight/controller/web/DaylightWebAdmin.java

index 75fcec5b3cc5e4d9e2804a0bc74da9dd5ae2456f..ea9e599d83c06ef9af96493935f7ebe53081ef97 100644 (file)
@@ -136,6 +136,10 @@ public class UserConfig extends ConfigurationObject implements Serializable {
         return new ArrayList<String>(roles);
     }
 
+    public byte[] getSalt() {
+        return salt.clone();
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
index 4c8a6b8439f2b18482a848605e1f5e234a27f8cd..b6a4d0dd543479881d86bc60eac3420ee1e7ce05 100644 (file)
@@ -212,10 +212,12 @@ public class DaylightWebAdmin {
         UserConfig newConfig = gson.fromJson(json, UserConfig.class);
         List<UserConfig> currentUserConfig = userManager.getLocalUserList();
         String password = null;
+        byte[] salt = null;
         String user = newConfig.getUser();
         for (UserConfig userConfig : currentUserConfig) {
             if(userConfig.getUser().equals(user)){
                 password = userConfig.getPassword();
+                salt = userConfig.getSalt();
                 break;
             }
         }
@@ -228,8 +230,9 @@ public class DaylightWebAdmin {
         //The password is stored in hash mode, hence it cannot be retrieved and added to UserConfig object
         //The hashed password is injected below to the json string containing username and new roles before
         //converting to UserConfig object.
-        json = json.replace("\"roles\"", "\"password\":\""+ password + "\",\"roles\"");
         Gson gson = new Gson();
+        json = json.replace("\"roles\"", "\"salt\":" + gson.toJson(salt, salt.getClass()) + ",\"password\":\""+ password + "\",\"roles\"");
+
         newConfig = gson.fromJson(json, UserConfig.class);
 
         Status result = userManager.modifyLocalUser(newConfig);