Search in sources :

Example 1 with GitUser

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;
}
Also used : IRemoteGitManagerPrivileged(de.catma.repository.git.interfaces.IRemoteGitManagerPrivileged) GitlabManagerPrivileged(de.catma.repository.git.managers.GitlabManagerPrivileged) GitUser(de.catma.repository.git.GitUser)

Example 2 with GitUser

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;
}
Also used : GitlabManagerPrivileged(de.catma.repository.git.managers.GitlabManagerPrivileged) GitUser(de.catma.repository.git.GitUser)

Example 3 with GitUser

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;
}
Also used : IRemoteGitManagerPrivileged(de.catma.repository.git.interfaces.IRemoteGitManagerPrivileged) GitlabManagerPrivileged(de.catma.repository.git.managers.GitlabManagerPrivileged) GitUser(de.catma.repository.git.GitUser)

Example 4 with GitUser

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;
}
Also used : User(org.gitlab4j.api.models.User) GitUser(de.catma.repository.git.GitUser) PersonalAccessToken(org.gitlab4j.api.models.PersonalAccessToken) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) UserApi(org.gitlab4j.api.UserApi) GitUser(de.catma.repository.git.GitUser) Pair(de.catma.util.Pair)

Aggregations

GitUser (de.catma.repository.git.GitUser)4 GitlabManagerPrivileged (de.catma.repository.git.managers.GitlabManagerPrivileged)3 IRemoteGitManagerPrivileged (de.catma.repository.git.interfaces.IRemoteGitManagerPrivileged)2 Pair (de.catma.util.Pair)1 IOException (java.io.IOException)1 GitLabApiException (org.gitlab4j.api.GitLabApiException)1 UserApi (org.gitlab4j.api.UserApi)1 PersonalAccessToken (org.gitlab4j.api.models.PersonalAccessToken)1 User (org.gitlab4j.api.models.User)1