@Test void testChangePasswordAuthenticatedUser() { String username = "MyUsername"; String password = "MyPassword"; SecurityContext securityContext = mock(SecurityContext.class); Authentication authentication = new UsernamePasswordAuthenticationToken(username, "MyCurrentPassword"); when(securityContext.getAuthentication()).thenReturn(authentication); SecurityContextHolder.setContext(securityContext); User user = mock(User.class); when(userService.getUser(username)).thenReturn(user); passwordResetServiceImpl.changePasswordAuthenticatedUser(password); verify(user).setChangePassword(false); verify(userService).update(user); }
@Transactional @Override public void changePasswordAuthenticatedUser(String password) { String username = SecurityUtils.getCurrentUsername(); if (username == null) { throw new AuthenticationCredentialsNotFoundException("not authenticated"); } User user = getUser(username); user.setPassword(password); user.setChangePassword(false); RunAsSystemAspect.runAsSystem(() -> userService.update(user)); }
PasswordResetterImpl implements PasswordResetter { @Transactional @Override public void changePasswordAuthenticatedUser(String password) { String username = SecurityUtils.getCurrentUsername(); if (username == null) { throw new AuthenticationCredentialsNotFoundException("not authenticated"); } User user = getUser(username); user.setPassword(password); user.setChangePassword(false); RunAsSystemAspect.runAsSystem(() -> userService.update(user)); } }
PasswordResetterImpl implements PasswordResetter { @Transactional @Override public void changePasswordAuthenticatedUser(String password) { String username = SecurityUtils.getCurrentUsername(); if (username == null) { throw new AuthenticationCredentialsNotFoundException("not authenticated"); } User user = getUser(username); user.setPassword(password); user.setChangePassword(false); RunAsSystemAspect.runAsSystem(() -> userService.update(user)); } PasswordResetterImpl(
      PasswordResetTokenRepository passwordResetTokenRepository,
      UserService userService,
      MailSender mailSender,
      AppSettings appSettings); }
PasswordResetterImpl implements PasswordResetter { @Transactional @Override public void changePasswordAuthenticatedUser(String password) { String username = SecurityUtils.getCurrentUsername(); if (username == null) { throw new AuthenticationCredentialsNotFoundException("not authenticated"); } User user = getUser(username); user.setPassword(password); user.setChangePassword(false); RunAsSystemAspect.runAsSystem(() -> userService.update(user)); } PasswordResetterImpl(
      PasswordResetTokenRepository passwordResetTokenRepository,
      UserService userService,
      MailSender mailSender,
      AppSettings appSettings); @Transactional @RunAsSystem @Override void resetPassword(String emailAddress); @Transactional(readOnly = true) @RunAsSystem @Override void validatePasswordResetToken(String username, String token); @Transactional @RunAsSystem @Override void changePassword(String username, String token, String password); @Transactional @Override void changePasswordAuthenticatedUser(String password); }
PasswordResetterImpl implements PasswordResetter { @Transactional @Override public void changePasswordAuthenticatedUser(String password) { String username = SecurityUtils.getCurrentUsername(); if (username == null) { throw new AuthenticationCredentialsNotFoundException("not authenticated"); } User user = getUser(username); user.setPassword(password); user.setChangePassword(false); RunAsSystemAspect.runAsSystem(() -> userService.update(user)); } PasswordResetterImpl(
      PasswordResetTokenRepository passwordResetTokenRepository,
      UserService userService,
      MailSender mailSender,
      AppSettings appSettings); @Transactional @RunAsSystem @Override void resetPassword(String emailAddress); @Transactional(readOnly = true) @RunAsSystem @Override void validatePasswordResetToken(String username, String token); @Transactional @RunAsSystem @Override void changePassword(String username, String token, String password); @Transactional @Override void changePasswordAuthenticatedUser(String password);  }