You could extend JdbcDaoImpl from Spring Security by overiding the createUserDetails API to achieve what you really intended to achieve. I have a use case where I store encrypted password in the database. I am using Jasypt instead of MD5. See the example below. I decrypt the encrypted user's password before the user object is created and sent to the UI layer. I am also using password digest username token in the soap header.
Code:
/**
* EisUsersJdbcDaoImpl.java : This implementation overrides some behavior of Spring Security's {@link JdbcDaoImpl}
* which retrieves the user details (username, password, enabled flag, and authorities) from a database
* using JDBC queries.
* @author Vigil Bose
*/
public class EisUsersJdbcDaoImpl extends JdbcDaoImpl {
@Autowired
@Qualifier("strongEncryptor")
private PBEStringEncryptor strongEncryptor;
/**
* The API createUserDetails() is overridden to apply decryption algorithm to the password before creating the final
* UserDetailsObject returned from <tt>loadUserByUsername</tt>.
*
* @param username the name originally passed to loadUserByUsername
* @param userFromUserQuery the object returned from the execution of the
* @param combinedAuthorities the combined array of authorities from all the authority loading queries.
* @return the final UserDetails which should be used in the system.
*/
@Override
public UserDetails createUserDetails(String username, UserDetails userFromUserQuery,
GrantedAuthority[] combinedAuthorities) {
String returnUsername = userFromUserQuery.getUsername();
if (!isUsernameBasedPrimaryKey()) {
returnUsername = username;
}
//Decrypt the encrypted password
String decryptedPassword = this.strongEncryptor.decrypt(userFromUserQuery.getPassword());
return new User(returnUsername, decryptedPassword, userFromUserQuery.isEnabled(),
true, true, true, combinedAuthorities);
}
}