use of de.catma.repository.git.GitUser in project catma by forTEXT.
the class LocalUserLoginService method loggedInFromThirdParty.
@Override
public IRemoteGitManagerRestricted loggedInFromThirdParty(String identifier, String provider, String email, String name) throws IOException {
IRemoteGitManagerPrivileged gitlabManagerPrivileged = new GitlabManagerPrivileged();
Pair<GitUser, String> userAndToken = gitlabManagerPrivileged.acquireImpersonationToken(identifier, provider, email, name);
api = iRemoteGitManagerFactory.createFromImpersonationToken(userAndToken.getSecond());
return api;
}
use of de.catma.repository.git.GitUser in project catma by forTEXT.
the class LocalUserLoginService method login.
@Override
public IRemoteGitManagerRestricted login(String username, String password) throws IOException {
String user = System.getProperty("user.name");
Pair<GitUser, String> userTokenPair = new GitlabManagerPrivileged().acquireImpersonationToken(user, "catma", user + "@catma.de", user);
api = iRemoteGitManagerFactory.createFromImpersonationToken(userTokenPair.getSecond());
return api;
}
use of de.catma.repository.git.GitUser in project catma by forTEXT.
the class GitlabLoginService method loggedInFromThirdParty.
@Override
public IRemoteGitManagerRestricted loggedInFromThirdParty(String identifier, String provider, String email, String name) throws IOException {
IRemoteGitManagerPrivileged gitlabManagerPrivileged = new GitlabManagerPrivileged();
Pair<GitUser, String> userAndToken = gitlabManagerPrivileged.acquireImpersonationToken(identifier, provider, email, name);
api = iRemoteGitManagerFactory.createFromImpersonationToken(userAndToken.getSecond());
logLoginEvent("third party");
return api;
}
use of de.catma.repository.git.GitUser in project catma by forTEXT.
the class GitlabManagerPrivileged method acquireImpersonationToken.
@Override
public Pair<GitUser, String> acquireImpersonationToken(String identifier, String provider, String email, String name) throws IOException {
User user = this.acquireUser(identifier, provider, email, name);
UserApi customUserApi = this.privilegedGitLabApi.getUserApi();
try {
List<PersonalAccessToken> impersonationTokens = customUserApi.getImpersonationTokens(user.getId(), ImpersonationState.ACTIVE);
// revoke the default token if it exists actively
for (PersonalAccessToken token : impersonationTokens) {
if (token.getName().equals(GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME)) {
privilegedGitLabApi.getUserApi().revokeImpersonationToken(user.getId(), token.getId());
break;
}
}
} catch (GitLabApiException e) {
throw new IOException("Failed to revoke existing impersonation token", e);
}
String impersonationToken = this.createImpersonationToken(user.getId(), GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME);
if (impersonationToken == null) {
String errorMessage = String.format("Failed to acquire impersonation token for CATMA with identifier `%s`. " + "The creation of the token the associated GitLab user ID `%s` failed, no " + "active impersonation token called `%s` can be found!", identifier, user.getId(), GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME);
throw new IOException(errorMessage);
}
Pair<GitUser, String> retVal = new Pair<>(new GitUser(user), impersonationToken);
return retVal;
}
Aggregations