use of de.tum.in.www1.artemis.exception.JenkinsException in project Artemis by ls1intum.
the class JenkinsUserManagementService method createUser.
/**
* Creates a user in Jenkins. Note that the user login acts as
* a unique identifier in Jenkins.
*
* @param user The user to create
* @param password The user's password
*/
@Override
public void createUser(User user, String password) throws ContinuousIntegrationException {
if (user.getLogin().equals(jenkinsAdminUsername)) {
log.debug("Jenkins createUser: Skipping jenkinsAdminUser: {}.", jenkinsAdminUsername);
return;
}
// Only create a user if it doesn't already exist.
if (getUser(user.getLogin()) != null) {
throw new JenkinsException("Cannot create user: " + user.getLogin() + " because the login already exists");
}
// Make sure the user login contains legal characters.
if (!isUserLoginLegal(user)) {
throw new JenkinsException("Cannot create user: " + user.getLogin() + " because the login contains illegal characters");
}
try {
// Create the Jenkins user
var uri = UriComponentsBuilder.fromHttpUrl(jenkinsServerUrl.toString()).pathSegment("securityRealm", "createAccountByAdmin").build().toUri();
restTemplate.exchange(uri, HttpMethod.POST, getCreateUserFormHttpEntity(user, password), Void.class);
// Adds the user to groups of existing programming exercises
addUserToGroups(user.getLogin(), getUserWithGroups(user).getGroups());
} catch (RestClientException e) {
throw new JenkinsException("Cannot create user: " + user.getLogin(), e);
}
}
use of de.tum.in.www1.artemis.exception.JenkinsException in project ArTEMiS by ls1intum.
the class JenkinsUserManagementService method createUser.
/**
* Creates a user in Jenkins. Note that the user login acts as
* a unique identifier in Jenkins.
*
* @param user The user to create
*/
@Override
public void createUser(User user) throws ContinuousIntegrationException {
if (user.getLogin().equals(jenkinsAdminUsername)) {
log.debug("Jenkins createUser: Skipping jenkinsAdminUser: {}.", jenkinsAdminUsername);
return;
}
// Only create a user if it doesn't already exist.
if (getUser(user.getLogin()) != null) {
throw new JenkinsException("Cannot create user: " + user.getLogin() + " because the login already exists");
}
// Make sure the user login contains legal characters.
if (!isUserLoginLegal(user)) {
throw new JenkinsException("Cannot create user: " + user.getLogin() + " because the login contains illegal characters");
}
try {
// Create the Jenkins user
var uri = UriComponentsBuilder.fromHttpUrl(jenkinsServerUrl.toString()).pathSegment("securityRealm", "createAccountByAdmin").build().toUri();
restTemplate.exchange(uri, HttpMethod.POST, getCreateUserFormHttpEntity(user), Void.class);
// Adds the user to groups of existing programming exercises
addUserToGroups(user.getLogin(), getUserWithGroups(user).getGroups());
} catch (RestClientException e) {
throw new JenkinsException("Cannot create user: " + user.getLogin(), e);
}
}
Aggregations