Package org.springframework.security.provisioning

# Class InMemoryUserDetailsManager

java.lang.Object
org.springframework.security.provisioning.InMemoryUserDetailsManager

All Implemented Interfaces:
  `UserDetailsPasswordService`, `UserDetailsService`, `UserDetailsManager`

public class InMemoryUserDetailsManager extends Object implements UserDetailsManager, UserDetailsPasswordService
Non-persistent implementation of `UserDetailsManager` which is backed by an in-memory map.

Mainly intended for testing and demonstration purposes, where a full blown persistent system isn't required.

Since:
  3.1

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final org.apache.commons.logging.Log`
`logger`

## Constructor Summary

Constructors
Constructor
Description
`InMemoryUserDetailsManager()`
`InMemoryUserDetailsManager(Collection<UserDetails> users)`
`InMemoryUserDetailsManager(Properties users)`
`InMemoryUserDetailsManager(UserDetails... users)`

## Method Summary

Modifier and Type
Method
Description
`void`
`changePassword(String oldPassword, String newPassword)`
Modify the current user's password.
`void`
`createUser(UserDetails user)`
Create a new user with the supplied details.
`void`
`deleteUser(String username)`
Remove the user with the given login name from the system.
`UserDetails`
`loadUserByUsername(String username)`
Locates the user based on the username.
`void`
`setAuthenticationManager(AuthenticationManager authenticationManager)`
`void`
`setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)`
Sets the `SecurityContextHolderStrategy` to use.
`UserDetails`
`updatePassword(UserDetails user, String newPassword)`
Modify the specified user's password.
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### logger

protected final org.apache.commons.logging.Log logger

## Constructor Details

### InMemoryUserDetailsManager

public InMemoryUserDetailsManager()

### InMemoryUserDetailsManager

public InMemoryUserDetailsManager(Collection<UserDetails> users)

### InMemoryUserDetailsManager

public InMemoryUserDetailsManager(UserDetails... users)

### InMemoryUserDetailsManager

public InMemoryUserDetailsManager(Properties users)

## Method Details

### createUser

public void createUser(UserDetails user)
Description copied from interface: `UserDetailsManager`
Create a new user with the supplied details.

Specified by:
  `createUser` in interface `UserDetailsManager`

### deleteUser

public void deleteUser(String username)
Description copied from interface: `UserDetailsManager`
Remove the user with the given login name from the system.

Specified by:
  `deleteUser` in interface `UserDetailsManager`

### updateUser

public void updateUser(UserDetails user)
Description copied from interface: `UserDetailsManager`
Update the specified user.

Specified by:
  `updateUser` in interface `UserDetailsManager`

### userExists

public boolean userExists(String username)
Description copied from interface: `UserDetailsManager`
Check if a user with the supplied login name exists in the system.

Specified by:
  `userExists` in interface `UserDetailsManager`

### changePassword

public void changePassword(String oldPassword, String newPassword)
Description copied from interface: `UserDetailsManager`
Modify the current user's password. This should change the user's password in the persistent user repository (database, LDAP etc).

Specified by:
  `changePassword` in interface `UserDetailsManager`
Parameters:
  `oldPassword` - current password (for re-authentication if required)
  `newPassword` - the password to change to

### updatePassword

public UserDetails updatePassword(UserDetails user, String newPassword)
Description copied from interface: `UserDetailsPasswordService`
Modify the specified user's password. This should change the user's password in the persistent user repository (database, LDAP etc).

Specified by:
  `updatePassword` in interface `UserDetailsPasswordService`
Parameters:
  `user` - the user to modify the password for
  `newPassword` - the password to change to, encoded by the configured `PasswordEncoder`
Returns:
  the updated UserDetails with the new password

### loadUserByUsername

public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
Description copied from interface: `UserDetailsService`
Locates the user based on the username. In the actual implementation, the search may possibly be case sensitive, or case insensitive depending on how the implementation instance is configured. In this case, the `UserDetails` object that comes back may have a username that is of a different case than what was actually requested..

Specified by:
  `loadUserByUsername` in interface `UserDetailsService`
Parameters:
  `username` - the username identifying the user whose data is required.
Returns:
  a fully populated user record (never `null`)
Throws:
  `UsernameNotFoundException` - if the user could not be found or the user has no GrantedAuthority

### setSecurityContextHolderStrategy

public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
Sets the `SecurityContextHolderStrategy` to use. The default action is to use the `SecurityContextHolderStrategy` stored in `SecurityContextHolder`.

Since:
  5.8

### setAuthenticationManager

public void setAuthenticationManager(AuthenticationManager authenticationManager)