Skip to content

Commit

Permalink
Merge branch 'develop' into feature/orgs
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	src/main/java/com/epam/reportportal/auth/event/UiAuthenticationSuccessEventHandler.java
  • Loading branch information
grabsefx committed Nov 15, 2024
2 parents a15317a + 813ba8b commit 61c966a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,23 +102,25 @@ private String validateEmail(String email) {

private User createNewUser(DirContextOperations ctx, Map<String, String> 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<String, String> syncAttributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Attribute> details = samlAuthentication.getDetails();

Expand Down

0 comments on commit 61c966a

Please sign in to comment.