// Path: src/main/java/com/behase/relumin/exception/InvalidParameterException.java
// public class InvalidParameterException extends ApiException {
//     private static final long serialVersionUID = -6416726302671334601L;
// 
//     public InvalidParameterException(String message) {
//         super(Constants.ERR_CODE_INVALID_PARAMETER, String.format("Invalid parameter. %s", message), HttpStatus.BAD_REQUEST);
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/model/LoginUser.java
// @Data
// @Builder
// @NoArgsConstructor
// public class LoginUser {
//     private String username;
//     private String displayName;
//     private String password;
//     private String role;
// 
//     public LoginUser(String username, String displayName, String rawPassword, String role) {
//         this.username = username;
//         this.displayName = displayName;
//         this.password = new StandardPasswordEncoder().encode(rawPassword);
//         this.role = Role.get(role).getAuthority();
//     }
// 
//     @JsonIgnore
//     public User getSpringUser() {
//         return new User(username, password, Lists.newArrayList(Role.get(role)));
//     }
// 
//     public void setRawPassword(String rawPassword) {
//         this.password = new StandardPasswordEncoder().encode(rawPassword);
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/service/LoggingOperationService.java
// public interface LoggingOperationService {
//     void log(String operationName, Authentication authentication);
// 
//     void log(String operationName, Authentication authentication, String msg);
// 
//     void log(String operationName, Authentication authentication, String msg, Object... objects);
// }
// 
// Path: src/main/java/com/behase/relumin/service/UserService.java
// public interface UserService extends UserDetailsService {
//     LoginUser getUser(String username) throws Exception;
// 
//     List<LoginUser> getUsers() throws Exception;
// 
//     void addUser(String username, String displayName, String password, String role) throws Exception;
// 
//     void changePassword(String username, String oldPassword, String password) throws Exception;
// 
//     void updateUser(String username, String displayName, String role) throws Exception;
// 
//     void deleteUser(String username) throws Exception;
// }


import com.behase.relumin.exception.InvalidParameterException;
import com.behase.relumin.model.LoginUser;
import com.behase.relumin.service.LoggingOperationService;
import com.behase.relumin.service.UserService;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
            @PathVariable String username,
            @RequestParam(defaultValue = "") String displayName,
            @RequestParam(defaultValue = "") String role
    ) throws Exception {
        loggingOperationService.log("updateUser", authentication, "username={}, displayName={}, role={}.", username, displayName, role);

        userService.updateUser(username, displayName, role);
        return userService.getUser(username);
    }

    @RequestMapping(value = "/me/update", method = RequestMethod.POST)
    public LoginUser updateMe(
            Authentication authentication,
            @RequestParam(defaultValue = "") String displayName
    ) throws Exception {
        if (authentication == null) {
            throw new InvalidParameterException("You are not loggedin.");
        }
        String username = authentication.getName();
        userService.updateUser(username, displayName, null);
        return userService.getUser(username);
    }

    @RequestMapping(value = "/me/change-password", method = RequestMethod.POST)
    public LoginUser changePassword(
            Authentication authentication,
            @RequestParam(defaultValue = "") String oldPassword,
            @RequestParam(defaultValue = "") String password
    ) throws Exception {
        if (authentication == null) {
// Path: src/main/java/com/behase/relumin/exception/InvalidParameterException.java
// public class InvalidParameterException extends ApiException {
//     private static final long serialVersionUID = -6416726302671334601L;
// 
//     public InvalidParameterException(String message) {
//         super(Constants.ERR_CODE_INVALID_PARAMETER, String.format("Invalid parameter. %s", message), HttpStatus.BAD_REQUEST);
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/model/LoginUser.java
// @Data
// @Builder
// @NoArgsConstructor
// public class LoginUser {
//     private String username;
//     private String displayName;
//     private String password;
//     private String role;
// 
//     public LoginUser(String username, String displayName, String rawPassword, String role) {
//         this.username = username;
//         this.displayName = displayName;
//         this.password = new StandardPasswordEncoder().encode(rawPassword);
//         this.role = Role.get(role).getAuthority();
//     }
// 
//     @JsonIgnore
//     public User getSpringUser() {
//         return new User(username, password, Lists.newArrayList(Role.get(role)));
//     }
// 
//     public void setRawPassword(String rawPassword) {
//         this.password = new StandardPasswordEncoder().encode(rawPassword);
//     }
// }
// 
// Path: src/main/java/com/behase/relumin/service/LoggingOperationService.java
// public interface LoggingOperationService {
//     void log(String operationName, Authentication authentication);
// 
//     void log(String operationName, Authentication authentication, String msg);
// 
//     void log(String operationName, Authentication authentication, String msg, Object... objects);
// }
// 
// Path: src/main/java/com/behase/relumin/service/UserService.java
// public interface UserService extends UserDetailsService {
//     LoginUser getUser(String username) throws Exception;
// 
//     List<LoginUser> getUsers() throws Exception;
// 
//     void addUser(String username, String displayName, String password, String role) throws Exception;
// 
//     void changePassword(String username, String oldPassword, String password) throws Exception;
// 
//     void updateUser(String username, String displayName, String role) throws Exception;
// 
//     void deleteUser(String username) throws Exception;
// }


// Path: src/main/java/com/behase/relumin/controller/UserApiController.java
import com.behase.relumin.exception.InvalidParameterException;
import com.behase.relumin.model.LoginUser;
import com.behase.relumin.service.LoggingOperationService;
import com.behase.relumin.service.UserService;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

            @PathVariable String username,
            @RequestParam(defaultValue = "") String displayName,
            @RequestParam(defaultValue = "") String role
    ) throws Exception {
        loggingOperationService.log("updateUser", authentication, "username={}, displayName={}, role={}.", username, displayName, role);

        userService.updateUser(username, displayName, role);
        return userService.getUser(username);
    }

    @RequestMapping(value = "/me/update", method = RequestMethod.POST)
    public LoginUser updateMe(
            Authentication authentication,
            @RequestParam(defaultValue = "") String displayName
    ) throws Exception {
        if (authentication == null) {
            throw new InvalidParameterException("You are not loggedin.");
        }
        String username = authentication.getName();
        userService.updateUser(username, displayName, null);
        return userService.getUser(username);
    }

    @RequestMapping(value = "/me/change-password", method = RequestMethod.POST)
    public LoginUser changePassword(
            Authentication authentication,
            @RequestParam(defaultValue = "") String oldPassword,
            @RequestParam(defaultValue = "") String password
    ) throws Exception {
        if (authentication == null) {
            throw new InvalidParameterException("You are not loggedin.");