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);
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations