diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/controller/UsersController.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/controller/UsersController.java index 8ccae082d..82fbd0745 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/controller/UsersController.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/security/controller/UsersController.java @@ -3,24 +3,20 @@ import edu.internet2.tier.shibboleth.admin.ui.controller.ErrorResponse; import edu.internet2.tier.shibboleth.admin.ui.security.model.User; import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository; -<<<<<<< Updated upstream + import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -======= -import org.springframework.beans.factory.annotation.Required; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; + import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; + import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; ->>>>>>> Stashed changes + import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -53,27 +49,21 @@ public List getAll() { } @Transactional(readOnly = true) - @GetMapping("/user/{username}") + @GetMapping("/users/{username}") public ResponseEntity getOne(@PathVariable String username) { return ResponseEntity.ok(findUserOrThrowHttp404(username)); } @Transactional - @DeleteMapping("/user/{username}") + @DeleteMapping("/users/{username}") public ResponseEntity deleteOne(@PathVariable String username) { User user = findUserOrThrowHttp404(username); userRepository.delete(user); return ResponseEntity.noContent().build(); } - - private User findUserOrThrowHttp404(String username) { - return userRepository.findByUsername(username) - .orElseThrow(() -> new HttpClientErrorException(NOT_FOUND, String.format("User with username [%s] not found", username))); - } - @Transactional - @PostMapping("/user") + @PostMapping("/users") ResponseEntity saveOne(@RequestParam User user) { Optional persistedUser = userRepository.findByUsername(user.getUsername()); if (persistedUser.isPresent()) { @@ -88,7 +78,7 @@ ResponseEntity saveOne(@RequestParam User user) { } @Transactional - @PutMapping("/user/{username}") + @PutMapping("/users/{username}") ResponseEntity updateOne(@PathVariable(value = "username") String username, @RequestParam User user) { Optional userSearchResult = userRepository.findByUsername(username); if (!userSearchResult.isPresent()) { @@ -98,11 +88,16 @@ ResponseEntity updateOne(@PathVariable(value = "username") String username, @ } PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); User persistedUser = userSearchResult.get(); - persistedUser.setPassword(passwordEncoder.encode(user.getPassword()); + persistedUser.setPassword(passwordEncoder.encode(user.getPassword())); persistedUser.setFirstName(user.getFirstName()); persistedUser.setLastName(user.getLastName()); persistedUser.setRoles(user.getRoles()); User savedUser = userRepository.save(persistedUser); return ResponseEntity.ok(savedUser); } + + private User findUserOrThrowHttp404(String username) { + return userRepository.findByUsername(username) + .orElseThrow(() -> new HttpClientErrorException(NOT_FOUND, String.format("User with username [%s] not found", username))); + } }