Commit 2e93023d authored by Jan Marchel's avatar Jan Marchel
Browse files

small changes in user service

parent c5eaeb94
......@@ -5,6 +5,7 @@ import eu.melodic.models.interfaces.security.UserRequest;
import eu.paasage.upperware.security.authapi.SecurityConstants;
import eu.paasage.upperware.security.server.controller.request.ChangePasswordRequest;
import eu.paasage.upperware.security.server.controller.request.NewUserRequest;
import eu.paasage.upperware.security.server.controller.request.UpdateExistingUserRequest;
import eu.paasage.upperware.security.server.controller.response.ExceptionResponse;
import eu.paasage.upperware.security.server.controller.response.UserDataResponse;
import eu.paasage.upperware.security.server.controller.response.UserResponse;
......@@ -72,9 +73,9 @@ public class UserController {
}
@GetMapping("/auth/username")
@ResponseBody
public String currentUserName(HttpServletRequest request) {
Principal principal = request.getUserPrincipal();
return principal.getName();
public String getUserFullName(HttpServletRequest request) {
User user = (User) request.getUserPrincipal();
return user.getFullName();
}
@DeleteMapping("/auth/user/{username}")
......@@ -99,11 +100,11 @@ public class UserController {
@PutMapping("/auth/user")
@ResponseStatus(HttpStatus.NO_CONTENT)
@PreAuthorize("#newUserRequest.username.equals(authentication.name)")
public void updateUser(@RequestBody @Valid NewUserRequest newUserRequest)
public void updateUser(@RequestBody @Valid UpdateExistingUserRequest updateExistingUserRequest)
throws AuthenticationException {
log.info("PUT request for change user info from user: {}", newUserRequest.getUsername());
userService.updateUser(newUserRequest);
log.info("user info for user: {} successfully changed", newUserRequest.getUsername());
log.info("PUT request for change user info from user: {}", updateExistingUserRequest.getUsername());
userService.updateUser(updateExistingUserRequest);
log.info("user info for user: {} successfully changed", updateExistingUserRequest.getUsername());
}
......
package eu.paasage.upperware.security.server.controller.request;
import eu.paasage.upperware.security.server.data.validator.UniqueUsername;
import lombok.*;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UpdateExistingUserRequest {
@UniqueUsername()
private String username;
private String fullName;
private String mail;
}
......@@ -4,6 +4,7 @@ import eu.paasage.upperware.security.authapi.SecurityConstants;
import eu.paasage.upperware.security.authapi.token.JWTService;
import eu.paasage.upperware.security.server.controller.request.ChangePasswordRequest;
import eu.paasage.upperware.security.server.controller.request.NewUserRequest;
import eu.paasage.upperware.security.server.controller.request.UpdateExistingUserRequest;
import eu.paasage.upperware.security.server.controller.response.UserDataResponse;
import eu.paasage.upperware.security.server.controller.response.UserResponse;
import eu.paasage.upperware.security.server.data.repository.User;
......@@ -123,12 +124,11 @@ public class UserService {
userLdapRepository.save(user);
}
public void updateUser(NewUserRequest newUserRequest) throws AuthenticationException {
User user = userLdapRepository.findByUsernameAndPassword(newUserRequest.getUsername(), digestSHA(newUserRequest.getPassword()))
public void updateUser(UpdateExistingUserRequest updateExistingUserRequest) {
User user = userLdapRepository.findByUsername(updateExistingUserRequest.getUsername())
.orElseThrow(UserNotFoundException::new);
user.setUsername(newUserRequest.getUsername());
user.setFullName(newUserRequest.getFullName());
user.setMail(newUserRequest.getMail());
user.setFullName(updateExistingUserRequest.getFullName());
user.setMail(updateExistingUserRequest.getMail());
userLdapRepository.save(user);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment