Search in sources :

Example 1 with HttpPasswordInput

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);
    }
}
Also used : AccountResource(com.google.gerrit.server.account.AccountResource) HttpPasswordInput(com.google.gerrit.extensions.common.HttpPasswordInput) IdString(com.google.gerrit.extensions.restapi.IdString) NameInput(com.google.gerrit.extensions.common.NameInput) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) EmailException(com.google.gerrit.exceptions.EmailException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) AuthException(com.google.gerrit.extensions.restapi.AuthException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) IOException(java.io.IOException)

Example 2 with HttpPasswordInput

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);
}
Also used : HttpPasswordInput(com.google.gerrit.extensions.common.HttpPasswordInput)

Example 3 with HttpPasswordInput

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);
    }
}
Also used : HttpPasswordInput(com.google.gerrit.extensions.common.HttpPasswordInput) IdString(com.google.gerrit.extensions.restapi.IdString) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 4 with HttpPasswordInput

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);
    }
}
Also used : HttpPasswordInput(com.google.gerrit.extensions.common.HttpPasswordInput) IdString(com.google.gerrit.extensions.restapi.IdString) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Aggregations

HttpPasswordInput (com.google.gerrit.extensions.common.HttpPasswordInput)4 IdString (com.google.gerrit.extensions.restapi.IdString)3 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)3 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)2 EmailException (com.google.gerrit.exceptions.EmailException)1 NameInput (com.google.gerrit.extensions.common.NameInput)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 AccountResource (com.google.gerrit.server.account.AccountResource)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)1