List of usage examples for org.eclipse.jgit.transport PushCertificateIdent parse
public static PushCertificateIdent parse(String str)
From source file:com.google.gerrit.acceptance.api.accounts.AccountIT.java
License:Apache License
@Test public void listGpgKeys() throws Exception { List<TestKey> keys = TestKey.allValidKeys(); List<String> toAdd = new ArrayList<>(keys.size()); for (TestKey key : keys) { addExternalIdEmail(admin, PushCertificateIdent.parse(key.getFirstUserId()).getEmailAddress()); toAdd.add(key.getPublicKeyArmored()); }/*from w ww . j a v a2 s .co m*/ gApi.accounts().self().putGpgKeys(toAdd, ImmutableList.<String>of()); assertKeys(keys); }
From source file:com.google.gerrit.acceptance.api.accounts.AccountIT.java
License:Apache License
@Test public void addAndRemoveGpgKeys() throws Exception { for (TestKey key : TestKey.allValidKeys()) { addExternalIdEmail(admin, PushCertificateIdent.parse(key.getFirstUserId()).getEmailAddress()); }/*from www.j a v a 2 s. c o m*/ TestKey key1 = TestKey.key1(); TestKey key2 = TestKey.key2(); TestKey key5 = TestKey.key5(); Map<String, GpgKeyInfo> infos = gApi.accounts().self().putGpgKeys( ImmutableList.of(key1.getPublicKeyArmored(), key2.getPublicKeyArmored()), ImmutableList.of(key5.getKeyIdString())); assertThat(infos.keySet()).containsExactly(key1.getKeyIdString(), key2.getKeyIdString()); assertKeys(key1, key2); infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key5.getPublicKeyArmored()), ImmutableList.of(key1.getKeyIdString())); assertThat(infos.keySet()).containsExactly(key1.getKeyIdString(), key5.getKeyIdString()); assertKeyMapContains(key5, infos); assertThat(infos.get(key1.getKeyIdString()).key).isNull(); assertKeys(key2, key5); exception.expect(BadRequestException.class); exception.expectMessage("Cannot both add and delete key: " + keyToString(key2.getPublicKey())); infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key2.getPublicKeyArmored()), ImmutableList.of(key2.getKeyIdString())); }
From source file:com.google.gerrit.gpg.GerritPublicKeyChecker.java
License:Apache License
private static boolean isAllowed(String userId, Set<String> allowedUserIds) { return allowedUserIds.contains(userId) || allowedUserIds.contains(PushCertificateIdent.parse(userId).getEmailAddress()); }
From source file:com.google.gerrit.gpg.GerritPublicKeyCheckerTest.java
License:Apache License
private void add(PGPPublicKeyRing kr, IdentifiedUser user) throws Exception { Account.Id id = user.getAccountId(); List<AccountExternalId> newExtIds = new ArrayList<>(2); newExtIds.add(new AccountExternalId(id, toExtIdKey(kr.getPublicKey()))); @SuppressWarnings("unchecked") String userId = (String) Iterators.getOnlyElement(kr.getPublicKey().getUserIDs(), null); if (userId != null) { String email = PushCertificateIdent.parse(userId).getEmailAddress(); assertThat(email).contains("@"); AccountExternalId mailto = new AccountExternalId(id, new AccountExternalId.Key(SCHEME_MAILTO, email)); mailto.setEmailAddress(email);// w w w. j a v a 2 s . c om newExtIds.add(mailto); } store.add(kr); PersonIdent ident = new PersonIdent("A U Thor", "author@example.com"); CommitBuilder cb = new CommitBuilder(); cb.setAuthor(ident); cb.setCommitter(ident); assertThat(store.save(cb)).isAnyOf(NEW, FAST_FORWARD, FORCED); db.accountExternalIds().insert(newExtIds); accountCache.evict(user.getAccountId()); }