From 06c713f8df67b477dfa439ff6e66ffa0eab8dc60 Mon Sep 17 00:00:00 2001 From: George Nash Date: Thu, 9 May 2024 15:54:50 +0100 Subject: [PATCH] removed impersonation fields from user object --- .../service/user/dto/UserDTO.java | 27 ++------------- .../service/user/mapper/UserMapper.java | 2 -- .../service/user/services/UserService.java | 1 - .../user/web/rest/AccountResource.java | 8 +---- .../service/user/web/rest/UserResource.java | 34 ------------------- 5 files changed, 4 insertions(+), 68 deletions(-) diff --git a/user-service/src/main/java/org/orcid/memberportal/service/user/dto/UserDTO.java b/user-service/src/main/java/org/orcid/memberportal/service/user/dto/UserDTO.java index 36eac8e24..99f73e2c5 100644 --- a/user-service/src/main/java/org/orcid/memberportal/service/user/dto/UserDTO.java +++ b/user-service/src/main/java/org/orcid/memberportal/service/user/dto/UserDTO.java @@ -61,12 +61,8 @@ public class UserDTO { private boolean isAdmin = false; - private boolean isLoggedAs = false; - - private String loginAs; - private String memberName; - + private boolean mfaEnabled; public UserDTO() { @@ -225,22 +221,6 @@ public void setIsAdmin(boolean isAdmin) { this.isAdmin = isAdmin; } - public boolean isLoggedAs() { - return isLoggedAs; - } - - public void setLoggedAs(boolean isLoggedAs) { - this.isLoggedAs = isLoggedAs; - } - - public String getLoginAs() { - return loginAs; - } - - public void setLoginAs(String loginAs) { - this.loginAs = loginAs; - } - public String getMemberName() { return memberName; } @@ -248,7 +228,7 @@ public String getMemberName() { public void setMemberName(String memberName) { this.memberName = memberName; } - + public boolean isMfaEnabled() { return mfaEnabled; } @@ -355,7 +335,6 @@ public boolean equals(Object obj) { public String toString() { return "UserDTO{firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + ", email='" + email + '\'' + ", imageUrl='" + imageUrl + '\'' + ", activated=" + activated + ", langKey='" + langKey + '\'' + ", createdBy=" + createdBy + ", createdDate=" + createdDate + ", lastModifiedBy='" - + lastModifiedBy + '\'' + ", lastModifiedDate=" + lastModifiedDate + ", authorities=" + authorities + " loginAs= " + loginAs + " isLoggedAs= " - + isLoggedAs + ", mainContact='" + mainContact + '\'' + "}"; + + lastModifiedBy + '\'' + ", lastModifiedDate=" + lastModifiedDate + ", authorities=" + authorities + ", mainContact='" + mainContact + '\'' + "}"; } } diff --git a/user-service/src/main/java/org/orcid/memberportal/service/user/mapper/UserMapper.java b/user-service/src/main/java/org/orcid/memberportal/service/user/mapper/UserMapper.java index 0155ae212..334147e78 100644 --- a/user-service/src/main/java/org/orcid/memberportal/service/user/mapper/UserMapper.java +++ b/user-service/src/main/java/org/orcid/memberportal/service/user/mapper/UserMapper.java @@ -32,7 +32,6 @@ public User toUser(UserDTO userDTO) { user.setAdmin(userDTO.getIsAdmin()); user.setMainContact(user.getMainContact()); user.setId(userDTO.getId()); - user.setLoginAs(userDTO.getLoginAs()); return user; } @@ -53,7 +52,6 @@ public UserDTO toUserDTO(User user) { userDTO.setMemberName(user.getMemberName()); userDTO.setMainContact(user.getMainContact()); userDTO.setId(user.getId()); - userDTO.setLoginAs(user.getLoginAs()); userDTO.setIsAdmin(user.getAdmin()); userDTO.setMfaEnabled(user.getMfaEnabled() != null ? user.getMfaEnabled() : false); return userDTO; diff --git a/user-service/src/main/java/org/orcid/memberportal/service/user/services/UserService.java b/user-service/src/main/java/org/orcid/memberportal/service/user/services/UserService.java index ff32d280b..e64100023 100644 --- a/user-service/src/main/java/org/orcid/memberportal/service/user/services/UserService.java +++ b/user-service/src/main/java/org/orcid/memberportal/service/user/services/UserService.java @@ -289,7 +289,6 @@ public Optional updateUser(UserDTO userDTO) { user.setMainContact(userDTO.getMainContact()); user.setSalesforceId(userDTO.getSalesforceId()); user.setMemberName(memberService.getMemberNameBySalesforce(userDTO.getSalesforceId())); - user.setLoginAs(userDTO.getLoginAs()); user.setLangKey(userDTO.getLangKey() != null ? userDTO.getLangKey() : user.getLangKey()); user.setAdmin(userDTO.getIsAdmin()); diff --git a/user-service/src/main/java/org/orcid/memberportal/service/user/web/rest/AccountResource.java b/user-service/src/main/java/org/orcid/memberportal/service/user/web/rest/AccountResource.java index c1b798153..14b805719 100644 --- a/user-service/src/main/java/org/orcid/memberportal/service/user/web/rest/AccountResource.java +++ b/user-service/src/main/java/org/orcid/memberportal/service/user/web/rest/AccountResource.java @@ -101,13 +101,7 @@ public void saveAccount(@Valid @RequestBody UserDTO userDTO) { @GetMapping("/account") public UserDTO getAccount() { User user = userService.getCurrentUser(); - UserDTO userDTO = userMapper.toUserDTO(user); - if (!StringUtils.isAllBlank(userDTO.getLoginAs())) { - Optional loginAsUser = userService.getUserByLogin(userDTO.getLoginAs()); - userDTO = userMapper.toUserDTO(loginAsUser.get()); - userDTO.setLoggedAs(true); - } - return userDTO; + return userMapper.toUserDTO(user); } /** diff --git a/user-service/src/main/java/org/orcid/memberportal/service/user/web/rest/UserResource.java b/user-service/src/main/java/org/orcid/memberportal/service/user/web/rest/UserResource.java index 362cc6847..23c96cb7f 100644 --- a/user-service/src/main/java/org/orcid/memberportal/service/user/web/rest/UserResource.java +++ b/user-service/src/main/java/org/orcid/memberportal/service/user/web/rest/UserResource.java @@ -436,40 +436,6 @@ public boolean getOwner(@PathVariable String salesforceId) { return userService.hasOwnerForSalesforceId(salesforceId); } - /** - * {@code POST /switch_user} : Switch user - * - * @return the {@link ResponseEntity} with status {@code 200 (OK)}. - */ - @PostMapping("/switch_user") - @PreAuthorize("hasRole(\"" + AuthoritiesConstants.ADMIN + "\")") - public ResponseEntity switchUser(@RequestParam(value = "username", required = true) String username) { - User user = userService.getCurrentUser(); - UserDTO userDTO = userMapper.toUserDTO(user); - userDTO.setLoginAs(username); - userDTO.setIsAdmin(true); - userService.updateUser(userDTO); - return ResponseEntity.status(HttpStatus.FOUND).location(URI.create("/")).build(); - } - - /** - * {@code POST /logout_as} : Switch user - * - * @return the {@link ResponseEntity} with status {@code 200 (OK)}. - */ - @PostMapping("/logout_as") - public ResponseEntity logoutAsSwitchedUser(@RequestParam(value = "username", required = true) String username) { - Optional authUser = userService.getUserByLogin(SecurityUtils.getCurrentUserLogin().get()); - if (authUser.isPresent()) { - UserDTO userDTO = userMapper.toUserDTO(authUser.get()); - userDTO.setIsAdmin(true); - userDTO.setLoginAs(null); - userService.updateUser(userDTO); - } - - return ResponseEntity.status(HttpStatus.FOUND).location(URI.create("/")).build(); - } - private User getCurrentUser() { return userRepository.findOneByEmailIgnoreCase(SecurityUtils.getCurrentUserLogin().get()).get(); }