Package org.keycloak.models.jpa
Class UserAdapter
- java.lang.Object
-
- org.keycloak.models.jpa.UserAdapter
-
- All Implemented Interfaces:
JpaModel<UserEntity>
,RoleMapperModel
,UserModel
public class UserAdapter extends Object implements UserModel, JpaModel<UserEntity>
- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.keycloak.models.UserModel
UserModel.RequiredAction, UserModel.SearchableFields, UserModel.Streams, UserModel.UserRemovedEvent
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.persistence.EntityManager
em
protected RealmModel
realm
protected UserEntity
user
-
Fields inherited from interface org.keycloak.models.UserModel
COMPARE_BY_USERNAME, DISABLED_REASON, EMAIL, EMAIL_VERIFIED, ENABLED, EXACT, FIRST_NAME, GROUPS, IDP_ALIAS, IDP_USER_ID, INCLUDE_SERVICE_ACCOUNT, LAST_NAME, LOCALE, SEARCH, USERNAME
-
-
Constructor Summary
Constructors Constructor Description UserAdapter(KeycloakSession session, RealmModel realm, javax.persistence.EntityManager em, UserEntity user)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRequiredAction(String actionName)
SubjectCredentialManager
credentialManager()
Instance of a user credential manager to validate and update the credentials of this user.void
deleteRoleMapping(RoleModel role)
Removes the given role mapping from this object.boolean
equals(Object o)
Map<String,List<String>>
getAttributes()
Stream<String>
getAttributeStream(String name)
Obtains all values associated with the specified attribute name.Stream<RoleModel>
getClientRoleMappingsStream(ClientModel app)
Returns stream of client roles that are directly set to this object for the given client.Long
getCreatedTimestamp()
Get timestamp of user creation.String
getEmail()
UserEntity
getEntity()
String
getFederationLink()
String
getFirstAttribute(String name)
String
getFirstName()
long
getGroupsCount()
long
getGroupsCountByNameContaining(String search)
Stream<GroupModel>
getGroupsStream()
Obtains the groups associated with the user.Stream<GroupModel>
getGroupsStream(String search, Integer first, Integer max)
Returns a paginated stream of groups within this realm with search in the nameString
getId()
String
getLastName()
Stream<RoleModel>
getRealmRoleMappingsStream()
Returns stream of realm roles that are directly set to this object.Stream<String>
getRequiredActionsStream()
Obtains the names of required actions associated with the user.Stream<RoleModel>
getRoleMappingsStream()
Returns stream of all role (both realm all client) that are directly set to this object.String
getServiceAccountClientLink()
protected javax.persistence.TypedQuery<UserGroupMembershipEntity>
getUserGroupMappingQuery(GroupModel group)
String
getUsername()
protected javax.persistence.TypedQuery<UserRoleMappingEntity>
getUserRoleMappingEntityTypedQuery(RoleModel role)
void
grantRole(RoleModel role)
Grants the given role to this object.void
grantRoleImpl(RoleModel role)
int
hashCode()
boolean
hasRole(RoleModel role)
Returnstrue
if this object is directly or indirectly assigned the given role,false
otherwise.boolean
isEmailVerified()
boolean
isEnabled()
boolean
isMemberOf(GroupModel group)
void
joinGroup(GroupModel group)
protected void
joinGroupImpl(GroupModel group)
void
leaveGroup(GroupModel group)
void
removeAttribute(String name)
void
removeRequiredAction(String actionName)
void
setAttribute(String name, List<String> values)
void
setCreatedTimestamp(Long timestamp)
void
setEmail(String email)
Sets email for this user.void
setEmailVerified(boolean verified)
void
setEnabled(boolean enabled)
void
setFederationLink(String link)
void
setFirstName(String firstName)
void
setLastName(String lastName)
void
setServiceAccountClientLink(String clientInternalId)
void
setSingleAttribute(String name, String value)
Set single value of specified attribute.void
setUsername(String username)
Sets username for this user.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.keycloak.models.RoleMapperModel
hasDirectRole
-
Methods inherited from interface org.keycloak.models.UserModel
addRequiredAction, removeRequiredAction
-
-
-
-
Field Detail
-
user
protected UserEntity user
-
em
protected javax.persistence.EntityManager em
-
realm
protected RealmModel realm
-
-
Constructor Detail
-
UserAdapter
public UserAdapter(KeycloakSession session, RealmModel realm, javax.persistence.EntityManager em, UserEntity user)
-
-
Method Detail
-
getEntity
public UserEntity getEntity()
- Specified by:
getEntity
in interfaceJpaModel<UserEntity>
-
getUsername
public String getUsername()
- Specified by:
getUsername
in interfaceUserModel
-
setUsername
public void setUsername(String username)
Description copied from interface:UserModel
Sets username for this user. No default method here to allow Abstract subclasses where the username is provided in a different manner- Specified by:
setUsername
in interfaceUserModel
- Parameters:
username
- username string
-
getCreatedTimestamp
public Long getCreatedTimestamp()
Description copied from interface:UserModel
Get timestamp of user creation. May be null for old users created before this feature introduction.- Specified by:
getCreatedTimestamp
in interfaceUserModel
-
setCreatedTimestamp
public void setCreatedTimestamp(Long timestamp)
- Specified by:
setCreatedTimestamp
in interfaceUserModel
-
setEnabled
public void setEnabled(boolean enabled)
- Specified by:
setEnabled
in interfaceUserModel
-
setSingleAttribute
public void setSingleAttribute(String name, String value)
Description copied from interface:UserModel
Set single value of specified attribute. Remove all other existing values of this attribute- Specified by:
setSingleAttribute
in interfaceUserModel
-
setAttribute
public void setAttribute(String name, List<String> values)
- Specified by:
setAttribute
in interfaceUserModel
-
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttribute
in interfaceUserModel
-
getFirstAttribute
public String getFirstAttribute(String name)
- Specified by:
getFirstAttribute
in interfaceUserModel
- Returns:
- null if there is not any value of specified attribute or first value otherwise. Don't throw exception if there are more values of the attribute
-
getAttributeStream
public Stream<String> getAttributeStream(String name)
Description copied from interface:UserModel
Obtains all values associated with the specified attribute name.- Specified by:
getAttributeStream
in interfaceUserModel
- Parameters:
name
- the name of the attribute.- Returns:
- a non-null
Stream
of attribute values.
-
getAttributes
public Map<String,List<String>> getAttributes()
- Specified by:
getAttributes
in interfaceUserModel
-
getRequiredActionsStream
public Stream<String> getRequiredActionsStream()
Description copied from interface:UserModel
Obtains the names of required actions associated with the user.- Specified by:
getRequiredActionsStream
in interfaceUserModel
- Returns:
- a non-null
Stream
of required action names.
-
addRequiredAction
public void addRequiredAction(String actionName)
- Specified by:
addRequiredAction
in interfaceUserModel
-
removeRequiredAction
public void removeRequiredAction(String actionName)
- Specified by:
removeRequiredAction
in interfaceUserModel
-
getFirstName
public String getFirstName()
- Specified by:
getFirstName
in interfaceUserModel
-
setFirstName
public void setFirstName(String firstName)
- Specified by:
setFirstName
in interfaceUserModel
-
getLastName
public String getLastName()
- Specified by:
getLastName
in interfaceUserModel
-
setLastName
public void setLastName(String lastName)
- Specified by:
setLastName
in interfaceUserModel
-
setEmail
public void setEmail(String email)
Description copied from interface:UserModel
Sets email for this user.
-
isEmailVerified
public boolean isEmailVerified()
- Specified by:
isEmailVerified
in interfaceUserModel
-
setEmailVerified
public void setEmailVerified(boolean verified)
- Specified by:
setEmailVerified
in interfaceUserModel
-
getGroupsStream
public Stream<GroupModel> getGroupsStream()
Description copied from interface:UserModel
Obtains the groups associated with the user.- Specified by:
getGroupsStream
in interfaceUserModel
- Returns:
- a non-null
Stream
of groups.
-
getGroupsStream
public Stream<GroupModel> getGroupsStream(String search, Integer first, Integer max)
Description copied from interface:UserModel
Returns a paginated stream of groups within this realm with search in the name- Specified by:
getGroupsStream
in interfaceUserModel
- Parameters:
search
- Case insensitive string which will be searched for. Ignored if null.first
- Index of first group to return. Ignored if negative ornull
.max
- Maximum number of records to return. Ignored if negative ornull
.- Returns:
- Stream of desired groups. Never returns
null
.
-
getGroupsCount
public long getGroupsCount()
- Specified by:
getGroupsCount
in interfaceUserModel
-
getGroupsCountByNameContaining
public long getGroupsCountByNameContaining(String search)
- Specified by:
getGroupsCountByNameContaining
in interfaceUserModel
-
joinGroup
public void joinGroup(GroupModel group)
-
joinGroupImpl
protected void joinGroupImpl(GroupModel group)
-
leaveGroup
public void leaveGroup(GroupModel group)
- Specified by:
leaveGroup
in interfaceUserModel
-
isMemberOf
public boolean isMemberOf(GroupModel group)
- Specified by:
isMemberOf
in interfaceUserModel
-
getUserGroupMappingQuery
protected javax.persistence.TypedQuery<UserGroupMembershipEntity> getUserGroupMappingQuery(GroupModel group)
-
hasRole
public boolean hasRole(RoleModel role)
Description copied from interface:RoleMapperModel
Returnstrue
if this object is directly or indirectly assigned the given role,false
otherwise.For example,
true
is returned for hasRole(R) if:- R is directly assigned to this object
- R is indirectly assigned to this object via composites
- R is not assigned to this object but this object belongs to a group G which is assigned the role R
- R is not assigned to this object but this object belongs to a group G, and G belongs to group H which is assigned the role R
- Specified by:
hasRole
in interfaceRoleMapperModel
- Returns:
- see description
- See Also:
if you want to check if this object is directly assigned to a role
-
getUserRoleMappingEntityTypedQuery
protected javax.persistence.TypedQuery<UserRoleMappingEntity> getUserRoleMappingEntityTypedQuery(RoleModel role)
-
grantRole
public void grantRole(RoleModel role)
Description copied from interface:RoleMapperModel
Grants the given role to this object.- Specified by:
grantRole
in interfaceRoleMapperModel
-
grantRoleImpl
public void grantRoleImpl(RoleModel role)
-
getRealmRoleMappingsStream
public Stream<RoleModel> getRealmRoleMappingsStream()
Description copied from interface:RoleMapperModel
Returns stream of realm roles that are directly set to this object.- Specified by:
getRealmRoleMappingsStream
in interfaceRoleMapperModel
- Returns:
- Stream of
RoleModel
. Never returnsnull
.
-
getRoleMappingsStream
public Stream<RoleModel> getRoleMappingsStream()
Description copied from interface:RoleMapperModel
Returns stream of all role (both realm all client) that are directly set to this object.- Specified by:
getRoleMappingsStream
in interfaceRoleMapperModel
- Returns:
- Stream of
RoleModel
. Never returnsnull
.
-
deleteRoleMapping
public void deleteRoleMapping(RoleModel role)
Description copied from interface:RoleMapperModel
Removes the given role mapping from this object.- Specified by:
deleteRoleMapping
in interfaceRoleMapperModel
- Parameters:
role
- Role to remove
-
getClientRoleMappingsStream
public Stream<RoleModel> getClientRoleMappingsStream(ClientModel app)
Description copied from interface:RoleMapperModel
Returns stream of client roles that are directly set to this object for the given client.- Specified by:
getClientRoleMappingsStream
in interfaceRoleMapperModel
- Parameters:
app
-ClientModel
Client to get the roles for.- Returns:
- Stream of
RoleModel
. Never returnsnull
.
-
getFederationLink
public String getFederationLink()
- Specified by:
getFederationLink
in interfaceUserModel
-
setFederationLink
public void setFederationLink(String link)
- Specified by:
setFederationLink
in interfaceUserModel
-
getServiceAccountClientLink
public String getServiceAccountClientLink()
- Specified by:
getServiceAccountClientLink
in interfaceUserModel
-
setServiceAccountClientLink
public void setServiceAccountClientLink(String clientInternalId)
- Specified by:
setServiceAccountClientLink
in interfaceUserModel
-
credentialManager
public SubjectCredentialManager credentialManager()
Description copied from interface:UserModel
Instance of a user credential manager to validate and update the credentials of this user.- Specified by:
credentialManager
in interfaceUserModel
-
-