Merge "Add getCacheKey() to CurrentUser and its implementations"
This commit is contained in:
@@ -26,6 +26,12 @@ public class AnonymousUser extends CurrentUser {
|
||||
return new ListGroupMembership(Collections.singleton(SystemGroupBackend.ANONYMOUS_USERS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCacheKey() {
|
||||
// Treat all anonymous users as a single user
|
||||
return "anonymous";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ANONYMOUS";
|
||||
|
||||
@@ -90,6 +90,12 @@ public abstract class CurrentUser {
|
||||
*/
|
||||
public abstract GroupMembership getEffectiveGroups();
|
||||
|
||||
/**
|
||||
* Returns a unique identifier for this user that is intended to be used as a cache key. Returned
|
||||
* object should to implement {@code equals()} and {@code hashCode()} for effective caching.
|
||||
*/
|
||||
public abstract Object getCacheKey();
|
||||
|
||||
/** Unique name of the user on this server, if one has been assigned. */
|
||||
public Optional<String> getUserName() {
|
||||
return Optional.empty();
|
||||
|
||||
@@ -382,6 +382,11 @@ public class IdentifiedUser extends CurrentUser {
|
||||
return effectiveGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCacheKey() {
|
||||
return getAccountId();
|
||||
}
|
||||
|
||||
public PersonIdent newRefLogIdent() {
|
||||
return newRefLogIdent(new Date(), TimeZone.getDefault());
|
||||
}
|
||||
|
||||
@@ -35,6 +35,11 @@ public class InternalUser extends CurrentUser {
|
||||
return GroupMembership.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCacheKey() {
|
||||
return "internal";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInternalUser() {
|
||||
return true;
|
||||
|
||||
@@ -40,6 +40,11 @@ public class PeerDaemonUser extends CurrentUser {
|
||||
return GroupMembership.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCacheKey() {
|
||||
return getRemoteAddress();
|
||||
}
|
||||
|
||||
public SocketAddress getRemoteAddress() {
|
||||
return peer;
|
||||
}
|
||||
|
||||
@@ -36,4 +36,9 @@ public final class SingleGroupUser extends CurrentUser {
|
||||
public GroupMembership getEffectiveGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCacheKey() {
|
||||
return groups.getKnownGroups();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,11 @@ public class UiActionsTest {
|
||||
throw new UnsupportedOperationException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCacheKey() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdentifiedUser() {
|
||||
return true;
|
||||
|
||||
@@ -1012,6 +1012,11 @@ public class RefControlTest {
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCacheKey() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getUserName() {
|
||||
return Optional.ofNullable(username);
|
||||
|
||||
Submodule plugins/replication updated: b9b41c010a...2c9d976f9e
Reference in New Issue
Block a user