use of org.gitlab4j.api.models.User 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.models.User 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;
}
}
use of org.gitlab4j.api.models.User in project catma by forTEXT.
the class GitlabManagerPrivileged method modifyUserAttributes.
@Override
public void modifyUserAttributes(int userId, String name, String password) throws IOException {
try {
User user = privilegedGitLabApi.getUserApi().getUser(userId);
BiConsumer<String, Consumer<String>> fExecIfNotNull = (attr, func) -> {
if (attr != null)
func.accept(attr);
};
fExecIfNotNull.accept(name, user::setName);
this.privilegedGitLabApi.getUserApi().updateUser(user, password);
} catch (GitLabApiException e) {
throw new IOException("failed to check for username", e);
}
}
use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.
the class UserApi method getblockedUsers.
/**
* Get a list of blocked users using the specified page and per page settings.
* <p>
* GET /users?blocked=true
*
* @param page the page to get
* @param perPage the number of users per page
* @return the list of blocked Users in the specified range
* @throws GitLabApiException if any exception occurs
*/
public List<User> getblockedUsers(int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("blocked", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() {
}));
}
use of org.gitlab4j.api.models.User in project choerodon-starters by open-hand.
the class UserApi method findUsers.
/**
* Search users by Email or username
* <p>
* GET /users?search=:email_or_username
*
* @param emailOrUsername the email or username to search for
* @return the User List with the email or username like emailOrUsername
* @throws GitLabApiException if any exception occurs
*/
public List<User> findUsers(String emailOrUsername) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("search", emailOrUsername, true).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() {
}));
}
Aggregations