+ User actualUser = null;
+ List<User> actualUsers = userService.findAllActive();
+ for (User tempUser : actualUsers) {
+ if (tempUser.getLoginId().equals(user.getLoginId())) {
+ actualUser = tempUser;
+ }
+ }
+ if (actualUser == null) {
+ throw new RuntimeException("User does not exist");
+ }
+ actualUser.setLoginPwd(CipherUtil.encryptPKC(user.getLoginPwd(), System.getenv("ENCRYPTION_KEY")));
+ userService.saveUser(actualUser);
+ return new ResponseEntity<>(true, HttpStatus.OK);
+ } catch (Exception e) {
+ LOGGER.error(EELFLoggerDelegate.errorLogger, "Update of user failed. " + UserUtils.getStackTrace(e));
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
+ }
+ }
+
+ @RequestMapping(value = { "/create" }, method = RequestMethod.POST)
+ public ResponseEntity<User> postUser(@RequestBody UserData userData) {
+ try {
+ return new ResponseEntity<>(createUser(userData.getUser(), userData.getRole()), HttpStatus.OK);
+ } catch (Exception e) {
+ LOGGER.error(EELFLoggerDelegate.errorLogger, "Creation of user failed. " + UserUtils.getStackTrace(e));
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
+ }
+ }
+
+ @RequestMapping(value = { "/updatepassword" }, method = RequestMethod.POST)
+ public ResponseEntity<Boolean> updatePassword(@RequestBody UserData userData) {
+ try {
+ User actualUser = null;
+ List<User> actualUsers = userService.findAllActive();
+ for (User tempUser : actualUsers) {
+ if (tempUser.getLoginId().equals(userData.getUser().getLoginId())) {
+ actualUser = tempUser;
+ }
+ }
+ if (actualUser == null) {
+ throw new RuntimeException("User does not exist");
+ }
+ if (!CipherUtil.decryptPKC(actualUser.getLoginPwd(), System.getenv("ENCRYPTION_KEY"))
+ .equals(userData.getUser().getLoginPwd())) {
+ throw new RuntimeException("Wrong password");
+ }
+ actualUser.setLoginPwd(CipherUtil.encryptPKC(userData.getNewPwd(), System.getenv("ENCRYPTION_KEY")));
+ userService.saveUser(actualUser);
+ return new ResponseEntity<>(true, HttpStatus.OK);