use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class BecomeAnyAccountLoginServlet method prepareHtmlOutput.
private byte[] prepareHtmlOutput() throws IOException {
final String pageName = "BecomeAnyAccount.html";
Document doc = headers.parse(getClass(), pageName);
if (doc == null) {
throw new FileNotFoundException("No " + pageName + " in webapp");
}
Element userlistElement = HtmlDomUtil.find(doc, "userlist");
for (Account.Id accountId : accounts.firstNIds(100)) {
Optional<AccountState> accountState = accountCache.get(accountId);
if (!accountState.isPresent()) {
continue;
}
Account account = accountState.get().account();
String displayName;
if (accountState.get().userName().isPresent()) {
displayName = accountState.get().userName().get();
} else if (account.fullName() != null && !account.fullName().isEmpty()) {
displayName = account.fullName();
} else if (account.preferredEmail() != null) {
displayName = account.preferredEmail();
} else {
displayName = accountId.toString();
}
Element linkElement = doc.createElement("a");
linkElement.setAttribute("href", "?account_id=" + account.id().toString());
linkElement.setTextContent(displayName);
userlistElement.appendChild(linkElement);
userlistElement.appendChild(doc.createElement("br"));
}
return HtmlDomUtil.toUTF8(doc);
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class AccountOperationsImpl method createAccount.
private Account.Id createAccount(TestAccountCreation testAccountCreation) throws Exception {
Account.Id accountId = Account.id(seq.nextAccountId());
Consumer<AccountDelta.Builder> accountCreation = deltaBuilder -> initAccountDelta(deltaBuilder, testAccountCreation, accountId);
AccountState createdAccount = accountsUpdate.insert("Create Test Account", accountId, accountCreation);
return createdAccount.account().id();
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class CommentsUtil method byPatchSet.
public List<HumanComment> byPatchSet(ChangeNotes notes, PatchSet.Id psId) {
List<HumanComment> comments = new ArrayList<>();
comments.addAll(publishedByPatchSet(notes, psId));
for (Ref ref : getDraftRefs(notes.getChangeId())) {
Account.Id account = Account.Id.fromRefSuffix(ref.getName());
if (account != null) {
comments.addAll(draftByPatchSetAuthor(psId, account, notes));
}
}
return sort(comments);
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class IdentifiedUser method newCommitterIdent.
public PersonIdent newCommitterIdent(Instant when, TimeZone tz) {
final Account ua = getAccount();
String name = ua.fullName();
String email = ua.preferredEmail();
if (email == null || email.isEmpty()) {
// No preferred email is configured. Use a generic identity so we
// don't leak an address the user may have given us, but doesn't
// necessarily want to publish through Git records.
//
String user = getUserName().orElseGet(() -> "account-" + ua.id().toString());
String host;
if (canonicalUrl.get() != null) {
try {
host = new URL(canonicalUrl.get()).getHost();
} catch (MalformedURLException e) {
host = SystemReader.getInstance().getHostname();
}
} else {
host = SystemReader.getInstance().getHostname();
}
email = user + "@" + host;
}
if (name == null || name.isEmpty()) {
final int at = email.indexOf('@');
if (0 < at) {
name = email.substring(0, at);
} else {
name = anonymousCowardName;
}
}
return newPersonIdent(name, email, when, tz);
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class AccountManager method create.
private AuthResult create(AuthRequest who) throws AccountException, IOException, ConfigInvalidException {
Account.Id newId = Account.id(sequences.nextAccountId());
logger.atFine().log("Assigning new Id %s to account", newId);
ExternalId extId = externalIdFactory.createWithEmail(who.getExternalIdKey(), newId, who.getEmailAddress());
logger.atFine().log("Created external Id: %s", extId);
checkEmailNotUsed(newId, extId);
ExternalId userNameExtId = who.getUserName().isPresent() ? createUsername(newId, who.getUserName().get()) : null;
boolean isFirstAccount = awaitsFirstAccountCheck.getAndSet(false) && !accounts.hasAnyAccount();
AccountState accountState;
try {
accountState = accountsUpdateProvider.get().insert("Create Account on First Login", newId, u -> {
u.setFullName(who.getDisplayName()).setPreferredEmail(extId.email()).addExternalId(extId);
if (userNameExtId != null) {
u.addExternalId(userNameExtId);
}
});
} catch (DuplicateExternalIdKeyException e) {
throw new AccountException("Cannot assign external ID \"" + e.getDuplicateKey().get() + "\" to account " + newId + "; external ID already in use.");
} finally {
// If adding the account failed, it may be that it actually was the
// first account. So we reset the 'check for first account'-guard, as
// otherwise the first account would not get administration permissions.
awaitsFirstAccountCheck.set(isFirstAccount);
}
if (userNameExtId != null) {
who.getUserName().ifPresent(sshKeyCache::evict);
}
IdentifiedUser user = userFactory.create(newId);
if (isFirstAccount) {
// This is the first user account on our site. Assume this user
// is going to be the site's administrator and just make them that
// to bootstrap the authentication database.
//
Permission admin = projectCache.getAllProjects().getConfig().getAccessSection(AccessSection.GLOBAL_CAPABILITIES).orElseThrow(() -> new IllegalStateException("access section does not exist")).getPermission(GlobalCapability.ADMINISTRATE_SERVER);
AccountGroup.UUID adminGroupUuid = admin.getRules().get(0).getGroup().getUUID();
addGroupMember(adminGroupUuid, user);
}
realm.onCreateAccount(who, accountState.account());
return new AuthResult(newId, extId.key(), true);
}
Aggregations