use of org.gitlab4j.api.UserApi in project catma by forTEXT.
the class GitlabManagerPrivileged method createUser.
// it's more convenient to work with the User class internally, which is why this method exists
private User createUser(String email, String username, String password, String publicname, String provider) throws IOException {
UserApi userApi = privilegedGitLabApi.getUserApi();
if (password == null) {
// generate a random password
password = RandomStringUtils.random(12, 0, GitlabUtils.PWD_CHARS.length - 1, false, false, GitlabUtils.PWD_CHARS, new SecureRandom());
}
User user = new User();
user.setEmail(email);
user.setUsername(username);
user.setName(publicname);
user.setIsAdmin(false);
user.setSkipConfirmation(true);
if (provider != null) {
Identity identity = new Identity();
identity.setExternUid(username);
identity.setProvider(provider);
user.setIdentities(Collections.singletonList(identity));
}
try {
// do not send a pwd reset link
user = userApi.createUser(user, password, false);
return user;
} catch (GitLabApiException e) {
throw new IOException("Failed to create user", e);
}
}
use of org.gitlab4j.api.UserApi in project catma by forTEXT.
the class GitlabManagerPrivileged method updateLastLoginAndGetTermsOfUseConsent.
public boolean updateLastLoginAndGetTermsOfUseConsent(de.catma.user.User catmaUser) {
try {
UserApi userApi = privilegedGitLabApi.getUserApi();
User user = userApi.getUser(catmaUser.getUserId());
Optional<CustomAttribute> optionalLastLoginAtt = Optional.empty();
if (user.getCustomAttributes() != null) {
optionalLastLoginAtt = user.getCustomAttributes().stream().filter(attr -> attr.getKey().equals(CustomAttributeName.last_login.name())).findFirst();
}
if (!optionalLastLoginAtt.isPresent()) {
logger.info(String.format("First Login of %1$s", user.getUsername()));
userApi.createCustomAttribute(user.getId(), CustomAttributeName.last_login.name(), LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
} else {
CustomAttribute lastLogin = optionalLastLoginAtt.get();
logger.info(String.format("Last Login of %1$s was %2$s.", user.getUsername(), lastLogin.getValue()));
lastLogin.setValue(LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
userApi.changeCustomAttribute(user.getId(), optionalLastLoginAtt.get());
}
if (user.getCustomAttributes() != null) {
return Boolean.valueOf(user.getCustomAttributes().stream().filter(attr -> attr.getKey().equals(CustomAttributeName.terms_of_use_consent_given.name())).findFirst().orElse(new CustomAttribute().withValue(Boolean.FALSE.toString())).getValue());
} else {
return false;
}
} catch (GitLabApiException e) {
logger.log(Level.SEVERE, "Could access custom attributes", e);
return false;
}
}
Aggregations