diff --git a/src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java b/src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java index 923d063a..8633b3c7 100644 --- a/src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java +++ b/src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java @@ -28,7 +28,9 @@ 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; @@ -55,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); if (MapUtils.isEmpty(acquireUser(event.getAuthentication()).getOrganizationDetails())) { diff --git a/src/main/java/com/epam/reportportal/auth/integration/github/GitHubUserReplicator.java b/src/main/java/com/epam/reportportal/auth/integration/github/GitHubUserReplicator.java index 68edee81..c98aac67 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/github/GitHubUserReplicator.java +++ b/src/main/java/com/epam/reportportal/auth/integration/github/GitHubUserReplicator.java @@ -45,6 +45,7 @@ import java.util.Date; import java.util.Objects; import java.util.Optional; +import java.util.UUID; import org.apache.commons.lang3.StringUtils; import org.springframework.core.io.Resource; import org.springframework.http.ResponseEntity; @@ -143,8 +144,10 @@ private void updateUser(User user, UserResource userResource, GitHubClient gitHu private User createUser(UserResource userResource, GitHubClient gitHubClient) { User user = new User(); - String login = normalizeId(userResource.getLogin()); - user.setLogin(login); + user.setLogin(normalizeId(userResource.getLogin())); + user.setUuid(UUID.randomUUID()); + user.setActive(Boolean.TRUE); + updateUser(user, userResource, gitHubClient); user.setUserType(UserType.GITHUB); user.setRole(UserRole.USER); diff --git a/src/main/java/com/epam/reportportal/auth/integration/ldap/LdapUserReplicator.java b/src/main/java/com/epam/reportportal/auth/integration/ldap/LdapUserReplicator.java index b285e2f2..d41190f5 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/ldap/LdapUserReplicator.java +++ b/src/main/java/com/epam/reportportal/auth/integration/ldap/LdapUserReplicator.java @@ -34,6 +34,7 @@ import com.epam.ta.reportportal.util.PersonalProjectService; import java.util.Map; import java.util.Optional; +import java.util.UUID; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ldap.core.DirContextOperations; @@ -101,23 +102,25 @@ private String validateEmail(String email) { private User createNewUser(DirContextOperations ctx, Map syncAttributes, String email, String login) { - User newUser = new User(); - newUser.setLogin(login); + User user = new User(); + user.setLogin(login); + user.setUuid(UUID.randomUUID()); + user.setActive(Boolean.TRUE); String fullName = getFullName(ctx, syncAttributes); - newUser.setFullName(fullName); + user.setFullName(fullName); checkEmail(email); - newUser.setEmail(email); - newUser.setMetadata(defaultMetaData()); - newUser.setUserType(UserType.LDAP); - newUser.setRole(UserRole.USER); - newUser.setExpired(false); + user.setEmail(email); + user.setMetadata(defaultMetaData()); + user.setUserType(UserType.LDAP); + user.setRole(UserRole.USER); + user.setExpired(false); - final Project project = generatePersonalProject(newUser); - newUser.getProjects().add(project.getUsers().iterator().next()); + final Project project = generatePersonalProject(user); + user.getProjects().add(project.getUsers().iterator().next()); - return userRepository.save(newUser); + return userRepository.save(user); } private String getFullName(DirContextOperations ctx, Map syncAttributes) { diff --git a/src/main/java/com/epam/reportportal/auth/integration/saml/SamlUserReplicator.java b/src/main/java/com/epam/reportportal/auth/integration/saml/SamlUserReplicator.java index ff9015aa..47791f1f 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/saml/SamlUserReplicator.java +++ b/src/main/java/com/epam/reportportal/auth/integration/saml/SamlUserReplicator.java @@ -43,6 +43,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.UUID; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; @@ -102,6 +103,8 @@ public User replicateUser(ReportPortalSamlAuthentication samlAuthentication) { User user = new User(); user.setLogin(userName); + user.setUuid(UUID.randomUUID()); + user.setActive(Boolean.TRUE); List details = samlAuthentication.getDetails();