Search in sources :

Example 11 with AccountSshKey

use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.

the class VersionedAuthorizedKeys method setKeys.

/**
   * Sets new SSH keys.
   *
   * <p>The existing SSH keys are overwritten.
   *
   * @param newKeys the new public SSH keys
   */
public void setKeys(Collection<AccountSshKey> newKeys) {
    Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
    keys = new ArrayList<>(Collections.nCopies(o.max(newKeys).getKey().get(), Optional.empty()));
    for (AccountSshKey key : newKeys) {
        keys.set(key.getKey().get() - 1, Optional.of(key));
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) VersionedMetaData(com.google.gerrit.server.git.VersionedMetaData) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) Inject(com.google.inject.Inject) SshKeyCreator(com.google.gerrit.server.ssh.SshKeyCreator) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) Strings(com.google.common.base.Strings) Account(com.google.gerrit.reviewdb.client.Account) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) Comparator.comparing(java.util.Comparator.comparing) AccountSshKey(com.google.gerrit.reviewdb.client.AccountSshKey) Collection(java.util.Collection) IOException(java.io.IOException) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Collectors.toList(java.util.stream.Collectors.toList) Provider(com.google.inject.Provider) List(java.util.List) Ordering(com.google.common.collect.Ordering) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) RefNames(com.google.gerrit.reviewdb.client.RefNames) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Optional(java.util.Optional) InvalidSshKeyException(com.google.gerrit.common.errors.InvalidSshKeyException) Id(com.google.gerrit.reviewdb.client.AccountSshKey.Id) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) Singleton(com.google.inject.Singleton) AccountSshKey(com.google.gerrit.reviewdb.client.AccountSshKey)

Example 12 with AccountSshKey

use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.

the class AuthorizedKeysTest method addInvalidKey.

/**
   * Adds the given public key as invalid SSH key to the given list.
   *
   * @return the expected line for this key in the authorized_keys file
   */
private static String addInvalidKey(List<Optional<AccountSshKey>> keys, String pub) {
    AccountSshKey.Id keyId = new AccountSshKey.Id(new Account.Id(1), keys.size() + 1);
    AccountSshKey key = new AccountSshKey(keyId, pub);
    key.setInvalid();
    keys.add(Optional.of(key));
    return AuthorizedKeys.INVALID_KEY_COMMENT_PREFIX + key.getSshPublicKey() + "\n";
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) AccountSshKey(com.google.gerrit.reviewdb.client.AccountSshKey)

Example 13 with AccountSshKey

use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.

the class AuthorizedKeysTest method addKey.

/**
   * Adds the given public key as new SSH key to the given list.
   *
   * @return the expected line for this key in the authorized_keys file
   */
private static String addKey(List<Optional<AccountSshKey>> keys, String pub) {
    AccountSshKey.Id keyId = new AccountSshKey.Id(new Account.Id(1), keys.size() + 1);
    AccountSshKey key = new AccountSshKey(keyId, pub);
    keys.add(Optional.of(key));
    return key.getSshPublicKey() + "\n";
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) AccountSshKey(com.google.gerrit.reviewdb.client.AccountSshKey)

Example 14 with AccountSshKey

use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.

the class SetAccountCommand method deleteSshKey.

private void deleteSshKey(SshKeyInfo i) throws AuthException, OrmException, RepositoryNotFoundException, IOException, ConfigInvalidException, PermissionBackendException {
    AccountSshKey sshKey = new AccountSshKey(new AccountSshKey.Id(user.getAccountId(), i.seq), i.sshPublicKey);
    deleteSshKey.apply(new AccountResource.SshKey(user, sshKey), null);
}
Also used : AccountResource(com.google.gerrit.server.account.AccountResource) AccountSshKey(com.google.gerrit.reviewdb.client.AccountSshKey)

Example 15 with AccountSshKey

use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.

the class VersionedAuthorizedKeysOnInit method addKey.

public AccountSshKey addKey(String pub) {
    checkState(keys != null, "SSH keys not loaded yet");
    int seq = keys.isEmpty() ? 1 : keys.size() + 1;
    AccountSshKey.Id keyId = new AccountSshKey.Id(accountId, seq);
    AccountSshKey key = new VersionedAuthorizedKeys.SimpleSshKeyCreator().create(keyId, pub);
    keys.add(Optional.of(key));
    return key;
}
Also used : AccountSshKey(com.google.gerrit.reviewdb.client.AccountSshKey) VersionedAuthorizedKeys(com.google.gerrit.server.account.VersionedAuthorizedKeys)

Aggregations

AccountSshKey (com.google.gerrit.reviewdb.client.AccountSshKey)15 Account (com.google.gerrit.reviewdb.client.Account)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 InvalidSshKeyException (com.google.gerrit.common.errors.InvalidSshKeyException)3 VersionedAuthorizedKeys (com.google.gerrit.server.account.VersionedAuthorizedKeys)3 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)3 Collection (java.util.Collection)3 Strings (com.google.common.base.Strings)2 Ordering (com.google.common.collect.Ordering)2 Id (com.google.gerrit.reviewdb.client.AccountSshKey.Id)2 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)2 SimpleSshKeyCreator (com.google.gerrit.server.account.VersionedAuthorizedKeys.SimpleSshKeyCreator)2 AllUsersName (com.google.gerrit.server.config.AllUsersName)2 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)2 OrmException (com.google.gwtorm.server.OrmException)2 Inject (com.google.inject.Inject)2 Provider (com.google.inject.Provider)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2