@Test(expected = AcmUserActionFailedException.class) public void resetUserPasswordLdapOperationFailed() throws AcmLdapActionFailedException, AcmUserActionFailedException { String password = "password"; PasswordResetToken passwordResetToken = new PasswordResetToken(); String token = passwordResetToken.getToken(); mockUser.setPasswordResetToken(passwordResetToken); expect(mockUserDao.findByPasswordResetToken(token)).andReturn(mockUser); expect(mockUserDao.save(mockUser)).andReturn(mockUser); LdapTemplate mockTemplate = createMock(LdapTemplate.class); expect(mockLdapDao.buildLdapTemplate(mockLdapAuthenticateConfig)).andReturn(mockTemplate); mockLdapUserDao.changeUserPasswordWithAdministrator(mockUser.getDistinguishedName(), password, mockTemplate, mockLdapAuthenticateConfig); expectLastCall().andThrow(new AcmLdapActionFailedException("LDAP Action Failed Exception")); replayAll(); unit.resetUserPassword(token, password); verifyAll(); assertFalse(mockUser.getPasswordResetToken().getExpiryDate().isAfter(LocalDateTime.now())); }
public void resetUserPassword(String token, String password) throws AcmUserActionFailedException { AcmUser user = userDao.findByPasswordResetToken(token); if (user == null) { throw new AcmUserActionFailedException("reset password", "USER", null, "User not found!", null); } LdapTemplate ldapTemplate = ldapDao.buildLdapTemplate(ldapAuthenticateConfig); try { log.debug("Changing password for user: [{}]", user.getUserId()); ldapUserDao.changeUserPasswordWithAdministrator(user.getDistinguishedName(), password, ldapTemplate, ldapAuthenticateConfig); } catch (AcmLdapActionFailedException e) { throw new AcmUserActionFailedException("reset password", "USER", null, "Change password action failed!", e); } try { savePasswordExpirationDate(user, ldapTemplate); invalidateToken(user); } catch (AuthenticationException e) { log.warn("Password expiration date was not set for user [{}]", user.getUserId(), e); } }
LdapAuthenticateService { public void resetUserPassword(String token, String password) throws AcmUserActionFailedException { AcmUser user = userDao.findByPasswordResetToken(token); if (user == null) { throw new AcmUserActionFailedException("reset password", "USER", null, "User not found!", null); } LdapTemplate ldapTemplate = ldapDao.buildLdapTemplate(ldapAuthenticateConfig); try { log.debug("Changing password for user: [{}]", user.getUserId()); ldapUserDao.changeUserPasswordWithAdministrator(user.getDistinguishedName(), password, ldapTemplate, ldapAuthenticateConfig); } catch (AcmLdapActionFailedException e) { throw new AcmUserActionFailedException("reset password", "USER", null, "Change password action failed!", e); } try { savePasswordExpirationDate(user, ldapTemplate); invalidateToken(user); } catch (AuthenticationException e) { log.warn("Password expiration date was not set for user [{}]", user.getUserId(), e); } } }
LdapAuthenticateService { public void resetUserPassword(String token, String password) throws AcmUserActionFailedException { AcmUser user = userDao.findByPasswordResetToken(token); if (user == null) { throw new AcmUserActionFailedException("reset password", "USER", null, "User not found!", null); } LdapTemplate ldapTemplate = ldapDao.buildLdapTemplate(ldapAuthenticateConfig); try { log.debug("Changing password for user: [{}]", user.getUserId()); ldapUserDao.changeUserPasswordWithAdministrator(user.getDistinguishedName(), password, ldapTemplate, ldapAuthenticateConfig); } catch (AcmLdapActionFailedException e) { throw new AcmUserActionFailedException("reset password", "USER", null, "Change password action failed!", e); } try { savePasswordExpirationDate(user, ldapTemplate); invalidateToken(user); } catch (AuthenticationException e) { log.warn("Password expiration date was not set for user [{}]", user.getUserId(), e); } }  }
LdapAuthenticateService { public void resetUserPassword(String token, String password) throws AcmUserActionFailedException { AcmUser user = userDao.findByPasswordResetToken(token); if (user == null) { throw new AcmUserActionFailedException("reset password", "USER", null, "User not found!", null); } LdapTemplate ldapTemplate = ldapDao.buildLdapTemplate(ldapAuthenticateConfig); try { log.debug("Changing password for user: [{}]", user.getUserId()); ldapUserDao.changeUserPasswordWithAdministrator(user.getDistinguishedName(), password, ldapTemplate, ldapAuthenticateConfig); } catch (AcmLdapActionFailedException e) { throw new AcmUserActionFailedException("reset password", "USER", null, "Change password action failed!", e); } try { savePasswordExpirationDate(user, ldapTemplate); invalidateToken(user); } catch (AuthenticationException e) { log.warn("Password expiration date was not set for user [{}]", user.getUserId(), e); } }  Boolean authenticate(String userName, String password); void changeUserPassword(String userName, String currentPassword, String newPassword); void resetUserPassword(String token, String password); SpringLdapDao getLdapDao(); void setLdapDao(SpringLdapDao ldapDao); AcmLdapAuthenticateConfig getLdapAuthenticateConfig(); void setLdapAuthenticateConfig(AcmLdapAuthenticateConfig ldapAuthenticateConfig); UserDao getUserDao(); void setUserDao(UserDao userDao); SpringLdapUserDao getLdapUserDao(); void setLdapUserDao(SpringLdapUserDao ldapUserDao); AcmLdapSyncConfig getLdapSyncConfig(); void setLdapSyncConfig(AcmLdapSyncConfig ldapSyncConfig); }
LdapAuthenticateService { public void resetUserPassword(String token, String password) throws AcmUserActionFailedException { AcmUser user = userDao.findByPasswordResetToken(token); if (user == null) { throw new AcmUserActionFailedException("reset password", "USER", null, "User not found!", null); } LdapTemplate ldapTemplate = ldapDao.buildLdapTemplate(ldapAuthenticateConfig); try { log.debug("Changing password for user: [{}]", user.getUserId()); ldapUserDao.changeUserPasswordWithAdministrator(user.getDistinguishedName(), password, ldapTemplate, ldapAuthenticateConfig); } catch (AcmLdapActionFailedException e) { throw new AcmUserActionFailedException("reset password", "USER", null, "Change password action failed!", e); } try { savePasswordExpirationDate(user, ldapTemplate); invalidateToken(user); } catch (AuthenticationException e) { log.warn("Password expiration date was not set for user [{}]", user.getUserId(), e); } }  Boolean authenticate(String userName, String password); void changeUserPassword(String userName, String currentPassword, String newPassword); void resetUserPassword(String token, String password); SpringLdapDao getLdapDao(); void setLdapDao(SpringLdapDao ldapDao); AcmLdapAuthenticateConfig getLdapAuthenticateConfig(); void setLdapAuthenticateConfig(AcmLdapAuthenticateConfig ldapAuthenticateConfig); UserDao getUserDao(); void setUserDao(UserDao userDao); SpringLdapUserDao getLdapUserDao(); void setLdapUserDao(SpringLdapUserDao ldapUserDao); AcmLdapSyncConfig getLdapSyncConfig(); void setLdapSyncConfig(AcmLdapSyncConfig ldapSyncConfig);  }