Search in sources :

Example 1 with UserApi

use of org.gitlab4j.api.UserApi in project Artemis by ls1intum.

the class GitLabUserManagementService method updateBasicUserInformation.

/**
 * Updates the basic information of the Gitlab user based on the passed Artemis user.
 *
 * @param userLogin the username of the user
 * @param user the Artemis user to update
 * @param shouldUpdatePassword if the Gitlab password should be updated
 * @return the updated Gitlab user
 * @throws GitLabApiException if the user cannot be retrieved or cannot update the user
 */
private org.gitlab4j.api.models.User updateBasicUserInformation(String userLogin, User user, boolean shouldUpdatePassword) throws GitLabApiException {
    UserApi userApi = gitlabApi.getUserApi();
    final var gitlabUser = userApi.getUser(userLogin);
    if (gitlabUser == null) {
        // in case the user does not exist in Gitlab, we cannot update it
        log.warn("User {} does not exist in Gitlab and cannot be updated!", userLogin);
        return null;
    }
    gitlabUser.setName(getUsersName(user));
    gitlabUser.setUsername(user.getLogin());
    gitlabUser.setEmail(user.getEmail());
    // Skip confirmation is necessary in order to update the email without user re-confirmation
    gitlabUser.setSkipConfirmation(true);
    String password = shouldUpdatePassword ? passwordService.decryptPassword(user) : null;
    return userApi.updateUser(gitlabUser, password);
}
Also used : UserApi(org.gitlab4j.api.UserApi)

Example 2 with UserApi

use of org.gitlab4j.api.UserApi in project OpenUnison by TremoloSecurity.

the class GitlabUserProvider method init.

@Override
public void init(Map<String, Attribute> cfg, ConfigManager cfgMgr, String name) throws ProvisioningException {
    this.token = cfg.get("token").getValues().get(0);
    this.url = cfg.get("url").getValues().get(0);
    this.name = name;
    this.gitLabApi = new GitLabApi(this.url, this.token);
    this.userApi = new UserApi(this.gitLabApi);
    this.groupApi = new GroupApi(this.gitLabApi);
    this.cfgMgr = cfgMgr;
}
Also used : GitLabApi(org.gitlab4j.api.GitLabApi) GroupApi(org.gitlab4j.api.GroupApi) UserApi(org.gitlab4j.api.UserApi)

Example 3 with UserApi

use of org.gitlab4j.api.UserApi in project ArTEMiS by ls1intum.

the class GitLabUserManagementService method updateBasicUserInformation.

/**
 * Updates the basic information of the Gitlab user based on the passed Artemis user.
 *
 * @param userLogin the username of the user
 * @param user the Artemis user to update
 * @param shouldUpdatePassword if the Gitlab password should be updated
 * @return the updated Gitlab user
 * @throws GitLabApiException if the user cannot be retrieved or cannot update the user
 */
private org.gitlab4j.api.models.User updateBasicUserInformation(String userLogin, User user, boolean shouldUpdatePassword) throws GitLabApiException {
    UserApi userApi = gitlabApi.getUserApi();
    final var gitlabUser = userApi.getUser(userLogin);
    if (gitlabUser == null) {
        // in case the user does not exist in Gitlab, we cannot update it
        log.warn("User {} does not exist in Gitlab and cannot be updated!", userLogin);
        return null;
    }
    gitlabUser.setName(getUsersName(user));
    gitlabUser.setUsername(user.getLogin());
    gitlabUser.setEmail(user.getEmail());
    // Skip confirmation is necessary in order to update the email without user re-confirmation
    gitlabUser.setSkipConfirmation(true);
    String password = shouldUpdatePassword ? passwordService.decryptPassword(user) : null;
    return userApi.updateUser(gitlabUser, password);
}
Also used : UserApi(org.gitlab4j.api.UserApi)

Example 4 with UserApi

use of org.gitlab4j.api.UserApi in project ArTEMiS by ls1intum.

the class GitLabUserManagementService method updateBasicUserInformation.

/**
 * Updates the basic information of the Gitlab user based on the passed Artemis user.
 *
 * @param userLogin the username of the user
 * @param user the Artemis user to update
 * @param newPassword if provided the Gitlab password should be updated to the new value
 * @return the updated Gitlab user
 * @throws GitLabApiException if the user cannot be retrieved or cannot update the user
 */
private org.gitlab4j.api.models.User updateBasicUserInformation(String userLogin, User user, String newPassword) throws GitLabApiException {
    UserApi userApi = gitlabApi.getUserApi();
    final var gitlabUser = userApi.getUser(userLogin);
    if (gitlabUser == null) {
        // in case the user does not exist in Gitlab, we cannot update it
        log.warn("User {} does not exist in Gitlab and cannot be updated!", userLogin);
        return null;
    }
    gitlabUser.setName(getUsersName(user));
    gitlabUser.setUsername(user.getLogin());
    gitlabUser.setEmail(user.getEmail());
    // Skip confirmation is necessary in order to update the email without user re-confirmation
    gitlabUser.setSkipConfirmation(true);
    return userApi.updateUser(gitlabUser, newPassword);
}
Also used : UserApi(org.gitlab4j.api.UserApi)

Example 5 with UserApi

use of org.gitlab4j.api.UserApi in project ArTEMiS by ls1intum.

the class GitLabUserManagementService method generateVersionControlAccessTokenIfNecessary.

/**
 * Generate a version control access token and store it in the user object, if it is needed.
 * It is needed if
 * 1. the config option is enabled, and
 * 2. the user does not yet have an access token
 *
 * The GitLab user will be extracted from the Gitlab user API
 *
 * @param user the Artemis user (where the token will be stored)
 */
public void generateVersionControlAccessTokenIfNecessary(User user) {
    UserApi userApi = gitlabApi.getUserApi();
    final org.gitlab4j.api.models.User gitlabUser;
    try {
        gitlabUser = userApi.getUser(user.getLogin());
        if (gitlabUser == null) {
            // No GitLab user is found -> Do nothing
            return;
        }
        generateVersionControlAccessTokenIfNecessary(gitlabUser, user);
    } catch (GitLabApiException e) {
        log.error("Could not generate a Gitlab access token for user " + user.getLogin(), e);
    }
}
Also used : GitLabApiException(org.gitlab4j.api.GitLabApiException) UserApi(org.gitlab4j.api.UserApi)

Aggregations

UserApi (org.gitlab4j.api.UserApi)17 GitLabApiException (org.gitlab4j.api.GitLabApiException)7 User (org.gitlab4j.api.models.User)5 GitUser (de.catma.repository.git.GitUser)4 IOException (java.io.IOException)3 PersonalAccessToken (org.gitlab4j.api.models.PersonalAccessToken)3 AfterEach (org.junit.jupiter.api.AfterEach)3 EventBus (com.google.common.eventbus.EventBus)2 BackgroundService (de.catma.backgroundservice.BackgroundService)2 File (java.io.File)2 GitLabApi (org.gitlab4j.api.GitLabApi)2 GroupApi (org.gitlab4j.api.GroupApi)2 CustomAttribute (org.gitlab4j.api.models.CustomAttribute)2 Pair (de.catma.util.Pair)1 SecureRandom (java.security.SecureRandom)1 ProjectApi (org.gitlab4j.api.ProjectApi)1 Identity (org.gitlab4j.api.models.Identity)1 Project (org.gitlab4j.api.models.Project)1 After (org.junit.After)1 Test (org.junit.jupiter.api.Test)1