Skip to content

Commit

Permalink
Merge pull request #344 from reportportal/EPMRPP-96070-saml-uuid
Browse files Browse the repository at this point in the history
EPMRPP-96070 || Fix handling of the locked account
  • Loading branch information
pbortnik authored Oct 18, 2024
2 parents 3219456 + 19d5f5c commit 813ba8b
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
package com.epam.reportportal.auth.event;

import com.epam.reportportal.auth.integration.saml.ReportPortalSamlAuthentication;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.dao.UserRepository;
import com.epam.ta.reportportal.entity.project.Project;
import com.epam.ta.reportportal.entity.user.User;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.util.PersonalProjectService;
import com.epam.reportportal.rules.exception.ErrorType;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.security.authentication.LockedException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -57,6 +57,10 @@ public UiAuthenticationSuccessEventHandler(UserRepository userRepository,
@Transactional
public void onApplicationEvent(UiUserSignedInEvent event) {
String username = event.getAuthentication().getName();
if (!((ReportPortalUser) event.getAuthentication().getPrincipal()).isEnabled()) {
SecurityContextHolder.clearContext();
throw new LockedException("User account is locked");
}
userRepository.updateLastLoginDate(
Instant.ofEpochMilli(event.getTimestamp()),
username);
Expand Down

0 comments on commit 813ba8b

Please sign in to comment.