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
Branches
2 merge requests!284Preparing August Release,!260Resolve "Sharing Plattform: Prüfung: Gitlab Login für Simon in Produktion funktioniert nicht zuverlässig."
This commit is part of merge request !260. Comments created here will be created in the context of that merge request.
......@@ -111,7 +111,6 @@ public class GitLabRepository {
@Cacheable(cacheNames = FULLPATH_OF_GROUP_CACHE)
public String getFullPathOfGroup(final Long groupId) throws GitLabApiException {
final Group group = getAdminGitLabApi().getGroupApi().getGroup(groupId);
final String fullPath = group.getFullPath();
return fullPath;
return group.getFullPath();
}
}
......@@ -12,6 +12,7 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Stream;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -123,14 +124,7 @@ public class UserDetailsFetcher {
}
userToken = requestGitLabUserToken(gitUser, gitLabApi);
List<Membership> memberships = gitLabApi.getUserApi().getMemberships(gitUser.getId());
for (Membership membership : memberships) {
if (MembershipSourceType.NAMESPACE.equals(membership.getSourceType())) {
final Long groupId = membership.getSourceId();
final String fullPath = gitLabRepository.getFullPathOfGroup(groupId);
authorities.add(fullPath);
}
}
getUserMemberships(gitLabApi, gitUser).forEach(gitAuthority -> authorities.add(gitAuthority));
modified |= updateAttribute(gitUser.getAvatarUrl(), u.getImageUrl(), u::setImageUrl);
modified |= updateAttribute(gitUser.getEmail(), u.getEmail(), u::setEmail);
......@@ -151,6 +145,36 @@ public class UserDetailsFetcher {
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() {
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