Replace pattern "user instanceof IdentifiedUser" with method call
Change-Id: Iac3af1340206ffd8f10db133bca5eab1f85926b6
This commit is contained in:
committed by
Shawn Pearce
parent
cd4be95d6e
commit
a35f8a20ab
@@ -256,7 +256,7 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
throws ServiceNotAuthorizedException {
|
||||
final ProjectControl pc = (ProjectControl) req.getAttribute(ATT_CONTROL);
|
||||
|
||||
if (!(pc.getCurrentUser() instanceof IdentifiedUser)) {
|
||||
if (!(pc.getCurrentUser().isIdentifiedUser())) {
|
||||
// Anonymous users are not permitted to push.
|
||||
throw new ServiceNotAuthorizedException();
|
||||
}
|
||||
@@ -316,7 +316,7 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(pc.getCurrentUser() instanceof IdentifiedUser)) {
|
||||
if (!(pc.getCurrentUser().isIdentifiedUser())) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class RequireIdentifiedUserFilter implements Filter {
|
||||
public void doFilter(ServletRequest request,
|
||||
ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
if (user.get() instanceof IdentifiedUser) {
|
||||
if (user.get().isIdentifiedUser()) {
|
||||
chain.doFilter(request, response);
|
||||
} else {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
|
||||
@@ -518,7 +518,7 @@ class GitWebServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
String remoteUser = null;
|
||||
if (project.getCurrentUser() instanceof IdentifiedUser) {
|
||||
if (project.getCurrentUser().isIdentifiedUser()) {
|
||||
final IdentifiedUser u = (IdentifiedUser) project.getCurrentUser();
|
||||
final String user = u.getUserName();
|
||||
env.set("GERRIT_USER_NAME", user);
|
||||
|
||||
@@ -175,7 +175,7 @@ public class HostPageServlet extends HttpServlet {
|
||||
final Page.Content page = select(req);
|
||||
final StringWriter w = new StringWriter();
|
||||
final CurrentUser user = currentUser.get();
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
w.write(HPD_ID + ".account=");
|
||||
json(((IdentifiedUser) user).getAccount(), w);
|
||||
w.write(";");
|
||||
|
||||
@@ -42,7 +42,7 @@ public class BaseServiceImplementation {
|
||||
|
||||
protected Account.Id getAccountId() {
|
||||
CurrentUser u = currentUser.get();
|
||||
if (u instanceof IdentifiedUser) {
|
||||
if (u.isIdentifiedUser()) {
|
||||
return ((IdentifiedUser) u).getAccountId();
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -189,7 +189,7 @@ public class ChangeDetailFactory extends Handler<ChangeDetail> {
|
||||
Set<PatchSet.Id> patchesWithDraftComments = new HashSet<PatchSet.Id>();
|
||||
final CurrentUser user = control.getCurrentUser();
|
||||
final Account.Id me =
|
||||
user instanceof IdentifiedUser ? ((IdentifiedUser) user).getAccountId()
|
||||
user.isIdentifiedUser() ? ((IdentifiedUser) user).getAccountId()
|
||||
: null;
|
||||
for (PatchSet ps : source) {
|
||||
final PatchSet.Id psId = ps.getId();
|
||||
@@ -306,7 +306,7 @@ public class ChangeDetailFactory extends Handler<ChangeDetail> {
|
||||
|
||||
final CurrentUser currentUser = control.getCurrentUser();
|
||||
Account.Id currentUserId = null;
|
||||
if (currentUser instanceof IdentifiedUser) {
|
||||
if (currentUser.isIdentifiedUser()) {
|
||||
currentUserId = ((IdentifiedUser) currentUser).getAccountId();
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
||||
detail.setPatches(patches);
|
||||
|
||||
final CurrentUser user = control.getCurrentUser();
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
// If we are signed in, compute the number of draft comments by the
|
||||
// current user on each of these patch files. This way they can more
|
||||
// quickly locate where they have pending drafts, and review them.
|
||||
|
||||
@@ -111,7 +111,7 @@ class HttpLog extends AbstractLifeCycle implements RequestLog {
|
||||
uri = uri + "?" + qs;
|
||||
}
|
||||
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
IdentifiedUser who = (IdentifiedUser) user;
|
||||
if (who.getUserName() != null && !who.getUserName().isEmpty()) {
|
||||
event.setProperty(P_USER, who.getUserName());
|
||||
|
||||
@@ -227,7 +227,7 @@ public class ProjectQoSFilter implements Filter {
|
||||
String userName = "";
|
||||
|
||||
CurrentUser who = userProvider.get();
|
||||
if (who instanceof IdentifiedUser) {
|
||||
if (who.isIdentifiedUser()) {
|
||||
String name = ((IdentifiedUser) who).getUserName();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
userName = " (" + name + ")";
|
||||
|
||||
@@ -95,4 +95,9 @@ public abstract class CurrentUser {
|
||||
}
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
/** Check if user is the IdentifiedUser */
|
||||
public boolean isIdentifiedUser() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,4 +412,10 @@ public class IdentifiedUser extends CurrentUser {
|
||||
public String toString() {
|
||||
return "IdentifiedUser[account " + getAccountId() + "]";
|
||||
}
|
||||
|
||||
/** Check if user is the IdentifiedUser */
|
||||
@Override
|
||||
public boolean isIdentifiedUser() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class AccountControl {
|
||||
*/
|
||||
public boolean canSee(final Account.Id otherUser) {
|
||||
// Special case: I can always see myself.
|
||||
if (currentUser instanceof IdentifiedUser
|
||||
if (currentUser.isIdentifiedUser()
|
||||
&& ((IdentifiedUser) currentUser).getAccountId().equals(otherUser)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class AccountsCollection implements
|
||||
CurrentUser user = self.get();
|
||||
|
||||
if (id.equals("self")) {
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
return (IdentifiedUser) user;
|
||||
} else if (user instanceof AnonymousUser) {
|
||||
throw new AuthException("Authentication required");
|
||||
|
||||
@@ -159,7 +159,7 @@ public class GroupControl {
|
||||
}
|
||||
|
||||
public boolean canSeeMember(Account.Id id) {
|
||||
if (user instanceof IdentifiedUser
|
||||
if (user.isIdentifiedUser()
|
||||
&& ((IdentifiedUser) user).getAccountId().equals(id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class LdapGroupBackend implements GroupBackend {
|
||||
|
||||
String groupDn = uuid.get().substring(LDAP_UUID.length());
|
||||
CurrentUser user = userProvider.get();
|
||||
if (!(user instanceof IdentifiedUser)
|
||||
if (!(user.isIdentifiedUser())
|
||||
|| !membershipsOf((IdentifiedUser) user).contains(uuid)) {
|
||||
try {
|
||||
if (!existsCache.get(groupDn)) {
|
||||
|
||||
@@ -289,7 +289,7 @@ public class ChangeJson {
|
||||
}
|
||||
}
|
||||
|
||||
if (has(CURRENT_ACTIONS) && userProvider.get() instanceof IdentifiedUser) {
|
||||
if (has(CURRENT_ACTIONS) && userProvider.get().isIdentifiedUser()) {
|
||||
out.actions = Maps.newTreeMap();
|
||||
for (UiAction.Description d : UiActions.from(
|
||||
changes,
|
||||
@@ -698,7 +698,7 @@ public class ChangeJson {
|
||||
|
||||
private boolean isChangeReviewed(ChangeData cd) throws OrmException {
|
||||
CurrentUser user = userProvider.get();
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
PatchSet currentPatchSet = cd.currentPatchSet(db);
|
||||
if (currentPatchSet == null) {
|
||||
return false;
|
||||
@@ -779,7 +779,7 @@ public class ChangeJson {
|
||||
}
|
||||
|
||||
if (out.isCurrent && has(CURRENT_ACTIONS)
|
||||
&& userProvider.get() instanceof IdentifiedUser) {
|
||||
&& userProvider.get().isIdentifiedUser()) {
|
||||
out.actions = Maps.newTreeMap();
|
||||
for (UiAction.Description d : UiActions.from(
|
||||
revisions,
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ChangeResource implements RestResource, HasETag {
|
||||
Hasher h = Hashing.md5().newHasher()
|
||||
.putLong(getChange().getLastUpdatedOn().getTime())
|
||||
.putInt(getChange().getRowVersion())
|
||||
.putInt(user instanceof IdentifiedUser
|
||||
.putInt(user.isIdentifiedUser()
|
||||
? ((IdentifiedUser) user).getAccountId().get()
|
||||
: 0);
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class Drafts implements ChildCollection<RevisionResource, DraftResource> {
|
||||
}
|
||||
|
||||
private void checkIdentifiedUser() throws AuthException {
|
||||
if (!(user.get() instanceof IdentifiedUser)) {
|
||||
if (!(user.get().isIdentifiedUser())) {
|
||||
throw new AuthException("drafts only available to authenticated users");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
private Object reviewed(RevisionResource resource)
|
||||
throws AuthException, OrmException {
|
||||
CurrentUser user = self.get();
|
||||
if (!(user instanceof IdentifiedUser)) {
|
||||
if (!(user.isIdentifiedUser())) {
|
||||
throw new AuthException("Authentication required");
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class GroupsCollection implements
|
||||
final CurrentUser user = self.get();
|
||||
if (user instanceof AnonymousUser) {
|
||||
throw new AuthException("Authentication required");
|
||||
} else if(!(user instanceof IdentifiedUser)) {
|
||||
} else if(!(user.isIdentifiedUser())) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class GroupsCollection implements
|
||||
final CurrentUser user = self.get();
|
||||
if (user instanceof AnonymousUser) {
|
||||
throw new AuthException("Authentication required");
|
||||
} else if(!(user instanceof IdentifiedUser)) {
|
||||
} else if(!(user.isIdentifiedUser())) {
|
||||
throw new ResourceNotFoundException(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
||||
}
|
||||
|
||||
final CurrentUser user = control.getCurrentUser();
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
final Account.Id me = ((IdentifiedUser) user).getAccountId();
|
||||
switch (changeType) {
|
||||
case ADDED:
|
||||
|
||||
@@ -264,7 +264,7 @@ public class ChangeControl {
|
||||
|
||||
/** Is this user the owner of the change? */
|
||||
public boolean isOwner() {
|
||||
if (getCurrentUser() instanceof IdentifiedUser) {
|
||||
if (getCurrentUser().isIdentifiedUser()) {
|
||||
final IdentifiedUser i = (IdentifiedUser) getCurrentUser();
|
||||
return i.getAccountId().equals(change.getOwner());
|
||||
}
|
||||
@@ -279,7 +279,7 @@ public class ChangeControl {
|
||||
/** Is this user a reviewer for the change? */
|
||||
public boolean isReviewer(ReviewDb db, @Nullable ChangeData cd)
|
||||
throws OrmException {
|
||||
if (getCurrentUser() instanceof IdentifiedUser) {
|
||||
if (getCurrentUser().isIdentifiedUser()) {
|
||||
final IdentifiedUser user = (IdentifiedUser) getCurrentUser();
|
||||
Iterable<PatchSetApproval> results;
|
||||
if (cd != null) {
|
||||
@@ -305,7 +305,7 @@ public class ChangeControl {
|
||||
if (getChange().getStatus().isOpen()) {
|
||||
// A user can always remove themselves.
|
||||
//
|
||||
if (getCurrentUser() instanceof IdentifiedUser) {
|
||||
if (getCurrentUser().isIdentifiedUser()) {
|
||||
final IdentifiedUser i = (IdentifiedUser) getCurrentUser();
|
||||
if (i.getAccountId().equals(reviewer)) {
|
||||
return true; // can remove self
|
||||
|
||||
@@ -296,7 +296,7 @@ public class ProjectControl {
|
||||
}
|
||||
|
||||
private Capable verifyActiveContributorAgreement() {
|
||||
if (! (user instanceof IdentifiedUser)) {
|
||||
if (! (user.isIdentifiedUser())) {
|
||||
return new Capable("Must be logged in to verify Contributor Agreement");
|
||||
}
|
||||
final IdentifiedUser iUser = (IdentifiedUser) user;
|
||||
|
||||
@@ -262,7 +262,7 @@ public class RefControl {
|
||||
final PersonIdent tagger = tag.getTaggerIdent();
|
||||
if (tagger != null) {
|
||||
boolean valid;
|
||||
if (getCurrentUser() instanceof IdentifiedUser) {
|
||||
if (getCurrentUser().isIdentifiedUser()) {
|
||||
final IdentifiedUser user = (IdentifiedUser) getCurrentUser();
|
||||
final String addr = tagger.getEmailAddress();
|
||||
valid = user.getEmailAddresses().contains(addr);
|
||||
|
||||
@@ -437,7 +437,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
Set<Account.Id> m = parseAccount(who);
|
||||
List<IsWatchedByPredicate> p = Lists.newArrayListWithCapacity(m.size());
|
||||
for (Account.Id id : m) {
|
||||
if (currentUser instanceof IdentifiedUser
|
||||
if (currentUser.isIdentifiedUser()
|
||||
&& id.equals(((IdentifiedUser) currentUser).getAccountId())) {
|
||||
p.add(new IsWatchedByPredicate(args, currentUser, false));
|
||||
} else {
|
||||
@@ -656,7 +656,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
}
|
||||
|
||||
private Account.Id self() {
|
||||
if (currentUser instanceof IdentifiedUser) {
|
||||
if (currentUser.isIdentifiedUser()) {
|
||||
return ((IdentifiedUser) currentUser).getAccountId();
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Set;
|
||||
class IsStarredByPredicate extends OrPredicate<ChangeData> implements
|
||||
ChangeDataSource {
|
||||
private static String describe(CurrentUser user) {
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
return ((IdentifiedUser) user).getAccountId().toString();
|
||||
}
|
||||
return user.toString();
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.inject.Provider;
|
||||
|
||||
class IsVisibleToPredicate extends OperatorPredicate<ChangeData> {
|
||||
private static String describe(CurrentUser user) {
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
return ((IdentifiedUser) user).getAccountId().toString();
|
||||
}
|
||||
if (user instanceof SingleGroupUser) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.List;
|
||||
|
||||
class IsWatchedByPredicate extends AndPredicate<ChangeData> {
|
||||
private static String describe(CurrentUser user) {
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
return ((IdentifiedUser) user).getAccountId().toString();
|
||||
}
|
||||
return user.toString();
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ThreadLocalRequestContext {
|
||||
|
||||
@Provides
|
||||
IdentifiedUser provideCurrentUser(CurrentUser user) {
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
return (IdentifiedUser) user;
|
||||
}
|
||||
throw new ProvisionException(NotSignedInException.MESSAGE,
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PRED_current_user_1 extends Predicate.P1 {
|
||||
CurrentUser curUser = cControl.getCurrentUser();
|
||||
Term resultTerm;
|
||||
|
||||
if (curUser instanceof IdentifiedUser) {
|
||||
if (curUser.isIdentifiedUser()) {
|
||||
Account.Id id = ((IdentifiedUser)curUser).getAccountId();
|
||||
resultTerm = new IntegerTerm(id.get());
|
||||
} else if (curUser instanceof AnonymousUser) {
|
||||
|
||||
@@ -339,7 +339,7 @@ public abstract class BaseCommand implements Command {
|
||||
} else {
|
||||
final StringBuilder m = new StringBuilder();
|
||||
m.append("Internal server error");
|
||||
if (userProvider.get() instanceof IdentifiedUser) {
|
||||
if (userProvider.get().isIdentifiedUser()) {
|
||||
final IdentifiedUser u = (IdentifiedUser) userProvider.get();
|
||||
m.append(" (user ");
|
||||
m.append(u.getAccount().getUserName());
|
||||
@@ -403,7 +403,7 @@ public abstract class BaseCommand implements Command {
|
||||
|
||||
StringBuilder m = new StringBuilder();
|
||||
m.append(context.getCommandLine());
|
||||
if (userProvider.get() instanceof IdentifiedUser) {
|
||||
if (userProvider.get().isIdentifiedUser()) {
|
||||
IdentifiedUser u = (IdentifiedUser) userProvider.get();
|
||||
m.append(" (" + u.getAccount().getUserName() + ")");
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ class SshLog implements LifecycleListener {
|
||||
|
||||
String userName = "-", accountId = "-";
|
||||
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
IdentifiedUser u = (IdentifiedUser) user;
|
||||
userName = u.getAccount().getUserName();
|
||||
accountId = "a/" + u.getAccountId().toString();
|
||||
|
||||
@@ -81,7 +81,7 @@ class SshScope {
|
||||
@Override
|
||||
public CurrentUser getCurrentUser() {
|
||||
final CurrentUser user = session.getCurrentUser();
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
IdentifiedUser identifiedUser = userFactory.create(((IdentifiedUser) user).getAccountId());
|
||||
identifiedUser.setAccessPath(user.getAccessPath());
|
||||
return identifiedUser;
|
||||
|
||||
@@ -146,7 +146,7 @@ final class ShowConnections extends SshCommand {
|
||||
}
|
||||
|
||||
final CurrentUser user = sd.getCurrentUser();
|
||||
if (user instanceof IdentifiedUser) {
|
||||
if (user.isIdentifiedUser()) {
|
||||
IdentifiedUser u = (IdentifiedUser) user;
|
||||
|
||||
if (!numeric) {
|
||||
|
||||
Reference in New Issue
Block a user