use of com.google.gerrit.extensions.common.HttpPasswordInput in project gerrit by GerritCodeReview.
the class SetAccountCommand method setAccount.
private void setAccount() throws Failure {
user = genericUserFactory.create(id);
rsrc = new AccountResource(user.asIdentifiedUser());
try {
for (String email : addEmails) {
addEmail(email);
}
for (String email : deleteEmails) {
deleteEmail(email);
}
if (preferredEmail != null) {
putPreferred(preferredEmail);
}
if (fullName != null) {
NameInput in = new NameInput();
in.name = fullName;
putName.apply(rsrc, in);
}
if (httpPassword != null || clearHttpPassword || generateHttpPassword) {
HttpPasswordInput in = new HttpPasswordInput();
in.httpPassword = httpPassword;
if (generateHttpPassword) {
in.generate = true;
}
Response<String> resp = putHttpPassword.apply(rsrc, in);
if (generateHttpPassword) {
stdout.print("New password: " + resp.value() + "\n");
}
}
if (active) {
putActive.apply(rsrc, null);
} else if (inactive) {
try {
deleteActive.apply(rsrc, null);
} catch (ResourceNotFoundException e) {
// user is already inactive
}
}
addSshKeys = readSshKey(addSshKeys);
if (!addSshKeys.isEmpty()) {
addSshKeys(addSshKeys);
}
deleteSshKeys = readSshKey(deleteSshKeys);
if (!deleteSshKeys.isEmpty()) {
deleteSshKeys(deleteSshKeys);
}
for (String externalId : externalIdsToDelete) {
deleteExternalId(externalId);
}
} catch (RestApiException e) {
throw die(e.getMessage());
} catch (Exception e) {
throw new Failure(1, "unavailable", e);
}
}
use of com.google.gerrit.extensions.common.HttpPasswordInput in project gerrit by GerritCodeReview.
the class PutHttpPassword method apply.
@Override
public Response<String> apply(AccountResource rsrc, HttpPasswordInput input) throws AuthException, ResourceNotFoundException, ResourceConflictException, IOException, ConfigInvalidException, PermissionBackendException {
if (!self.get().hasSameAccountId(rsrc.getUser())) {
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
}
if (input == null) {
input = new HttpPasswordInput();
}
input.httpPassword = Strings.emptyToNull(input.httpPassword);
String newPassword;
if (input.generate) {
newPassword = generate();
} else if (input.httpPassword == null) {
newPassword = null;
} else {
// Only administrators can explicitly set the password.
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
newPassword = input.httpPassword;
}
return apply(rsrc.getUser(), newPassword);
}
use of com.google.gerrit.extensions.common.HttpPasswordInput in project gerrit by GerritCodeReview.
the class AccountApiImpl method generateHttpPassword.
@Override
public String generateHttpPassword() throws RestApiException {
HttpPasswordInput input = new HttpPasswordInput();
input.generate = true;
try {
// Response should never be 'none' for a generated password, but
// let's make sure.
Response<String> result = putHttpPassword.apply(account, input);
return result.isNone() ? null : result.value();
} catch (Exception e) {
throw asRestApiException("Cannot generate HTTP password", e);
}
}
use of com.google.gerrit.extensions.common.HttpPasswordInput in project gerrit by GerritCodeReview.
the class AccountApiImpl method setHttpPassword.
@Override
public String setHttpPassword(String password) throws RestApiException {
HttpPasswordInput input = new HttpPasswordInput();
input.generate = false;
input.httpPassword = password;
try {
Response<String> result = putHttpPassword.apply(account, input);
return result.isNone() ? null : result.value();
} catch (Exception e) {
throw asRestApiException("Cannot generate HTTP password", e);
}
}
Aggregations