This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit a9e35138 authored by Michael Breu's avatar Michael Breu
Browse files

P;D

parent 99c34f67
2 merge requests!284Preparing August Release,!260Resolve "Sharing Plattform: Prüfung: Gitlab Login für Simon in Produktion funktioniert nicht zuverlässig."
...@@ -111,7 +111,6 @@ public class GitLabRepository { ...@@ -111,7 +111,6 @@ public class GitLabRepository {
@Cacheable(cacheNames = FULLPATH_OF_GROUP_CACHE) @Cacheable(cacheNames = FULLPATH_OF_GROUP_CACHE)
public String getFullPathOfGroup(final Long groupId) throws GitLabApiException { public String getFullPathOfGroup(final Long groupId) throws GitLabApiException {
final Group group = getAdminGitLabApi().getGroupApi().getGroup(groupId); final Group group = getAdminGitLabApi().getGroupApi().getGroup(groupId);
final String fullPath = group.getFullPath(); return group.getFullPath();
return fullPath;
} }
} }
...@@ -12,6 +12,7 @@ import java.util.List; ...@@ -12,6 +12,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Stream;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -123,14 +124,7 @@ public class UserDetailsFetcher { ...@@ -123,14 +124,7 @@ public class UserDetailsFetcher {
} }
userToken = requestGitLabUserToken(gitUser, gitLabApi); userToken = requestGitLabUserToken(gitUser, gitLabApi);
List<Membership> memberships = gitLabApi.getUserApi().getMemberships(gitUser.getId()); getUserMemberships(gitLabApi, gitUser).forEach(gitAuthority -> authorities.add(gitAuthority));
for (Membership membership : memberships) {
if (MembershipSourceType.NAMESPACE.equals(membership.getSourceType())) {
final Long groupId = membership.getSourceId();
final String fullPath = gitLabRepository.getFullPathOfGroup(groupId);
authorities.add(fullPath);
}
}
modified |= updateAttribute(gitUser.getAvatarUrl(), u.getImageUrl(), u::setImageUrl); modified |= updateAttribute(gitUser.getAvatarUrl(), u.getImageUrl(), u::setImageUrl);
modified |= updateAttribute(gitUser.getEmail(), u.getEmail(), u::setEmail); modified |= updateAttribute(gitUser.getEmail(), u.getEmail(), u::setEmail);
...@@ -151,6 +145,36 @@ public class UserDetailsFetcher { ...@@ -151,6 +145,36 @@ public class UserDetailsFetcher {
return new UserDetailsInfo(userToken, modified); return new UserDetailsInfo(userToken, modified);
} }
/**
* returns the pathes of all groups the user belongs to
*
* @param gitLabApi
* @param gitUser
* @return
*/
public Stream<String> getUserMemberships(GitLabApi gitLabApi, User gitUser) {
List<Membership> memberships;
try {
memberships = gitLabApi.getUserApi().getMemberships(gitUser.getId());
} catch (GitLabApiException e) {
logger.warn("Cannot read group path for {}", gitUser);
return Stream.empty();
}
return memberships
.stream()
.filter(membership -> MembershipSourceType.NAMESPACE.equals(membership.getSourceType()))
.map(membership -> membership.getSourceId()) // map to group id
.map(groupId -> {
try {
return gitLabRepository.getFullPathOfGroup(groupId);
} catch (GitLabApiException e) {
logger.warn("Cannot read group path for {}", groupId);
return null;
}
})
.filter(path -> path != null);
}
private String generatePassword() { private String generatePassword() {
return RandomStringUtils.random(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz=%$-."); return RandomStringUtils.random(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz=%$-.");
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment