BecomeAnyAccountLoginServlet: Remove SchemaFactory
Change-Id: I090f886e47ef9b695ffe9c19970802610a81a762
This commit is contained in:
@@ -24,7 +24,6 @@ import com.google.gerrit.httpd.LoginUrlToken;
|
|||||||
import com.google.gerrit.httpd.WebSession;
|
import com.google.gerrit.httpd.WebSession;
|
||||||
import com.google.gerrit.httpd.template.SiteHeaderFooter;
|
import com.google.gerrit.httpd.template.SiteHeaderFooter;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
|
||||||
import com.google.gerrit.server.account.AccountCache;
|
import com.google.gerrit.server.account.AccountCache;
|
||||||
import com.google.gerrit.server.account.AccountException;
|
import com.google.gerrit.server.account.AccountException;
|
||||||
import com.google.gerrit.server.account.AccountManager;
|
import com.google.gerrit.server.account.AccountManager;
|
||||||
@@ -36,7 +35,6 @@ import com.google.gerrit.server.account.externalids.ExternalId;
|
|||||||
import com.google.gerrit.server.query.account.InternalAccountQuery;
|
import com.google.gerrit.server.query.account.InternalAccountQuery;
|
||||||
import com.google.gerrit.util.http.CacheHeaders;
|
import com.google.gerrit.util.http.CacheHeaders;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.gwtorm.server.SchemaFactory;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -59,7 +57,6 @@ import org.w3c.dom.Element;
|
|||||||
@Singleton
|
@Singleton
|
||||||
class BecomeAnyAccountLoginServlet extends HttpServlet {
|
class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||||
private final DynamicItem<WebSession> webSession;
|
private final DynamicItem<WebSession> webSession;
|
||||||
private final SchemaFactory<ReviewDb> schema;
|
|
||||||
private final Accounts accounts;
|
private final Accounts accounts;
|
||||||
private final AccountCache accountCache;
|
private final AccountCache accountCache;
|
||||||
private final AccountManager accountManager;
|
private final AccountManager accountManager;
|
||||||
@@ -69,14 +66,12 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
|||||||
@Inject
|
@Inject
|
||||||
BecomeAnyAccountLoginServlet(
|
BecomeAnyAccountLoginServlet(
|
||||||
DynamicItem<WebSession> ws,
|
DynamicItem<WebSession> ws,
|
||||||
SchemaFactory<ReviewDb> sf,
|
|
||||||
Accounts a,
|
Accounts a,
|
||||||
AccountCache ac,
|
AccountCache ac,
|
||||||
AccountManager am,
|
AccountManager am,
|
||||||
SiteHeaderFooter shf,
|
SiteHeaderFooter shf,
|
||||||
Provider<InternalAccountQuery> qp) {
|
Provider<InternalAccountQuery> qp) {
|
||||||
webSession = ws;
|
webSession = ws;
|
||||||
schema = sf;
|
|
||||||
accounts = a;
|
accounts = a;
|
||||||
accountCache = ac;
|
accountCache = ac;
|
||||||
accountManager = am;
|
accountManager = am;
|
||||||
@@ -91,8 +86,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse rsp)
|
protected void doPost(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
||||||
throws IOException, ServletException {
|
|
||||||
CacheHeaders.setNotCacheable(rsp);
|
CacheHeaders.setNotCacheable(rsp);
|
||||||
|
|
||||||
final AuthResult res;
|
final AuthResult res;
|
||||||
@@ -110,11 +104,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
byte[] raw;
|
byte[] raw;
|
||||||
try {
|
raw = prepareHtmlOutput();
|
||||||
raw = prepareHtmlOutput();
|
|
||||||
} catch (OrmException e) {
|
|
||||||
throw new ServletException(e);
|
|
||||||
}
|
|
||||||
rsp.setContentType("text/html");
|
rsp.setContentType("text/html");
|
||||||
rsp.setCharacterEncoding(HtmlDomUtil.ENC.name());
|
rsp.setCharacterEncoding(HtmlDomUtil.ENC.name());
|
||||||
rsp.setContentLength(raw.length);
|
rsp.setContentLength(raw.length);
|
||||||
@@ -150,7 +140,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] prepareHtmlOutput() throws IOException, OrmException {
|
private byte[] prepareHtmlOutput() throws IOException {
|
||||||
final String pageName = "BecomeAnyAccount.html";
|
final String pageName = "BecomeAnyAccount.html";
|
||||||
Document doc = headers.parse(getClass(), pageName);
|
Document doc = headers.parse(getClass(), pageName);
|
||||||
if (doc == null) {
|
if (doc == null) {
|
||||||
@@ -158,30 +148,28 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Element userlistElement = HtmlDomUtil.find(doc, "userlist");
|
Element userlistElement = HtmlDomUtil.find(doc, "userlist");
|
||||||
try (ReviewDb db = schema.open()) {
|
for (Account.Id accountId : accounts.firstNIds(100)) {
|
||||||
for (Account.Id accountId : accounts.firstNIds(100)) {
|
Optional<AccountState> accountState = accountCache.get(accountId);
|
||||||
Optional<AccountState> accountState = accountCache.get(accountId);
|
if (!accountState.isPresent()) {
|
||||||
if (!accountState.isPresent()) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Account account = accountState.get().getAccount();
|
|
||||||
String displayName;
|
|
||||||
if (accountState.get().getUserName().isPresent()) {
|
|
||||||
displayName = accountState.get().getUserName().get();
|
|
||||||
} else if (account.getFullName() != null && !account.getFullName().isEmpty()) {
|
|
||||||
displayName = account.getFullName();
|
|
||||||
} else if (account.getPreferredEmail() != null) {
|
|
||||||
displayName = account.getPreferredEmail();
|
|
||||||
} else {
|
|
||||||
displayName = accountId.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
Element linkElement = doc.createElement("a");
|
|
||||||
linkElement.setAttribute("href", "?account_id=" + account.getId().toString());
|
|
||||||
linkElement.setTextContent(displayName);
|
|
||||||
userlistElement.appendChild(linkElement);
|
|
||||||
userlistElement.appendChild(doc.createElement("br"));
|
|
||||||
}
|
}
|
||||||
|
Account account = accountState.get().getAccount();
|
||||||
|
String displayName;
|
||||||
|
if (accountState.get().getUserName().isPresent()) {
|
||||||
|
displayName = accountState.get().getUserName().get();
|
||||||
|
} else if (account.getFullName() != null && !account.getFullName().isEmpty()) {
|
||||||
|
displayName = account.getFullName();
|
||||||
|
} else if (account.getPreferredEmail() != null) {
|
||||||
|
displayName = account.getPreferredEmail();
|
||||||
|
} else {
|
||||||
|
displayName = accountId.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
Element linkElement = doc.createElement("a");
|
||||||
|
linkElement.setAttribute("href", "?account_id=" + account.getId().toString());
|
||||||
|
linkElement.setTextContent(displayName);
|
||||||
|
userlistElement.appendChild(linkElement);
|
||||||
|
userlistElement.appendChild(doc.createElement("br"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return HtmlDomUtil.toUTF8(doc);
|
return HtmlDomUtil.toUTF8(doc);
|
||||||
@@ -218,7 +206,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Optional<AuthResult> byPreferredEmail(String email) {
|
private Optional<AuthResult> byPreferredEmail(String email) {
|
||||||
try (ReviewDb db = schema.open()) {
|
try {
|
||||||
Optional<AccountState> match =
|
Optional<AccountState> match =
|
||||||
queryProvider.get().byPreferredEmail(email).stream().findFirst();
|
queryProvider.get().byPreferredEmail(email).stream().findFirst();
|
||||||
return auth(match);
|
return auth(match);
|
||||||
|
|||||||
Reference in New Issue
Block a user