@Test public void testPasswordHash() { given(passwordEncoder.encode(PASSWORD)).willReturn(HASHED_PASSWORD); SignupForm form = populateForm(NAME, PASSWORD); Errors noErrors = new DirectFieldBindingResult(form, "form"); controller.signup(form, noErrors); verify(userDetailsManager).createUser(argThat(hasProperty("password", equalTo(HASHED_PASSWORD)))); }
@RequestMapping(value = CONTROLLER_URL, method = RequestMethod.POST) public String signup(@Valid @ModelAttribute SignupForm signupForm, Errors errors) { if (errors.hasErrors()) { log.warn("Oh no! Signup failed as there are validation errors."); return null; } String hashedPassword = passwordEncoder.encode(signupForm.getPassword()); UserDetails userDetails = new User(signupForm.getName(), hashedPassword, ENABLED); userDetailsManager.createUser(userDetails); log.info("Success! Created new user " + userDetails.getUsername()); return VIEW_SUCCESS; }
SignupController { @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.POST) public String signup(@Valid @ModelAttribute SignupForm signupForm, Errors errors) { if (errors.hasErrors()) { log.warn("Oh no! Signup failed as there are validation errors."); return null; } String hashedPassword = passwordEncoder.encode(signupForm.getPassword()); UserDetails userDetails = new User(signupForm.getName(), hashedPassword, ENABLED); userDetailsManager.createUser(userDetails); log.info("Success! Created new user " + userDetails.getUsername()); return VIEW_SUCCESS; } }
SignupController { @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.POST) public String signup(@Valid @ModelAttribute SignupForm signupForm, Errors errors) { if (errors.hasErrors()) { log.warn("Oh no! Signup failed as there are validation errors."); return null; } String hashedPassword = passwordEncoder.encode(signupForm.getPassword()); UserDetails userDetails = new User(signupForm.getName(), hashedPassword, ENABLED); userDetailsManager.createUser(userDetails); log.info("Success! Created new user " + userDetails.getUsername()); return VIEW_SUCCESS; }  }
SignupController { @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.POST) public String signup(@Valid @ModelAttribute SignupForm signupForm, Errors errors) { if (errors.hasErrors()) { log.warn("Oh no! Signup failed as there are validation errors."); return null; } String hashedPassword = passwordEncoder.encode(signupForm.getPassword()); UserDetails userDetails = new User(signupForm.getName(), hashedPassword, ENABLED); userDetailsManager.createUser(userDetails); log.info("Success! Created new user " + userDetails.getUsername()); return VIEW_SUCCESS; }  @RequestMapping(value = CONTROLLER_URL) SignupForm displayPage(); @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.POST) String signup(@Valid @ModelAttribute SignupForm signupForm, Errors errors); }
SignupController { @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.POST) public String signup(@Valid @ModelAttribute SignupForm signupForm, Errors errors) { if (errors.hasErrors()) { log.warn("Oh no! Signup failed as there are validation errors."); return null; } String hashedPassword = passwordEncoder.encode(signupForm.getPassword()); UserDetails userDetails = new User(signupForm.getName(), hashedPassword, ENABLED); userDetailsManager.createUser(userDetails); log.info("Success! Created new user " + userDetails.getUsername()); return VIEW_SUCCESS; }  @RequestMapping(value = CONTROLLER_URL) SignupForm displayPage(); @RequestMapping(value = CONTROLLER_URL, method = RequestMethod.POST) String signup(@Valid @ModelAttribute SignupForm signupForm, Errors errors); static final String CONTROLLER_URL; static final String VIEW_SUCCESS; }