CustomerServiceImpl extends BaseGenericServiceImpl<Customer> implements CustomerService { @Override public boolean isPasswordValid(final String email, final Shop shop, final String password) { try { if (StringUtils.isBlank(password)) { return false; } final String hash = passwordHashHelper.getHash(password); final int validLoginsFound = getGenericDao().findCountByNamedQuery("PASS.CHECK", email.toLowerCase(), shop.getShopId(), hash, Boolean.FALSE); if (validLoginsFound == 1) { return true; } else if (validLoginsFound > 1) { LOG.warn(Markers.alert(), "Customer {} assigned to multiple shops when checking {} ... password will be marked as invalid", email, shop.getCode()); } return false; } catch (Exception exp) { LOG.error(exp.getMessage(), exp); return false; } } CustomerServiceImpl(final GenericDAO<Customer, Long> genericDao,
                               final HashHelper passwordHashHelper,
                               final GenericDAO<Object, Long> customerShopDao,
                               final AttributeService attributeService,
                               final ShopService shopService,
                               final CustomerNameFormatter customerNameFormatter); @Override Customer getCustomerByEmail(final String email, Shop shop); @Override Customer findCustomerByEmail(final String email, final Shop shop, final boolean includeDisabled); @Override Customer getCustomerByToken(final String token); @Override Customer getCustomerByPublicKey(final String publicKey, final String lastName); @Override List<Shop> getCustomerShops(final Customer customer); @Override String formatNameFor(final Customer customer, final Shop shop); @Override List<Customer> findCustomers(final int start,
                                        final int offset,
                                        final String sort,
                                        final boolean sortDescending,
                                        final Map<String, List> filter); @Override int findCustomerCount(final Map<String, List> filter); @Override boolean isCustomerExists(final String email, final Shop shop, final boolean includeDisabled); @Override boolean isPasswordValid(final String email, final Shop shop, final String password); @Override List<AttrValueCustomer> getRankedAttributeValues(final Customer customer); @Override void resetPassword(final Customer customer, final Shop shop, final String authToken); @Override void updatePassword(final Customer customer, final Shop shop, final String newPassword); @Override Customer create(final Customer customer, final Shop shop); @Override Customer updateActivate(final Customer customer, final Shop shop, final boolean soft); @Override Customer updateDeactivate(final Customer customer, final Shop shop, final boolean soft); @Override Customer create(final Customer instance); @Override Customer update(final String email, final String shopCode); @Override Customer update(final Customer instance); @Override void delete(final Customer instance);  }
@Test public void testIsPasswordValid() throws Exception { final Shop shop = shopService.getById(10L); final Shop subShop = shopService.getById(1010L); Customer customer = getCustomer(getTestName() + "_1"); customer.setEmail("user1@passvalid.com"); assertFalse(customerService.isCustomerExists(customer.getEmail(), shop, true)); assertFalse(customerService.isPasswordValid(customer.getEmail(), shop, "rawpassword")); customerService.create(customer, shop); assertTrue(customerService.isCustomerExists(customer.getEmail(), shop, true)); assertTrue(customerService.isPasswordValid(customer.getEmail(), shop, "rawpassword")); getTx().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus transactionStatus) { final Customer cust = customerService.findById(customer.getId()); final CustomerShop customerShop = customerService.getGenericDao().getEntityFactory().getByIface(CustomerShop.class); customerShop.setShop(subShop); customerShop.setCustomer(cust); customerShop.setDisabled(false); cust.getShops().add(customerShop); customerService.update(cust); } }); assertTrue(customerService.isCustomerExists(customer.getEmail(), shop, true)); assertFalse("Cannot determine shop with multiple assignments", customerService.isPasswordValid(customer.getEmail(), shop, "rawpassword")); }