Log all configuration(add/modify/delete) changes to a new log file audit.log
[controller.git] / opendaylight / web / root / src / main / java / org / opendaylight / controller / web / DaylightWebAdmin.java
index 46b8d4e0fe5e0329299a5671a6440ae801fbc853..524cb62b3a2175d24596f4b5727a5d7a57310005 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
 import org.opendaylight.controller.usermanager.IUserManager;
-import org.opendaylight.controller.usermanager.internal.UserConfig;
+import org.opendaylight.controller.usermanager.UserConfig;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -30,6 +30,9 @@ import com.google.gson.Gson;
 @Controller
 @RequestMapping("/admin")
 public class DaylightWebAdmin {
+
+
+
     @RequestMapping("/users")
     @ResponseBody
     public List<UserConfig> getUsers() {
@@ -69,7 +72,11 @@ public class DaylightWebAdmin {
 
         Status result = (action.equals("add")) ? userManager
                 .addLocalUser(config) : userManager.removeLocalUser(config);
-
+        if(result.getCode().equals(StatusCode.SUCCESS)) {
+            String userAction=(action.equals("add")) ? "added":"removed";
+            DaylightWebUtil.auditlog("User", request.getUserPrincipal().getName(), userAction, config.getUser());
+            return "Success";
+        }
         return result.getDescription();
     }
 
@@ -93,9 +100,14 @@ public class DaylightWebAdmin {
             return "Operation not permitted";
         }
 
-        return userManager.removeLocalUser(userName).getDescription();
+        Status result = userManager.removeLocalUser(userName);
+        if(result.getCode().equals(StatusCode.SUCCESS)) {
+            DaylightWebUtil.auditlog("User", request.getUserPrincipal().getName(), "removed", userName);
+            return "Success";
+        }
+        return result.getDescription();
     }
-    
+
     @RequestMapping(value = "/users/password/{username}", method = RequestMethod.POST)
     @ResponseBody
     public Status changePassword(@PathVariable("username") String username, HttpServletRequest request,
@@ -105,23 +117,25 @@ public class DaylightWebAdmin {
         if (userManager == null) {
             return new Status(StatusCode.GONE, "User Manager not found");
         }
-        
+
         if (!authorize(userManager, UserLevel.NETWORKADMIN, request)) {
             return new Status(StatusCode.FORBIDDEN, "Operation not permitted");
         }
-        
+
         if (newPassword.isEmpty()) {
             return new Status(StatusCode.BADREQUEST, "Empty passwords not allowed");
         }
-        
+
         Status status = userManager.changeLocalUserPassword(username, currentPassword, newPassword);
-        
+        if(status.isSuccess()){
+            DaylightWebUtil.auditlog("User", request.getUserPrincipal().getName(), "changed password for", username);
+        }
         return status;
     }
 
     /**
      * Is the operation permitted for the given level
-     * 
+     *
      * @param level
      */
     private boolean authorize(IUserManager userManager, UserLevel level,