Skip to content

Commit

Permalink
Fix indentation and add missing Javadoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raikbitters committed Dec 4, 2024
1 parent b3479d0 commit ca42dbd
Showing 1 changed file with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@ public class UiAuthenticationSuccessEventHandler {

private PersonalProjectService personalProjectService;

/**
* Event handler for successful UI authentication events.
* Updates the last login date for the user and generates
* a personal project if the user has no projects.
*/
@Autowired
public UiAuthenticationSuccessEventHandler(UserRepository userRepository,
PersonalProjectService personalProjectService) {
this.userRepository = userRepository;
this.personalProjectService = personalProjectService;
}

/**
* Handles the UI user signed-in event.
* Updates the last login date for the user and generates
* a personal project if the user has no projects.
*
* @param event the UI user signed-in event
*/
@EventListener
@Transactional
public void onApplicationEvent(UiUserSignedInEvent event) {
Expand All @@ -67,20 +79,22 @@ public void onApplicationEvent(UiUserSignedInEvent event) {
}
}

private User acquireUser (Authentication authentication){
if (authentication instanceof ReportPortalSamlAuthentication rpAuth) {
User user = userRepository.findByLogin(rpAuth.getPrincipal())
.orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, rpAuth.getPrincipal()));

if (!user.getActive()) {
user.setActive(true);
userRepository.save(user);
}

return user;
} else {
return userRepository.findByLogin(authentication.getName())
.orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, authentication.getName()));
}
private User acquireUser(Authentication authentication) {
if (authentication instanceof ReportPortalSamlAuthentication rpAuth) {
return userRepository.findByLogin(rpAuth.getPrincipal())
.map(user -> {
if (!user.getActive()) {
user.setActive(true);
userRepository.save(user);
}
return user;
})
.orElseThrow(
() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, rpAuth.getPrincipal()));
} else {
return userRepository.findByLogin(authentication.getName())
.orElseThrow(
() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, authentication.getName()));
}
}
}

0 comments on commit ca42dbd

Please sign in to comment.