ProjectBasicAuthFilter: Extract repeated code to a method
Change-Id: I5f2c2c7c289aefa0b61f5e8f68f0f82234611ab4
This commit is contained in:

committed by
David Pursehouse

parent
f15659d36f
commit
470984e1d3
@@ -20,6 +20,7 @@ import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
|
|||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||||
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.server.AccessPath;
|
import com.google.gerrit.server.AccessPath;
|
||||||
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;
|
||||||
@@ -153,17 +154,11 @@ class ProjectBasicAuthFilter implements Filter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
AuthResult whoAuthResult = accountManager.authenticate(whoAuth);
|
AuthResult whoAuthResult = accountManager.authenticate(whoAuth);
|
||||||
WebSession ws = session.get();
|
setUserIdentified(whoAuthResult.getAccountId());
|
||||||
ws.setUserAccountId(whoAuthResult.getAccountId());
|
|
||||||
ws.setAccessPathOk(AccessPath.GIT, true);
|
|
||||||
ws.setAccessPathOk(AccessPath.REST_API, true);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (NoSuchUserException e) {
|
} catch (NoSuchUserException e) {
|
||||||
if (password.equals(who.getPassword(who.getUserName()))) {
|
if (password.equals(who.getPassword(who.getUserName()))) {
|
||||||
WebSession ws = session.get();
|
setUserIdentified(who.getAccount().getId());
|
||||||
ws.setUserAccountId(who.getAccount().getId());
|
|
||||||
ws.setAccessPathOk(AccessPath.GIT, true);
|
|
||||||
ws.setAccessPathOk(AccessPath.REST_API, true);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
log.warn("Authentication failed for " + username, e);
|
log.warn("Authentication failed for " + username, e);
|
||||||
@@ -180,6 +175,13 @@ class ProjectBasicAuthFilter implements Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUserIdentified(Account.Id id) {
|
||||||
|
WebSession ws = session.get();
|
||||||
|
ws.setUserAccountId(id);
|
||||||
|
ws.setAccessPathOk(AccessPath.GIT, true);
|
||||||
|
ws.setAccessPathOk(AccessPath.REST_API, true);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean passwordMatchesTheUserGeneratedOne(AccountState who,
|
private boolean passwordMatchesTheUserGeneratedOne(AccountState who,
|
||||||
String username, String password) {
|
String username, String password) {
|
||||||
String accountPassword = who.getPassword(username);
|
String accountPassword = who.getPassword(username);
|
||||||
|
Reference in New Issue
Block a user