public class Users extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Users.Command
Command is an interface used to perform operations on a
UserEntity while safely updating
a UserEntity object. |
Modifier and Type | Field and Description |
---|---|
protected Configuration |
configuration |
protected AmbariLdapConfigurationProvider |
ldapConfigurationProvider |
Constructor and Description |
---|
Users() |
Modifier and Type | Method and Description |
---|---|
void |
addAuthentication(UserEntity userEntity,
UserAuthenticationType authenticationType,
String key)
Adds a new authentication type for the given user.
|
void |
addJWTAuthentication(UserEntity userEntity,
String key)
Adds the ability for a user to authenticate using a JWT token.
|
void |
addJWTAuthentication(UserEntity userEntity,
String key,
boolean persist)
Adds the ability for a user to authenticate using a JWT token.
|
void |
addKerberosAuthentication(UserEntity userEntity,
String principalName)
Adds the ability for a user to authenticate using a Kerberos token.
|
void |
addKerberosAuthentication(UserEntity userEntity,
String principalName,
boolean persist)
Adds the ability for a user to authenticate using a Kerberos token.
|
void |
addLdapAuthentication(UserEntity userEntity,
String dn)
Adds the ability for a user to authenticate using a remote LDAP server
|
void |
addLdapAuthentication(UserEntity userEntity,
String dn,
boolean persist)
Adds the ability for a user to authenticate using a remote LDAP server
|
void |
addLocalAuthentication(UserEntity userEntity,
String password)
Adds the ability for a user to authenticate using a password stored in Ambari's database
|
void |
addLocalAuthentication(UserEntity userEntity,
String password,
boolean persist)
Adds the ability for a user to authenticate using a password stored in Ambari's database
|
void |
addMemberToGroup(GroupEntity groupEntity,
UserEntity userEntity) |
void |
addMemberToGroup(String groupName,
String userName) |
void |
addPamAuthentication(UserEntity userEntity,
String userName)
Adds the ability for a user to authenticate using Pam
|
void |
addPamAuthentication(UserEntity userEntity,
String userName,
boolean persist)
Adds the ability for a user to authenticate using Pam
|
void |
clearConsecutiveAuthenticationFailures(String username)
Resets the named user's consecutive authentication failure count to
0 . |
void |
clearConsecutiveAuthenticationFailures(UserEntity userEntity)
Resets the named user's consecutive authentication failure count to
0 . |
GroupEntity |
createGroup(String groupName,
GroupType groupType)
Creates new group with provided name & type
|
UserEntity |
createUser(String userName,
String localUserName,
String displayName)
Creates new, active, user with provided userName, local username, and display name.
|
UserEntity |
createUser(String userName,
String localUserName,
String displayName,
Boolean active)
Creates new, user with provided userName, local username, and display name.
|
void |
executeUserHook(Map<String,Set<String>> userGroupsMap)
Triggers the post user creation hook, if enabled
|
void |
executeUserHook(String username)
Triggers the post user creation hook, if enabled
|
List<Group> |
getAllGroups()
Gets all groups.
|
List<String> |
getAllMembers(String groupName)
Gets all members of a group specified.
|
List<UserEntity> |
getAllUserEntities() |
List<User> |
getAllUsers() |
Group |
getGroup(String groupName)
Gets group by given name.
|
Group |
getGroup(String groupName,
GroupType groupType)
Gets group by given name & type.
|
GroupEntity |
getGroupEntity(String groupName,
GroupType groupType)
Gets a
GroupEntity by name and type. |
Collection<User> |
getGroupMembers(String groupName)
Gets group members.
|
Collection<PrivilegeEntity> |
getGroupPrivileges(GroupEntity groupEntity)
Gets the explicit and implicit privileges for the given group.
|
User |
getUser(Integer userId) |
User |
getUser(String userName) |
User |
getUser(UserEntity userEntity) |
Collection<UserAuthenticationEntity> |
getUserAuthenticationEntities(String username,
UserAuthenticationType authenticationType)
Gets the collection of
UserAuthenticationEntity s for a given user. |
Collection<UserAuthenticationEntity> |
getUserAuthenticationEntities(UserAuthenticationType authenticationType,
String key)
Find the
UserAuthenticationEntity items for a specific UserAuthenticationType
and key value. |
Collection<UserAuthenticationEntity> |
getUserAuthenticationEntities(UserEntity userEntity,
UserAuthenticationType authenticationType)
Gets the collection of
UserAuthenticationEntity s for a given user. |
Collection<AmbariGrantedAuthority> |
getUserAuthorities(String userName)
Gets the explicit and implicit authorities for the given user.
|
Collection<AmbariGrantedAuthority> |
getUserAuthorities(UserEntity userEntity)
Gets the explicit and implicit authorities for the given user.
|
UserEntity |
getUserEntity(Integer userId) |
UserEntity |
getUserEntity(String userName) |
Collection<PrivilegeEntity> |
getUserPrivileges(UserEntity userEntity)
Gets the explicit and implicit privileges for the given user.
|
void |
grantAdminPrivilege(Integer userId)
Grants Ambari Administrator privilege to provided user.
|
void |
grantAdminPrivilege(UserEntity userEntity)
Grants Ambari Administrator privilege to provided user.
|
void |
grantPrivilegeToGroup(Integer groupId,
Long resourceId,
ResourceType resourceType,
String permissionName)
Grants privilege to provided group.
|
boolean |
hasAdminPrivilege(UserEntity userEntity)
Test the user for Ambari Admistrator privileges.
|
Integer |
incrementConsecutiveAuthenticationFailures(String username)
Increments the named user's consecutive authentication failure count by
1 . |
Integer |
incrementConsecutiveAuthenticationFailures(UserEntity userEntity)
Increments the named user's consecutive authentication failure count by
1 . |
boolean |
isUserCanBeRemoved(UserEntity userEntity)
Performs a check if the user can be removed.
|
boolean |
isUserInGroup(UserEntity userEntity,
GroupEntity groupEntity)
Performs a check if given user belongs to given group.
|
void |
modifyAuthentication(UserAuthenticationEntity userAuthenticationEntity,
String currentKey,
String newKey,
boolean isSelf)
Modifies authentication key of an authentication source for a user
|
void |
processLdapSync(LdapBatchDto batchInfo)
Executes batch queries to database to insert large amounts of LDAP data.
|
void |
removeAuthentication(String username,
Long authenticationId) |
void |
removeAuthentication(UserEntity userEntity,
Long authenticationId) |
void |
removeGroup(Group group) |
void |
removeMemberFromGroup(GroupEntity groupEntity,
UserEntity userEntity) |
void |
removeMemberFromGroup(String groupName,
String userName) |
void |
removeUser(User user)
Removes a user from the Ambari database.
|
void |
removeUser(UserEntity userEntity)
Removes a user from the Ambari database.
|
void |
revokeAdminPrivilege(Integer userId)
Revokes Ambari Administrator privileges from provided user.
|
void |
revokeAdminPrivilege(UserEntity userEntity)
Revokes Ambari Administrator privileges from provided user.
|
UserEntity |
safelyUpdateUserEntity(UserEntity userEntity,
Users.Command command)
Attempts to update the specified
UserEntity while handling OptimisticLockException s
by obtaining the latest version of the UserEntity and retrying the operation. |
UserEntity |
safelyUpdateUserEntity(UserEntity userEntity,
Users.Command command,
int maxRetries)
Attempts to update the specified
UserEntity while handling OptimisticLockException s
by obtaining the latest version of the UserEntity and retrying the operation. |
void |
setGroupLdap(String groupName)
Converts group to LDAP group.
|
void |
setUserActive(String userName,
boolean active)
Enables/disables user.
|
void |
setUserActive(UserEntity userEntity,
boolean active)
Enables/disables user.
|
void |
validateLogin(UserEntity userEntity,
String userName)
Validates the user account such that the user is allowed to log in.
|
void |
validatePassword(String password)
Validates the password meets configured requirements according ambari.properties.
|
@Inject protected AmbariLdapConfigurationProvider ldapConfigurationProvider
@Inject protected Configuration configuration
public List<UserEntity> getAllUserEntities()
public UserEntity getUserEntity(String userName)
public UserEntity getUserEntity(Integer userId)
public User getUser(UserEntity userEntity)
public void setUserActive(String userName, boolean active) throws org.apache.ambari.server.AmbariException
userName
- user nameactive
- true if active; false if not activeorg.apache.ambari.server.AmbariException
- if user does not existpublic void setUserActive(UserEntity userEntity, boolean active) throws org.apache.ambari.server.AmbariException
userEntity
- the useractive
- true if active; false if not activeorg.apache.ambari.server.AmbariException
- if user does not existpublic void validateLogin(UserEntity userEntity, String userName)
userEntity
- the user entityuserName
- the Ambari usernamepublic void setGroupLdap(String groupName) throws org.apache.ambari.server.AmbariException
groupName
- group nameorg.apache.ambari.server.AmbariException
- if group does not existpublic UserEntity createUser(String userName, String localUserName, String displayName) throws org.apache.ambari.server.AmbariException
userName
- user namelocalUserName
- the local username to use; if null
or empty, userName will be useddisplayName
- the name to display for presentation; if null
or empty, userName will be usedorg.apache.ambari.server.AmbariException
- if user already existspublic UserEntity createUser(String userName, String localUserName, String displayName, Boolean active) throws org.apache.ambari.server.AmbariException
userName
- user namelocalUserName
- the local username to use; if null
or empty, userName will be useddisplayName
- the name to display for presentation; if null
or empty, userName will be usedactive
- is user activeorg.apache.ambari.server.AmbariException
- if user already existspublic void executeUserHook(String username)
username
- the username of the user to processpublic void executeUserHook(Map<String,Set<String>> userGroupsMap)
userGroupsMap
- a map of user names to relevant groupspublic void removeUser(User user) throws org.apache.ambari.server.AmbariException
It is expected that the associated user authentication records are removed by this operation as well.
user
- the user to removeorg.apache.ambari.server.AmbariException
public void removeUser(UserEntity userEntity) throws org.apache.ambari.server.AmbariException
It is expected that the associated user authentication records are removed by this operation as well.
userEntity
- the user to removeorg.apache.ambari.server.AmbariException
public Group getGroup(String groupName)
groupName
- group namepublic Group getGroup(String groupName, GroupType groupType)
groupName
- group namegroupType
- group typepublic GroupEntity getGroupEntity(String groupName, GroupType groupType)
GroupEntity
by name and type.groupName
- group namegroupType
- group typepublic Collection<User> getGroupMembers(String groupName)
groupName
- group namepublic GroupEntity createGroup(String groupName, GroupType groupType)
public List<String> getAllMembers(String groupName) throws org.apache.ambari.server.AmbariException
groupName
- group nameorg.apache.ambari.server.AmbariException
public void removeGroup(Group group) throws org.apache.ambari.server.AmbariException
org.apache.ambari.server.AmbariException
public boolean hasAdminPrivilege(UserEntity userEntity)
userEntity
- the user to testpublic void grantAdminPrivilege(Integer userId)
userId
- user idpublic void grantAdminPrivilege(UserEntity userEntity)
userEntity
- the userpublic void grantPrivilegeToGroup(Integer groupId, Long resourceId, ResourceType resourceType, String permissionName)
groupId
- group idresourceId
- resource idresourceType
- resource typepermissionName
- permission namepublic void revokeAdminPrivilege(Integer userId)
userId
- user idpublic void revokeAdminPrivilege(UserEntity userEntity)
userEntity
- the userpublic void addMemberToGroup(String groupName, String userName) throws org.apache.ambari.server.AmbariException
org.apache.ambari.server.AmbariException
public void addMemberToGroup(GroupEntity groupEntity, UserEntity userEntity) throws org.apache.ambari.server.AmbariException
org.apache.ambari.server.AmbariException
public void removeMemberFromGroup(String groupName, String userName) throws org.apache.ambari.server.AmbariException
org.apache.ambari.server.AmbariException
public void removeMemberFromGroup(GroupEntity groupEntity, UserEntity userEntity) throws org.apache.ambari.server.AmbariException
org.apache.ambari.server.AmbariException
public boolean isUserCanBeRemoved(UserEntity userEntity)
userEntity
- user to be checkedpublic boolean isUserInGroup(UserEntity userEntity, GroupEntity groupEntity)
userEntity
- user entitygroupEntity
- group entitypublic void processLdapSync(LdapBatchDto batchInfo)
batchInfo
- DTO with batch informationpublic Collection<PrivilegeEntity> getUserPrivileges(UserEntity userEntity)
The explicit privileges are the privileges that have be explicitly set by assigning roles to a user. For example the Cluster Operator role on a given cluster gives that the ability to start and stop services in that cluster, among other privileges for that particular cluster.
The implicit privileges are the privileges that have been given to the roles themselves which in turn are granted to the users that have been assigned those roles. For example if the Cluster User role for a given cluster has been given View User access on a specified File View instance, then all users who have the Cluster User role for that cluster will implicitly be granted View User access on that File View instance.
userEntity
- the relevant userpublic Collection<PrivilegeEntity> getGroupPrivileges(GroupEntity groupEntity)
The explicit privileges are the privileges that have be explicitly set by assigning roles to a group. For example the Cluster Operator role on a given cluster gives that the ability to start and stop services in that cluster, among other privileges for that particular cluster.
The implicit privileges are the privileges that have been given to the roles themselves which in turn are granted to the groups that have been assigned those roles. For example if the Cluster User role for a given cluster has been given View User access on a specified File View instance, then all groups that have the Cluster User role for that cluster will implicitly be granted View User access on that File View instance.
groupEntity
- the relevant grouppublic Collection<AmbariGrantedAuthority> getUserAuthorities(String userName)
The explicit authorities are the authorities that have be explicitly set by assigning roles to a user. For example the Cluster Operator role on a given cluster gives that the ability to start and stop services in that cluster, among other privileges for that particular cluster.
The implicit authorities are the authorities that have been given to the roles themselves which in turn are granted to the users that have been assigned those roles. For example if the Cluster User role for a given cluster has been given View User access on a specified File View instance, then all users who have the Cluster User role for that cluster will implicitly be granted View User access on that File View instance.
userName
- the username for the relevant userpublic Collection<AmbariGrantedAuthority> getUserAuthorities(UserEntity userEntity)
The explicit authorities are the authorities that have be explicitly set by assigning roles to a user. For example the Cluster Operator role on a given cluster gives that the ability to start and stop services in that cluster, among other privileges for that particular cluster.
The implicit authorities are the authorities that have been given to the roles themselves which in turn are granted to the users that have been assigned those roles. For example if the Cluster User role for a given cluster has been given View User access on a specified File View instance, then all users who have the Cluster User role for that cluster will implicitly be granted View User access on that File View instance.
userEntity
- the relevant userpublic Collection<UserAuthenticationEntity> getUserAuthenticationEntities(String username, UserAuthenticationType authenticationType)
UserAuthenticationEntity
s for a given user.username
- the username of a user; if null assumes all usersauthenticationType
- the authentication type, if null assumes allUserAuthenticationEntity
spublic Collection<UserAuthenticationEntity> getUserAuthenticationEntities(UserEntity userEntity, UserAuthenticationType authenticationType)
UserAuthenticationEntity
s for a given user.userEntity
- the user; if null assumes all usersauthenticationType
- the authentication type, if null assumes allUserAuthenticationEntity
spublic Collection<UserAuthenticationEntity> getUserAuthenticationEntities(UserAuthenticationType authenticationType, String key)
UserAuthenticationEntity
items for a specific UserAuthenticationType
and key value.authenticationType
- the authentication typekey
- the key valueUserAuthenticationEntity
valuespublic void modifyAuthentication(UserAuthenticationEntity userAuthenticationEntity, String currentKey, String newKey, boolean isSelf) throws org.apache.ambari.server.AmbariException
org.apache.ambari.server.AmbariException
public void removeAuthentication(UserEntity userEntity, Long authenticationId)
public void addAuthentication(UserEntity userEntity, UserAuthenticationType authenticationType, String key) throws org.apache.ambari.server.AmbariException
userEntity
- the userauthenticationType
- the authentication typekey
- the relevant keyorg.apache.ambari.server.AmbariException
addLocalAuthentication(UserEntity, String)
,
addLdapAuthentication(UserEntity, String)
,
addJWTAuthentication(UserEntity, String)
,
addKerberosAuthentication(UserEntity, String)
,
addPamAuthentication(UserEntity, String)
public void addJWTAuthentication(UserEntity userEntity, String key) throws org.apache.ambari.server.AmbariException
The key for this authentication mechanism is the username expected to be in the JWT token.
The created UserAuthenticationEntity
and the supplied UserEntity
are persisted.
userEntity
- the userkey
- the relevant keyorg.apache.ambari.server.AmbariException
addJWTAuthentication(UserEntity, String, boolean)
public void addJWTAuthentication(UserEntity userEntity, String key, boolean persist) throws org.apache.ambari.server.AmbariException
The key for this authentication mechanism is the username expected to be in the JWT token.
userEntity
- the userkey
- the relevant keypersist
- true, to persist the created entity; false, to not persist the created entityorg.apache.ambari.server.AmbariException
public void addKerberosAuthentication(UserEntity userEntity, String principalName) throws org.apache.ambari.server.AmbariException
The created UserAuthenticationEntity
and the supplied UserEntity
are persisted.
userEntity
- the userprincipalName
- the user's principal nameorg.apache.ambari.server.AmbariException
addKerberosAuthentication(UserEntity, String, boolean)
public void addKerberosAuthentication(UserEntity userEntity, String principalName, boolean persist) throws org.apache.ambari.server.AmbariException
userEntity
- the userprincipalName
- the user's principal namepersist
- true, to persist the created entity; false, to not persist the created entityorg.apache.ambari.server.AmbariException
public void addLocalAuthentication(UserEntity userEntity, String password) throws org.apache.ambari.server.AmbariException
The supplied plaintext password will be encoded before storing.
The created UserAuthenticationEntity
and the supplied UserEntity
are persisted.
userEntity
- the userpassword
- the user's plaintext passwordorg.apache.ambari.server.AmbariException
addLocalAuthentication(UserEntity, String, boolean)
public void addLocalAuthentication(UserEntity userEntity, String password, boolean persist) throws org.apache.ambari.server.AmbariException
The supplied plaintext password will be encoded before storing.
userEntity
- the userpassword
- the user's plaintext passwordpersist
- true, to persist the created entity; false, to not persist the created entityorg.apache.ambari.server.AmbariException
public void addPamAuthentication(UserEntity userEntity, String userName) throws org.apache.ambari.server.AmbariException
The created UserAuthenticationEntity
and the supplied UserEntity
are persisted.
userEntity
- the useruserName
- the user's os-level usernameorg.apache.ambari.server.AmbariException
addPamAuthentication(UserEntity, String, boolean)
public void addPamAuthentication(UserEntity userEntity, String userName, boolean persist) throws org.apache.ambari.server.AmbariException
userEntity
- the useruserName
- the user's os-level usernamepersist
- true, to persist the created entity; false, to not persist the created entityorg.apache.ambari.server.AmbariException
public void addLdapAuthentication(UserEntity userEntity, String dn) throws org.apache.ambari.server.AmbariException
The created UserAuthenticationEntity
and the supplied UserEntity
are persisted.
userEntity
- the userdn
- the user's distinguished nameorg.apache.ambari.server.AmbariException
addLdapAuthentication(UserEntity, String, boolean)
public void addLdapAuthentication(UserEntity userEntity, String dn, boolean persist) throws org.apache.ambari.server.AmbariException
userEntity
- the userdn
- the user's distinguished namepersist
- true, to persist the created entity; false, to not persist the created entityorg.apache.ambari.server.AmbariException
public Integer incrementConsecutiveAuthenticationFailures(String username)
1
.
This operation is safe when concurrent authentication attempts by the same username are made
due to UserEntity.version
and optimistic locking.
username
- the user's usernamepublic Integer incrementConsecutiveAuthenticationFailures(UserEntity userEntity)
1
.
This operation is safe when concurrent authentication attempts by the same username are made
due to UserEntity.version
and optimistic locking.
userEntity
- the userpublic void clearConsecutiveAuthenticationFailures(String username)
0
.
This operation is safe when concurrent authentication attempts by the same username are made
due to UserEntity.version
and optimistic locking.
username
- the user's usernamepublic void clearConsecutiveAuthenticationFailures(UserEntity userEntity)
0
.
This operation is safe when concurrent authentication attempts by the same username are made
due to UserEntity.version
and optimistic locking.
userEntity
- the userpublic UserEntity safelyUpdateUserEntity(UserEntity userEntity, Users.Command command)
UserEntity
while handling OptimisticLockException
s
by obtaining the latest version of the UserEntity
and retrying the operation.
If the maximum number of retries is exceeded (see MAX_RETRIES
), then the operation
will fail by rethrowing the last exception encountered.userEntity
- the user entitycommand
- a command to perform on the user entity object that changes it state thus needing
to be persistedpublic UserEntity safelyUpdateUserEntity(UserEntity userEntity, Users.Command command, int maxRetries)
UserEntity
while handling OptimisticLockException
s
by obtaining the latest version of the UserEntity
and retrying the operation.
If the maximum number of retries is exceeded, then the operation will fail by rethrowing the last
exception encountered.userEntity
- the user entitycommand
- a command to perform on the user entity object that changes it state thus needing
to be persistedmaxRetries
- the maximum number of reties to peform before failingpublic void validatePassword(String password)
password
- the passwordIllegalArgumentException
- if password does not meet the password policy requirementsCopyright © 2022 Apache Software Foundation. All rights reserved.