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 String |
DEF_CHANGE_PASSWORD_SQL |
static String |
DEF_CREATE_USER_SQL |
static String |
DEF_DELETE_GROUP_AUTHORITIES_SQL |
static String |
DEF_DELETE_GROUP_AUTHORITY_SQL |
static String |
DEF_DELETE_GROUP_MEMBER_SQL |
static String |
DEF_DELETE_GROUP_MEMBERS_SQL |
static String |
DEF_DELETE_GROUP_SQL |
static String |
DEF_DELETE_USER_AUTHORITIES_SQL |
static String |
DEF_DELETE_USER_SQL |
static String |
DEF_FIND_GROUP_ID_SQL |
static String |
DEF_FIND_GROUPS_SQL |
static String |
DEF_FIND_USERS_IN_GROUP_SQL |
static String |
DEF_GROUP_AUTHORITIES_QUERY_SQL |
static String |
DEF_INSERT_AUTHORITY_SQL |
static String |
DEF_INSERT_GROUP_AUTHORITY_SQL |
static String |
DEF_INSERT_GROUP_MEMBER_SQL |
static String |
DEF_INSERT_GROUP_SQL |
static String |
DEF_RENAME_GROUP_SQL |
static String |
DEF_UPDATE_USER_SQL |
static 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() |
| Modifier and Type | Method and Description |
|---|---|
void |
addGroupAuthority(String groupName,
GrantedAuthority authority)
Assigns a new authority to a group.
|
void |
addUserToGroup(String username,
String groupName)
Makes a user a member of a particular group.
|
void |
changePassword(String oldPassword,
String newPassword)
Modify the current user's password.
|
void |
createGroup(String groupName,
List<GrantedAuthority> authorities)
Creates a new group with the specified list of authorities.
|
protected Authentication |
createNewAuthentication(Authentication currentAuth,
String newPassword) |
void |
createUser(UserDetails user)
Create a new user with the supplied details.
|
void |
deleteGroup(String groupName)
Removes a group, including all members and authorities.
|
void |
deleteUser(String username)
Remove the user with the given login name from the system.
|
List<String> |
findAllGroups()
Returns the names of all groups that this group manager controls.
|
List<GrantedAuthority> |
findGroupAuthorities(String groupName)
Obtains the list of authorities which are assigned to a group.
|
List<String> |
findUsersInGroup(String groupName)
Locates the users who are members of a group
|
protected void |
initDao() |
void |
removeGroupAuthority(String groupName,
GrantedAuthority authority)
Deletes an authority from those assigned to a group
|
void |
removeUserFromGroup(String username,
String groupName)
Deletes a user's membership of a group.
|
void |
renameGroup(String oldName,
String newName)
Changes the name of a group without altering the assigned authorities or members.
|
void |
setAuthenticationManager(AuthenticationManager authenticationManager) |
void |
setChangePasswordSql(String changePasswordSql) |
void |
setCreateAuthoritySql(String createAuthoritySql) |
void |
setCreateUserSql(String createUserSql) |
void |
setDeleteGroupAuthoritiesSql(String deleteGroupAuthoritiesSql) |
void |
setDeleteGroupAuthoritySql(String deleteGroupAuthoritySql) |
void |
setDeleteGroupMemberSql(String deleteGroupMemberSql) |
void |
setDeleteGroupMembersSql(String deleteGroupMembersSql) |
void |
setDeleteGroupSql(String deleteGroupSql) |
void |
setDeleteUserAuthoritiesSql(String deleteUserAuthoritiesSql) |
void |
setDeleteUserSql(String deleteUserSql) |
void |
setFindAllGroupsSql(String findAllGroupsSql) |
void |
setFindGroupIdSql(String findGroupIdSql) |
void |
setFindUsersInGroupSql(String findUsersInGroupSql) |
void |
setGroupAuthoritiesSql(String groupAuthoritiesSql) |
void |
setInsertGroupAuthoritySql(String insertGroupAuthoritySql) |
void |
setInsertGroupMemberSql(String insertGroupMemberSql) |
void |
setInsertGroupSql(String insertGroupSql) |
void |
setRenameGroupSql(String renameGroupSql) |
void |
setUpdateUserSql(String updateUserSql) |
void |
setUserCache(UserCache userCache)
Optionally sets the UserCache if one is in use in the application.
|
void |
setUserExistsSql(String userExistsSql) |
void |
updateUser(UserDetails user)
Update the specified user.
|
boolean |
userExists(String username)
Check if a user with the supplied login name exists in the system.
|
addCustomAuthorities, createUserDetails, getAuthoritiesByUsernameQuery, getEnableAuthorities, getEnableGroups, getRolePrefix, getUsersByUsernameQuery, isUsernameBasedPrimaryKey, loadGroupAuthorities, loadUserAuthorities, loadUserByUsername, loadUsersByUsername, setAuthoritiesByUsernameQuery, setEnableAuthorities, setEnableGroups, setGroupAuthoritiesByUsernameQuery, setRolePrefix, setUsernameBasedPrimaryKey, setUsersByUsernameQuerycheckDaoConfig, createJdbcTemplate, getConnection, getDataSource, getExceptionTranslator, getJdbcTemplate, initTemplateConfig, releaseConnection, setDataSource, setJdbcTemplateafterPropertiesSetclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitloadUserByUsernamepublic static final String DEF_CREATE_USER_SQL
public static final String DEF_DELETE_USER_SQL
public static final String DEF_UPDATE_USER_SQL
public static final String DEF_INSERT_AUTHORITY_SQL
public static final String DEF_DELETE_USER_AUTHORITIES_SQL
public static final String DEF_USER_EXISTS_SQL
public static final String DEF_CHANGE_PASSWORD_SQL
public static final String DEF_FIND_GROUPS_SQL
public static final String DEF_FIND_USERS_IN_GROUP_SQL
public static final String DEF_INSERT_GROUP_SQL
public static final String DEF_FIND_GROUP_ID_SQL
public static final String DEF_INSERT_GROUP_AUTHORITY_SQL
public static final String DEF_DELETE_GROUP_SQL
public static final String DEF_DELETE_GROUP_AUTHORITIES_SQL
public static final String DEF_DELETE_GROUP_MEMBERS_SQL
public static final String DEF_RENAME_GROUP_SQL
public static final String DEF_INSERT_GROUP_MEMBER_SQL
public static final String DEF_DELETE_GROUP_MEMBER_SQL
public static final String DEF_GROUP_AUTHORITIES_QUERY_SQL
public static final String DEF_DELETE_GROUP_AUTHORITY_SQL
protected final org.apache.commons.logging.Log logger
protected void initDao()
throws ApplicationContextException
initDao in class JdbcDaoImplApplicationContextExceptionpublic void createUser(UserDetails user)
UserDetailsManagercreateUser in interface UserDetailsManagerpublic void updateUser(UserDetails user)
UserDetailsManagerupdateUser in interface UserDetailsManagerpublic void deleteUser(String username)
UserDetailsManagerdeleteUser in interface UserDetailsManagerpublic void changePassword(String oldPassword, String newPassword) throws AuthenticationException
UserDetailsManagerchangePassword in interface UserDetailsManageroldPassword - current password (for re-authentication if required)newPassword - the password to change toAuthenticationExceptionprotected Authentication createNewAuthentication(Authentication currentAuth, String newPassword)
public boolean userExists(String username)
UserDetailsManageruserExists in interface UserDetailsManagerpublic List<String> findAllGroups()
GroupManagerfindAllGroups in interface GroupManagerpublic List<String> findUsersInGroup(String groupName)
GroupManagerfindUsersInGroup in interface GroupManagergroupName - the group whose members are requiredpublic void createGroup(String groupName, List<GrantedAuthority> authorities)
GroupManagercreateGroup in interface GroupManagergroupName - the name for the new groupauthorities - the authorities which are to be allocated to this group.public void deleteGroup(String groupName)
GroupManagerdeleteGroup in interface GroupManagergroupName - the group to remove.public void renameGroup(String oldName, String newName)
GroupManagerrenameGroup in interface GroupManagerpublic void addUserToGroup(String username, String groupName)
GroupManageraddUserToGroup in interface GroupManagerusername - the user to be given membership.groupName - the name of the group to which the user will be added.public void removeUserFromGroup(String username, String groupName)
GroupManagerremoveUserFromGroup in interface GroupManagerusername - the usergroupName - the group to remove them frompublic List<GrantedAuthority> findGroupAuthorities(String groupName)
GroupManagerfindGroupAuthorities in interface GroupManagerpublic void removeGroupAuthority(String groupName, GrantedAuthority authority)
GroupManagerremoveGroupAuthority in interface GroupManagerpublic void addGroupAuthority(String groupName, GrantedAuthority authority)
GroupManageraddGroupAuthority in interface GroupManagerpublic void setAuthenticationManager(AuthenticationManager authenticationManager)
public void setCreateUserSql(String createUserSql)
public void setDeleteUserSql(String deleteUserSql)
public void setUpdateUserSql(String updateUserSql)
public void setCreateAuthoritySql(String createAuthoritySql)
public void setDeleteUserAuthoritiesSql(String deleteUserAuthoritiesSql)
public void setUserExistsSql(String userExistsSql)
public void setChangePasswordSql(String changePasswordSql)
public void setFindAllGroupsSql(String findAllGroupsSql)
public void setFindUsersInGroupSql(String findUsersInGroupSql)
public void setInsertGroupSql(String insertGroupSql)
public void setFindGroupIdSql(String findGroupIdSql)
public void setInsertGroupAuthoritySql(String insertGroupAuthoritySql)
public void setDeleteGroupSql(String deleteGroupSql)
public void setDeleteGroupAuthoritiesSql(String deleteGroupAuthoritiesSql)
public void setDeleteGroupMembersSql(String deleteGroupMembersSql)
public void setRenameGroupSql(String renameGroupSql)
public void setInsertGroupMemberSql(String insertGroupMemberSql)
public void setDeleteGroupMemberSql(String deleteGroupMemberSql)
public void setGroupAuthoritiesSql(String groupAuthoritiesSql)
public void setDeleteGroupAuthoritySql(String deleteGroupAuthoritySql)
public void setUserCache(UserCache userCache)
userCache - the cache used by the AuthenticationManager.