diff --git a/src/main/java/no/fintlabs/user/LoggedOnUser.java b/src/main/java/no/fintlabs/user/LoggedOnUser.java new file mode 100644 index 0000000..11e2cc2 --- /dev/null +++ b/src/main/java/no/fintlabs/user/LoggedOnUser.java @@ -0,0 +1,16 @@ +package no.fintlabs.user; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class LoggedOnUser { + String firstName; + String lastName; + String organisationId; + String mail; +} diff --git a/src/main/java/no/fintlabs/user/UserController.java b/src/main/java/no/fintlabs/user/UserController.java index 9a9a743..0739d04 100644 --- a/src/main/java/no/fintlabs/user/UserController.java +++ b/src/main/java/no/fintlabs/user/UserController.java @@ -58,4 +58,18 @@ public ResponseEntity getDetailedUserById(@AuthenticationPrincipal else { return new ResponseEntity<>(HttpStatus.FORBIDDEN);} } + + @GetMapping("/me") + public ResponseEntity getLoggedOnUser(@AuthenticationPrincipal Jwt jwt){ + FintJwtEndUserPrincipal principal = FintJwtEndUserPrincipal.from(jwt); + LoggedOnUser loggedOnUser = new LoggedOnUser( + principal.getGivenName(), + principal.getSurname(), + principal.getOrgId(), + principal.getMail() + ); + + return new ResponseEntity<>(loggedOnUser,HttpStatus.OK); + } + } diff --git a/src/main/java/no/fintlabs/user/UserService.java b/src/main/java/no/fintlabs/user/UserService.java index 346b32b..d2a625a 100644 --- a/src/main/java/no/fintlabs/user/UserService.java +++ b/src/main/java/no/fintlabs/user/UserService.java @@ -42,7 +42,7 @@ public void save(User user) { private Runnable onSaveNewUser(User user) { return () -> { User newUser = userRepository.save(user); - //log.info("Create new user: " + user.getId()); + log.info("Create new user: " + user.getId()); memberService.process(memberService.create(newUser)); userEntityProducerService.publish(newUser); }; @@ -51,11 +51,10 @@ private Runnable onSaveNewUser(User user) { private Consumer onSaveExistingUser(User user) { return existingUser -> { user.setId(existingUser.getId()); - //log.info("Update user: " + user.getId()); + log.info("Update user: " + user.getId()); memberService.process(memberService.create(user)); userRepository.save(user); - User userToPublish = userRepository.findById(user.getId()).orElse(user); - userEntityProducerService.publish(userToPublish); + userEntityProducerService.publish(user); }; } diff --git a/src/main/resources/application-local.yaml b/src/main/resources/application-local.yaml index 6177b46..2810008 100644 --- a/src/main/resources/application-local.yaml +++ b/src/main/resources/application-local.yaml @@ -1,5 +1,6 @@ fint: org-id: fintlabs.no + application-id: fint-kontroll-user-catalog kafka: default-replicas: 1 bootstrap-servers: localhost:9092