public class

JdbcUserDetailsManager

extends JdbcDaoImpl
implements GroupManager UserDetailsManager
java.lang.Object
   ↳ org.springframework.dao.support.DaoSupport
     ↳ org.springframework.jdbc.core.support.JdbcDaoSupport
       ↳ org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
         ↳ org.springframework.security.provisioning.JdbcUserDetailsManager

Class Overview

Jdbc user management service, based on the same table structure as its parent class, JdbcDaoImpl.

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.

Summary

Constants
String DEF_CHANGE_PASSWORD_SQL
String DEF_CREATE_USER_SQL
String DEF_DELETE_GROUP_AUTHORITIES_SQL
String DEF_DELETE_GROUP_AUTHORITY_SQL
String DEF_DELETE_GROUP_MEMBERS_SQL
String DEF_DELETE_GROUP_MEMBER_SQL
String DEF_DELETE_GROUP_SQL
String DEF_DELETE_USER_AUTHORITIES_SQL
String DEF_DELETE_USER_SQL
String DEF_FIND_GROUPS_SQL
String DEF_FIND_GROUP_ID_SQL
String DEF_FIND_USERS_IN_GROUP_SQL
String DEF_GROUP_AUTHORITIES_QUERY_SQL
String DEF_INSERT_AUTHORITY_SQL
String DEF_INSERT_GROUP_AUTHORITY_SQL
String DEF_INSERT_GROUP_MEMBER_SQL
String DEF_INSERT_GROUP_SQL
String DEF_RENAME_GROUP_SQL
String DEF_UPDATE_USER_SQL
String DEF_USER_EXISTS_SQL
[Expand]
Inherited Constants
From class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
Fields
protected final Log logger
[Expand]
Inherited Fields
From class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
From class org.springframework.dao.support.DaoSupport
Public Constructors
JdbcUserDetailsManager()
Public Methods
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.
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
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.
Protected Methods
Authentication createNewAuthentication(Authentication currentAuth, String newPassword)
void initDao()
[Expand]
Inherited Methods
From class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
From class org.springframework.jdbc.core.support.JdbcDaoSupport
From class org.springframework.dao.support.DaoSupport
From class java.lang.Object
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.security.core.userdetails.UserDetailsService
From interface org.springframework.security.provisioning.GroupManager
From interface org.springframework.security.provisioning.UserDetailsManager

Constants

public static final String DEF_CHANGE_PASSWORD_SQL

Constant Value: "update users set password = ? where username = ?"

public static final String DEF_CREATE_USER_SQL

Constant Value: "insert into users (username, password, enabled) values (?,?,?)"

public static final String DEF_DELETE_GROUP_AUTHORITIES_SQL

Constant Value: "delete from group_authorities where group_id = ?"

public static final String DEF_DELETE_GROUP_AUTHORITY_SQL

Constant Value: "delete from group_authorities where group_id = ? and authority = ?"

public static final String DEF_DELETE_GROUP_MEMBERS_SQL

Constant Value: "delete from group_members where group_id = ?"

public static final String DEF_DELETE_GROUP_MEMBER_SQL

Constant Value: "delete from group_members where group_id = ? and username = ?"

public static final String DEF_DELETE_GROUP_SQL

Constant Value: "delete from groups where id = ?"

public static final String DEF_DELETE_USER_AUTHORITIES_SQL

Constant Value: "delete from authorities where username = ?"

public static final String DEF_DELETE_USER_SQL

Constant Value: "delete from users where username = ?"

public static final String DEF_FIND_GROUPS_SQL

Constant Value: "select group_name from groups"

public static final String DEF_FIND_GROUP_ID_SQL

Constant Value: "select id from groups where group_name = ?"

public static final String DEF_FIND_USERS_IN_GROUP_SQL

Constant Value: "select username from group_members gm, groups g where gm.group_id = g.id and g.group_name = ?"

public static final String DEF_GROUP_AUTHORITIES_QUERY_SQL

Constant Value: "select g.id, g.group_name, ga.authority from groups g, group_authorities ga where g.group_name = ? and g.id = ga.group_id "

public static final String DEF_INSERT_AUTHORITY_SQL

Constant Value: "insert into authorities (username, authority) values (?,?)"

public static final String DEF_INSERT_GROUP_AUTHORITY_SQL

Constant Value: "insert into group_authorities (group_id, authority) values (?,?)"

public static final String DEF_INSERT_GROUP_MEMBER_SQL

Constant Value: "insert into group_members (group_id, username) values (?,?)"

public static final String DEF_INSERT_GROUP_SQL

Constant Value: "insert into groups (group_name) values (?)"

public static final String DEF_RENAME_GROUP_SQL

Constant Value: "update groups set group_name = ? where group_name = ?"

public static final String DEF_UPDATE_USER_SQL

Constant Value: "update users set password = ?, enabled = ? where username = ?"

public static final String DEF_USER_EXISTS_SQL

Constant Value: "select username from users where username = ?"

Fields

protected final Log logger

Public Constructors

public JdbcUserDetailsManager ()

Public Methods

public void addGroupAuthority (String groupName, GrantedAuthority authority)

Assigns a new authority to a group.

public void addUserToGroup (String username, String groupName)

Makes a user a member of a particular group.

Parameters
username the user to be given membership.
groupName the name of the group to which the user will be added.

public void changePassword (String oldPassword, String newPassword)

Modify the current user's password. This should change the user's password in the persistent user repository (datbase, LDAP etc).

Parameters
oldPassword current password (for re-authentication if required)
newPassword the password to change to

public void createGroup (String groupName, List<GrantedAuthority> authorities)

Creates a new group with the specified list of authorities.

Parameters
groupName the name for the new group
authorities the authorities which are to be allocated to this group.

public void createUser (UserDetails user)

Create a new user with the supplied details.

public void deleteGroup (String groupName)

Removes a group, including all members and authorities.

Parameters
groupName the group to remove.

public void deleteUser (String username)

Remove the user with the given login name from the system.

public List<String> findAllGroups ()

Returns the names of all groups that this group manager controls.

public List<GrantedAuthority> findGroupAuthorities (String groupName)

Obtains the list of authorities which are assigned to a group.

public List<String> findUsersInGroup (String groupName)

Locates the users who are members of a group

Parameters
groupName the group whose members are required
Returns
  • the usernames of the group members

public void removeGroupAuthority (String groupName, GrantedAuthority authority)

Deletes an authority from those assigned to a group

public void removeUserFromGroup (String username, String groupName)

Deletes a user's membership of a group.

Parameters
username the user
groupName the group to remove them from

public void renameGroup (String oldName, String newName)

Changes the name of a group without altering the assigned authorities or members.

public void setAuthenticationManager (AuthenticationManager authenticationManager)

public void setChangePasswordSql (String changePasswordSql)

public void setCreateAuthoritySql (String createAuthoritySql)

public void setCreateUserSql (String createUserSql)

public void setDeleteGroupAuthoritiesSql (String deleteGroupAuthoritiesSql)

public void setDeleteGroupAuthoritySql (String deleteGroupAuthoritySql)

public void setDeleteGroupMemberSql (String deleteGroupMemberSql)

public void setDeleteGroupMembersSql (String deleteGroupMembersSql)

public void setDeleteGroupSql (String deleteGroupSql)

public void setDeleteUserAuthoritiesSql (String deleteUserAuthoritiesSql)

public void setDeleteUserSql (String deleteUserSql)

public void setFindAllGroupsSql (String findAllGroupsSql)

public void setFindGroupIdSql (String findGroupIdSql)

public void setFindUsersInGroupSql (String findUsersInGroupSql)

public void setGroupAuthoritiesSql (String groupAuthoritiesSql)

public void setInsertGroupAuthoritySql (String insertGroupAuthoritySql)

public void setInsertGroupMemberSql (String insertGroupMemberSql)

public void setInsertGroupSql (String insertGroupSql)

public void setRenameGroupSql (String renameGroupSql)

public void setUpdateUserSql (String updateUserSql)

public void setUserCache (UserCache userCache)

Optionally sets the UserCache if one is in use in the application. This allows the user to be removed from the cache after updates have taken place to avoid stale data.

Parameters
userCache the cache used by the AuthenticationManager.

public void setUserExistsSql (String userExistsSql)

public void updateUser (UserDetails user)

Update the specified user.

public boolean userExists (String username)

Check if a user with the supplied login name exists in the system.

Protected Methods

protected Authentication createNewAuthentication (Authentication currentAuth, String newPassword)

protected void initDao ()

Throws
ApplicationContextException