Class Identity (2.37.0)

publicfinalclassIdentityimplementsSerializable

An identity in aPolicy. The following types of identities are permitted in IAM policies:

  • Google account
  • Service account
  • Google group
  • Google Apps domain

There are also two special identities that represent all users and all Google-authenticated accounts.See Also:Concepts related to identity

Inheritance

Object >Identity

Implements

Serializable

Static Methods

allAuthenticatedUsers()

publicstaticIdentityallAuthenticatedUsers()

Returns a new identity representing anyone who is authenticated with a Google account or a service account.

Returns
TypeDescription
Identity

allUsers()

publicstaticIdentityallUsers()

Returns a new identity representing anyone who is on the internet; with or without a Google account.

Returns
TypeDescription
Identity

domain(String domain)

publicstaticIdentitydomain(Stringdomain)

Returns a new domain identity.

Parameter
NameDescription
domainString

A Google Apps domain name that represents all the users of that domain. For example,google.com orexample.com.

Returns
TypeDescription
Identity

group(String email)

publicstaticIdentitygroup(Stringemail)

Returns a new group identity.

Parameter
NameDescription
emailString

An email address that represents a Google group. For example,admins@example.com.

Returns
TypeDescription
Identity

projectEditor(String projectId)

publicstaticIdentityprojectEditor(StringprojectId)

Returns a new project editor identity.

Parameter
NameDescription
projectIdString

A Google Cloud Platform project ID. For example,my-sample-project.

Returns
TypeDescription
Identity

projectOwner(String projectId)

publicstaticIdentityprojectOwner(StringprojectId)

Returns a new project owner identity.

Parameter
NameDescription
projectIdString

A Google Cloud Platform project ID. For example,my-sample-project.

Returns
TypeDescription
Identity

projectViewer(String projectId)

publicstaticIdentityprojectViewer(StringprojectId)

Returns a new project viewer identity.

Parameter
NameDescription
projectIdString

A Google Cloud Platform project ID. For example,my-sample-project.

Returns
TypeDescription
Identity

serviceAccount(String email)

publicstaticIdentityserviceAccount(Stringemail)

Returns a new service account identity.

Parameter
NameDescription
emailString

An email address that represents a service account. For example,my-other-app@appspot.gserviceaccount.com.

Returns
TypeDescription
Identity

user(String email)

publicstaticIdentityuser(Stringemail)

Returns a new user identity.

Parameter
NameDescription
emailString

An email address that represents a specific Google account. For example,alice@gmail.com orjoe@example.com.

Returns
TypeDescription
Identity

valueOf(String identityStr)

publicstaticIdentityvalueOf(StringidentityStr)

Converts a string to anIdentity. Used primarily for converting protobuf-generated policy identities toIdentity objects.

Parameter
NameDescription
identityStrString
Returns
TypeDescription
Identity

Methods

equals(Object obj)

publicbooleanequals(Objectobj)
Parameter
NameDescription
objObject
Returns
TypeDescription
boolean
Overrides

getType()

publicIdentity.TypegetType()
Returns
TypeDescription
Identity.Type

getValue()

publicStringgetValue()

Returns the string identifier for this identity. The value corresponds to:

  • email address (for identities of typeUSER,SERVICE_ACCOUNT, and GROUP)
  • domain (for identities of typeDOMAIN)
  • null (for identities of typeALL_USERS and ALL_AUTHENTICATED_USERS)
Returns
TypeDescription
String

hashCode()

publicinthashCode()
Returns
TypeDescription
int
Overrides

strValue()

publicStringstrValue()

Returns the string value associated with the identity. Used primarily for converting fromIdentity objects to strings for protobuf-generated policies.

Returns
TypeDescription
String

toString()

publicStringtoString()
Returns
TypeDescription
String
Overrides

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-31 UTC.