Created
June 5, 2014 17:45
-
-
Save scottcagno/de1810471fcb530fc396 to your computer and use it in GitHub Desktop.
Spring Security - Password Encode Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In SecurityConfig.java (config) | |
| ====================== | |
| ... | |
| auth.jdbcAuthentication() | |
| .dataSource(...) | |
| .passwordEncoder(passEncoder()) <--- ADD | |
| .usersByUsernameQuery(...) | |
| .authoritiesByUsernameQuery(...); | |
| ... | |
| @Bean | |
| private PasswordEncoder passEncoder() { <--- ADD | |
| return new BCryptPasswordEncoder(); | |
| } | |
| ... | |
| NOTE: The above is all you should really have to do. If you | |
| want some manual control over things, or test anything out | |
| you can always implement something like the following... | |
| In User.java (domain) | |
| ============ | |
| ... | |
| // modify setPassword(...) | |
| private void setPassword(String password) { | |
| PasswordEncoder encoder = new BCryptPasswordEncoder(); | |
| this.password = encoder.encode(password); | |
| } | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment