public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsManager, GroupManager
Provides CRUD operations for both users and groups. Note that if the
enableAuthorities
property is set to false,
calls to createUser, updateUser and deleteUser will not store the authorities from the
UserDetails or delete authorities for the user. Since this class cannot
differentiate between authorities which were loaded for an individual or for a group of
which the individual is a member, it's important that you take this into account when
using this implementation for managing your users.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEF_CHANGE_PASSWORD_SQL |
static java.lang.String |
DEF_CREATE_USER_SQL |
static java.lang.String |
DEF_DELETE_GROUP_AUTHORITIES_SQL |
static java.lang.String |
DEF_DELETE_GROUP_AUTHORITY_SQL |
static java.lang.String |
DEF_DELETE_GROUP_MEMBER_SQL |
static java.lang.String |
DEF_DELETE_GROUP_MEMBERS_SQL |
static java.lang.String |
DEF_DELETE_GROUP_SQL |
static java.lang.String |
DEF_DELETE_USER_AUTHORITIES_SQL |
static java.lang.String |
DEF_DELETE_USER_SQL |
static java.lang.String |
DEF_FIND_GROUP_ID_SQL |
static java.lang.String |
DEF_FIND_GROUPS_SQL |
static java.lang.String |
DEF_FIND_USERS_IN_GROUP_SQL |
static java.lang.String |
DEF_GROUP_AUTHORITIES_QUERY_SQL |
static java.lang.String |
DEF_INSERT_AUTHORITY_SQL |
static java.lang.String |
DEF_INSERT_GROUP_AUTHORITY_SQL |
static java.lang.String |
DEF_INSERT_GROUP_MEMBER_SQL |
static java.lang.String |
DEF_INSERT_GROUP_SQL |
static java.lang.String |
DEF_RENAME_GROUP_SQL |
static java.lang.String |
DEF_UPDATE_USER_SQL |
static java.lang.String |
DEF_USER_EXISTS_SQL |
protected org.apache.commons.logging.Log |
logger |
DEF_AUTHORITIES_BY_USERNAME_QUERY, DEF_GROUP_AUTHORITIES_BY_USERNAME_QUERY, DEF_USERS_BY_USERNAME_QUERY, messages
Constructor and Description |
---|
JdbcUserDetailsManager() |
JdbcUserDetailsManager(javax.sql.DataSource dataSource) |
Modifier and Type | Method and Description |
---|---|
void |
addGroupAuthority(java.lang.String groupName,
GrantedAuthority authority)
Assigns a new authority to a group.
|
void |
addUserToGroup(java.lang.String username,
java.lang.String groupName)
Makes a user a member of a particular group.
|
void |
changePassword(java.lang.String oldPassword,
java.lang.String newPassword)
Modify the current user's password.
|
void |
createGroup(java.lang.String groupName,
java.util.List<GrantedAuthority> authorities)
Creates a new group with the specified list of authorities.
|
protected Authentication |
createNewAuthentication(Authentication currentAuth,
java.lang.String newPassword) |
void |
createUser(UserDetails user)
Create a new user with the supplied details.
|
void |
deleteGroup(java.lang.String groupName)
Removes a group, including all members and authorities.
|
void |
deleteUser(java.lang.String username)
Remove the user with the given login name from the system.
|
java.util.List<java.lang.String> |
findAllGroups()
Returns the names of all groups that this group manager controls.
|
java.util.List<GrantedAuthority> |
findGroupAuthorities(java.lang.String groupName)
Obtains the list of authorities which are assigned to a group.
|
java.util.List<java.lang.String> |
findUsersInGroup(java.lang.String groupName)
Locates the users who are members of a group
|
protected void |
initDao() |
void |
removeGroupAuthority(java.lang.String groupName,
GrantedAuthority authority)
Deletes an authority from those assigned to a group
|
void |
removeUserFromGroup(java.lang.String username,
java.lang.String groupName)
Deletes a user's membership of a group.
|
void |
renameGroup(java.lang.String oldName,
java.lang.String newName)
Changes the name of a group without altering the assigned authorities or members.
|
void |
setAuthenticationManager(AuthenticationManager authenticationManager) |
void |
setChangePasswordSql(java.lang.String changePasswordSql) |
void |
setCreateAuthoritySql(java.lang.String createAuthoritySql) |
void |
setCreateUserSql(java.lang.String createUserSql) |
void |
setDeleteGroupAuthoritiesSql(java.lang.String deleteGroupAuthoritiesSql) |
void |
setDeleteGroupAuthoritySql(java.lang.String deleteGroupAuthoritySql) |
void |
setDeleteGroupMemberSql(java.lang.String deleteGroupMemberSql) |
void |
setDeleteGroupMembersSql(java.lang.String deleteGroupMembersSql) |
void |
setDeleteGroupSql(java.lang.String deleteGroupSql) |
void |
setDeleteUserAuthoritiesSql(java.lang.String deleteUserAuthoritiesSql) |
void |
setDeleteUserSql(java.lang.String deleteUserSql) |
void |
setFindAllGroupsSql(java.lang.String findAllGroupsSql) |
void |
setFindGroupIdSql(java.lang.String findGroupIdSql) |
void |
setFindUsersInGroupSql(java.lang.String findUsersInGroupSql) |
void |
setGroupAuthoritiesSql(java.lang.String groupAuthoritiesSql) |
void |
setInsertGroupAuthoritySql(java.lang.String insertGroupAuthoritySql) |
void |
setInsertGroupMemberSql(java.lang.String insertGroupMemberSql) |
void |
setInsertGroupSql(java.lang.String insertGroupSql) |
void |
setRenameGroupSql(java.lang.String renameGroupSql) |
void |
setUpdateUserSql(java.lang.String updateUserSql) |
void |
setUserCache(UserCache userCache)
Optionally sets the UserCache if one is in use in the application.
|
void |
setUserExistsSql(java.lang.String userExistsSql) |
void |
updateUser(UserDetails user)
Update the specified user.
|
boolean |
userExists(java.lang.String username)
Check if a user with the supplied login name exists in the system.
|
addCustomAuthorities, createUserDetails, getAuthoritiesByUsernameQuery, getEnableAuthorities, getEnableGroups, getMessages, getRolePrefix, getUsersByUsernameQuery, isUsernameBasedPrimaryKey, loadGroupAuthorities, loadUserAuthorities, loadUserByUsername, loadUsersByUsername, setAuthoritiesByUsernameQuery, setEnableAuthorities, setEnableGroups, setGroupAuthoritiesByUsernameQuery, setMessageSource, setRolePrefix, setUsernameBasedPrimaryKey, setUsersByUsernameQuery
checkDaoConfig, createJdbcTemplate, getConnection, getDataSource, getExceptionTranslator, getJdbcTemplate, initTemplateConfig, releaseConnection, setDataSource, setJdbcTemplate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
loadUserByUsername
public static final java.lang.String DEF_CREATE_USER_SQL
public static final java.lang.String DEF_DELETE_USER_SQL
public static final java.lang.String DEF_UPDATE_USER_SQL
public static final java.lang.String DEF_INSERT_AUTHORITY_SQL
public static final java.lang.String DEF_DELETE_USER_AUTHORITIES_SQL
public static final java.lang.String DEF_USER_EXISTS_SQL
public static final java.lang.String DEF_CHANGE_PASSWORD_SQL
public static final java.lang.String DEF_FIND_GROUPS_SQL
public static final java.lang.String DEF_FIND_USERS_IN_GROUP_SQL
public static final java.lang.String DEF_INSERT_GROUP_SQL
public static final java.lang.String DEF_FIND_GROUP_ID_SQL
public static final java.lang.String DEF_INSERT_GROUP_AUTHORITY_SQL
public static final java.lang.String DEF_DELETE_GROUP_SQL
public static final java.lang.String DEF_DELETE_GROUP_AUTHORITIES_SQL
public static final java.lang.String DEF_DELETE_GROUP_MEMBERS_SQL
public static final java.lang.String DEF_RENAME_GROUP_SQL
public static final java.lang.String DEF_INSERT_GROUP_MEMBER_SQL
public static final java.lang.String DEF_DELETE_GROUP_MEMBER_SQL
public static final java.lang.String DEF_GROUP_AUTHORITIES_QUERY_SQL
public static final java.lang.String DEF_DELETE_GROUP_AUTHORITY_SQL
protected final org.apache.commons.logging.Log logger
public JdbcUserDetailsManager()
public JdbcUserDetailsManager(javax.sql.DataSource dataSource)
protected void initDao() throws org.springframework.context.ApplicationContextException
initDao
in class JdbcDaoImpl
org.springframework.context.ApplicationContextException
public void createUser(UserDetails user)
UserDetailsManager
createUser
in interface UserDetailsManager
public void updateUser(UserDetails user)
UserDetailsManager
updateUser
in interface UserDetailsManager
public void deleteUser(java.lang.String username)
UserDetailsManager
deleteUser
in interface UserDetailsManager
public void changePassword(java.lang.String oldPassword, java.lang.String newPassword) throws AuthenticationException
UserDetailsManager
changePassword
in interface UserDetailsManager
oldPassword
- current password (for re-authentication if required)newPassword
- the password to change toAuthenticationException
protected Authentication createNewAuthentication(Authentication currentAuth, java.lang.String newPassword)
public boolean userExists(java.lang.String username)
UserDetailsManager
userExists
in interface UserDetailsManager
public java.util.List<java.lang.String> findAllGroups()
GroupManager
findAllGroups
in interface GroupManager
public java.util.List<java.lang.String> findUsersInGroup(java.lang.String groupName)
GroupManager
findUsersInGroup
in interface GroupManager
groupName
- the group whose members are requiredpublic void createGroup(java.lang.String groupName, java.util.List<GrantedAuthority> authorities)
GroupManager
createGroup
in interface GroupManager
groupName
- the name for the new groupauthorities
- the authorities which are to be allocated to this group.public void deleteGroup(java.lang.String groupName)
GroupManager
deleteGroup
in interface GroupManager
groupName
- the group to remove.public void renameGroup(java.lang.String oldName, java.lang.String newName)
GroupManager
renameGroup
in interface GroupManager
public void addUserToGroup(java.lang.String username, java.lang.String groupName)
GroupManager
addUserToGroup
in interface GroupManager
username
- the user to be given membership.groupName
- the name of the group to which the user will be added.public void removeUserFromGroup(java.lang.String username, java.lang.String groupName)
GroupManager
removeUserFromGroup
in interface GroupManager
username
- the usergroupName
- the group to remove them frompublic java.util.List<GrantedAuthority> findGroupAuthorities(java.lang.String groupName)
GroupManager
findGroupAuthorities
in interface GroupManager
public void removeGroupAuthority(java.lang.String groupName, GrantedAuthority authority)
GroupManager
removeGroupAuthority
in interface GroupManager
public void addGroupAuthority(java.lang.String groupName, GrantedAuthority authority)
GroupManager
addGroupAuthority
in interface GroupManager
public void setAuthenticationManager(AuthenticationManager authenticationManager)
public void setCreateUserSql(java.lang.String createUserSql)
public void setDeleteUserSql(java.lang.String deleteUserSql)
public void setUpdateUserSql(java.lang.String updateUserSql)
public void setCreateAuthoritySql(java.lang.String createAuthoritySql)
public void setDeleteUserAuthoritiesSql(java.lang.String deleteUserAuthoritiesSql)
public void setUserExistsSql(java.lang.String userExistsSql)
public void setChangePasswordSql(java.lang.String changePasswordSql)
public void setFindAllGroupsSql(java.lang.String findAllGroupsSql)
public void setFindUsersInGroupSql(java.lang.String findUsersInGroupSql)
public void setInsertGroupSql(java.lang.String insertGroupSql)
public void setFindGroupIdSql(java.lang.String findGroupIdSql)
public void setInsertGroupAuthoritySql(java.lang.String insertGroupAuthoritySql)
public void setDeleteGroupSql(java.lang.String deleteGroupSql)
public void setDeleteGroupAuthoritiesSql(java.lang.String deleteGroupAuthoritiesSql)
public void setDeleteGroupMembersSql(java.lang.String deleteGroupMembersSql)
public void setRenameGroupSql(java.lang.String renameGroupSql)
public void setInsertGroupMemberSql(java.lang.String insertGroupMemberSql)
public void setDeleteGroupMemberSql(java.lang.String deleteGroupMemberSql)
public void setGroupAuthoritiesSql(java.lang.String groupAuthoritiesSql)
public void setDeleteGroupAuthoritySql(java.lang.String deleteGroupAuthoritySql)
public void setUserCache(UserCache userCache)
userCache
- the cache used by the AuthenticationManager.