Package com.google.gerrit.server
Class CurrentUser
- java.lang.Object
-
- com.google.gerrit.server.CurrentUser
-
- Direct Known Subclasses:
AnonymousUser,IdentifiedUser,InternalUser,PeerDaemonUser,SingleGroupUser
public abstract class CurrentUser extends Object
Information about the currently logged in user.This is a
RequestScopedproperty managed by Guice.- See Also:
AnonymousUser,IdentifiedUser
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCurrentUser.PropertyKey<T>Unique key for plugin/extension specific data on a CurrentUser.
-
Constructor Summary
Constructors Constructor Description CurrentUser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description IdentifiedUserasIdentifiedUser()Cast to IdentifiedUser if possible.<T> Tget(CurrentUser.PropertyKey<T> key)Lookup a previously stored property.AccessPathgetAccessPath()How this user is accessing the Gerrit Code Review application.Account.IdgetAccountId()Return account ID ifisIdentifiedUser()is true.abstract GroupMembershipgetEffectiveGroups()Get the set of groups the user is currently a member of.ExternalId.KeygetLastLoginExternalIdKey()CurrentUsergetRealUser()Identity of the authenticated user.StringgetUserName()Unique name of the user on this server, if one has been assigned.booleanhasSameAccountId(CurrentUser other)Checks if the current user has the same account id of another.booleanisIdentifiedUser()Check if user is the IdentifiedUserbooleanisImpersonating()booleanisInternalUser()Check if the CurrentUser is an InternalUser.<T> voidput(CurrentUser.PropertyKey<T> key, T value)Store a property for later retrieval.voidsetAccessPath(AccessPath path)voidsetLastLoginExternalIdKey(ExternalId.Key externalIdKey)voidupdateRealAccountId(Consumer<Account.Id> setter)If thegetRealUser()has an account ID associated with it, call the given setter with that ID.
-
-
-
Method Detail
-
getAccessPath
public final AccessPath getAccessPath()
How this user is accessing the Gerrit Code Review application.
-
setAccessPath
public void setAccessPath(AccessPath path)
-
getRealUser
public CurrentUser getRealUser()
Identity of the authenticated user.In the normal case where a user authenticates as themselves
getRealUser() == this.If
X-Gerrit-RunAsorsuexecwas used this method returns the identity of the account that has permission to act on behalf of this user.
-
isImpersonating
public boolean isImpersonating()
-
updateRealAccountId
public void updateRealAccountId(Consumer<Account.Id> setter)
If thegetRealUser()has an account ID associated with it, call the given setter with that ID.
-
getEffectiveGroups
public abstract GroupMembership getEffectiveGroups()
Get the set of groups the user is currently a member of.The returned set may be a subset of the user's actual groups; if the user's account is currently deemed to be untrusted then the effective group set is only the anonymous and registered user groups. To enable additional groups (and gain their granted permissions) the user must update their account to use only trusted authentication providers.
- Returns:
- active groups for this user.
-
getUserName
public String getUserName()
Unique name of the user on this server, if one has been assigned.
-
isIdentifiedUser
public boolean isIdentifiedUser()
Check if user is the IdentifiedUser
-
asIdentifiedUser
public IdentifiedUser asIdentifiedUser()
Cast to IdentifiedUser if possible.
-
getAccountId
public Account.Id getAccountId()
Return account ID ifisIdentifiedUser()is true.- Throws:
UnsupportedOperationException- if the user is not logged in.
-
isInternalUser
public boolean isInternalUser()
Check if the CurrentUser is an InternalUser.
-
get
public <T> T get(CurrentUser.PropertyKey<T> key)
Lookup a previously stored property.- Parameters:
key- unique property key.- Returns:
- previously stored value, or
null.
-
put
public <T> void put(CurrentUser.PropertyKey<T> key, T value)
Store a property for later retrieval.- Parameters:
key- unique property key.value- value to store; ornullto clear the value.
-
setLastLoginExternalIdKey
public void setLastLoginExternalIdKey(ExternalId.Key externalIdKey)
-
getLastLoginExternalIdKey
public ExternalId.Key getLastLoginExternalIdKey()
-
hasSameAccountId
public boolean hasSameAccountId(CurrentUser other)
Checks if the current user has the same account id of another.Provide a generic interface for allowing subclasses to define whether two accounts represent the same account id.
- Parameters:
other- user to compare- Returns:
- true if the two users have the same account id
-
-