Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IM-562 fix: Bug with uppercase/lowercase names #225

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<Task> build(TaskParameters parameters) {
} else {
throw new ClassCastException();
}
User user = userRepository.findByName(param.username).orElseThrow();
User user = userRepository.findByNameIgnoreCase(param.username).orElseThrow();
ArrayList<Task> ret = new ArrayList<Task>(2);

Set<GroupEntry> optIn = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void checkUserName(EmailTemplate emailTemplate) {
if (emailTemplate.getAuthorUsername() == null) {
emailTemplate.setAuthorUsername(profileService.getCurrentUserProfile(false).getUsername());
} else {
Optional<User> user = userRepository.findByName(emailTemplate.getAuthorUsername());
Optional<User> user = userRepository.findByNameIgnoreCase(emailTemplate.getAuthorUsername());
if (!user.isPresent()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "User not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
public interface UserRepository extends ResourceRepository<User, String>{

Optional<User> findById(String id);

Optional<User> findByName(String username); // need exactly the username

default Optional<User> findByName(String username) {
return findByNameIgnoreCase(username);
}; // need exactly the username

Optional<User> findByNameIgnoreCase(String username);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public boolean isUser(String userName) {

String preferredUsername = principal.getKeycloakSecurityContext().getToken().getPreferredUsername();
if (preferredUsername != null) {
return preferredUsername.equals(userName);
return preferredUsername.equals(userName.toLowerCase());
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,41 +182,6 @@ public class UserProfileController {

}

// TODO keycloak
// @PutMapping(value = API.HUB.USER_BASE_ID, params = API.HUB.PARAMETERS.USER_SET_EMAIL)
// public ResponseEntity< ? > updateUserEmail(@PathVariable String id,
// @RequestParam(API.HUB.PARAMETERS.USER_SET_EMAIL) String setPassword,
// @RequestBody UpdateEmailRequest updateEmailRequest) {
//
// /* Check user and password are correct */
// try {
// userAuthService.getAuthResponse(updateEmailRequest.getUsername(), updateEmailRequest.getPassword(),
// updateEmailRequest.isRemote());
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Incorrect password.");
// }
//
// /* Check token is correct */
// TokenVerifyEmailClickback token = (TokenVerifyEmailClickback) tokenService.getAndVerifyToken(id,
// updateEmailRequest.getToken(), TokenType.verifyEmail);
// if (token == null) {
// throw new ActivationTokenFailedException("User Verification token failed");
// }
//
// /* Update user email */
// try {
// userService.updateUserEmail(id, updateEmailRequest.getEmail());
//
// tokenService.deleteToken(token.getTokenString());
//
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
// }
//
// JSONObject resp = new JSONObject();
// return new ResponseEntity<JSONObject>(resp, HttpStatus.CREATED);
// }

@GetMapping(value = API.HUB.USER_BASE_ID, params = "remote-login")
@PreAuthorize("@securityService.isUser(#id)")
public ResponseEntity< ? > getFullUserProfile(@PathVariable String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class UserTagServiceImpl implements UserTagService {
TagNotificationRepository notificationRepository;

private User findUserByName(String username) {
return userRepository.findByName(username).orElseThrow(() -> new BadRequestException("User is not present."));
return userRepository.findByNameIgnoreCase(username).orElseThrow(() -> new BadRequestException("User is not present."));
}

private boolean doesTagExistInTheDatabase(MongoTag tag) {
Expand Down