Skip to content

Commit

Permalink
Merge pull request #1185 from ORCID/removeImpersonationBackEnd
Browse files Browse the repository at this point in the history
removed impersonation fields from user object
  • Loading branch information
auumgn committed May 14, 2024
2 parents 3a1a172 + 06c713f commit 7874748
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -225,30 +221,14 @@ 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;
}

public void setMemberName(String memberName) {
this.memberName = memberName;
}

public boolean isMfaEnabled() {
return mfaEnabled;
}
Expand Down Expand Up @@ -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 + '\'' + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ public Optional<UserDTO> 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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<User> loginAsUser = userService.getUserByLogin(userDTO.getLoginAs());
userDTO = userMapper.toUserDTO(loginAsUser.get());
userDTO.setLoggedAs(true);
}
return userDTO;
return userMapper.toUserDTO(user);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> 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<Void> logoutAsSwitchedUser(@RequestParam(value = "username", required = true) String username) {
Optional<User> 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();
}
Expand Down

0 comments on commit 7874748

Please sign in to comment.