hi to all.
i working on a simple spring security example and now exercising on salting password on a db.
after changing my authentication manager to this style :
and write a simple class to change stored password in my persons tables like as this :Code:<authentication-manager alias="mySimpleAuthenticationManager"> <authentication-provider ref="dbAuthenticationProvider"> <jdbc-user-service data-source-ref="dataSource"/> <password-encoder ref="passwordEncoder"> <salt-source ref="saltSource"/> </password-encoder> </authentication-provider> </authentication-manager> <beans:bean class="org.springframework.security.authentication.encoding.ShaPasswordEncoder" id="passwordEncoder"/> <beans:bean class="org.springframework.security.authentication.dao.ReflectionSaltSource" id="saltSource"> <beans:property name="userPropertyToUse" value="username"/> </beans:bean>
my orginal password changed in database to this :Code:public class DatabasePasswordSecurerBean extends JdbcDaoSupport { @Autowired private PasswordEncoder passwordEncoder; @Autowired private SaltSource saltSource; @Autowired private UserDetailsService userDetailsService; public void secureDatabase() { getJdbcTemplate().query("select username, password from persons", new RowCallbackHandler(){ @Override public void processRow(ResultSet rs) throws SQLException { String username = rs.getString(1); String password = rs.getString(2); UserDetails user = userDetailsService.loadUserByUsername(username); String encodedPassword = passwordEncoder.encodePassword(password, saltSource.getSalt(user)); getJdbcTemplate().update("update persons set password = ? where username = ?", encodedPassword, username); logger.debug("Updating password for username: " + username + " to: " + encodedPassword); } }); } public PasswordEncoder getPasswordEncoder() { return passwordEncoder; } public void setPasswordEncoder(PasswordEncoder passwordEncoder) { this.passwordEncoder = passwordEncoder; } public SaltSource getSaltSource() { return saltSource; } public void setSaltSource(SaltSource saltSource) { this.saltSource = saltSource; } public UserDetailsService getUserDetailsService() { return userDetailsService; } public void setUserDetailsService(UserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } }
"354e72c1f52f683be6e930a757faed58c3b07386"
so i understand that my class changed the password in db.
problem is where when i want to login to system with my orginal password i cant to login to system and it seems password encoder not encode my orginal password to compare with encoded password that stored in db.
because when i enter my username and "354e72c1f52f683be6e930a757faed58c3b07386" as password value i can login to systeem?!


Reply With Quote