@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { Customer customer = customerService.readCustomerByUsername(username, false); if (customer == null) { throw new UsernameNotFoundException("The customer was not found"); } boolean isActive = !customer.isDeactivated(); if (Status.class.isAssignableFrom(customer.getClass())) { isActive = isActive && ((Status) customer).isActive(); } List<GrantedAuthority> grantedAuthorities = createGrantedAuthorities(roleService.findCustomerRolesByCustomerId(customer.getId())); return new CustomerUserDetails(customer.getId(), username, customer.getPassword(), isActive, true, !customer.isPasswordChangeRequired(), true, grantedAuthorities); }
@Test(groups = { "changeCustomerPassword" }, dependsOnGroups = { "readCustomer" }) @Transactional @Commit public void changeCustomerPasswords() { for (String userName : userNames) { Customer customer = customerService.readCustomerByUsername(userName); customer.setPassword(customer.getPassword() + "-Changed"); customerService.saveCustomer(customer); } }
public void validate(Customer customer, String password, String passwordConfirm, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath(); if (errors.hasErrors()){ if (!passwordConfirm.equals(password)) { errors.rejectValue("passwordConfirm", "invalid"); } if (!customer.getFirstName().matches(getValidNameRegex())) { errors.rejectValue("firstName", "firstName.invalid", null, null); } if (!customer.getLastName().matches(getValidNameRegex())) { errors.rejectValue("lastName", "lastName.invalid", null, null); } if (!customer.getPassword().matches(getValidPasswordRegex())) { errors.rejectValue("password", "password.invalid", null, null); } if (!password.equals(passwordConfirm)) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(customer.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid", null, null); } } }
public void validate(PasswordChange passwordChange, Errors errors) { String currentPassword = passwordChange.getCurrentPassword(); String password = passwordChange.getNewPassword(); String passwordConfirm = passwordChange.getNewPasswordConfirm(); if (enableCurrentPasswordCheck) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "currentPassword", "currentPassword.required"); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "newPassword", "newPassword.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "newPasswordConfirm", "newPasswordConfirm.required"); if (!errors.hasErrors()) { //validate current password if (enableCurrentPasswordCheck && !customerService.isPasswordValid(currentPassword, CustomerState.getCustomer().getPassword(), CustomerState.getCustomer())) { errors.rejectValue("currentPassword", "currentPassword.invalid"); } //password and confirm password fields must be equal if (!passwordConfirm.equals(password)) { errors.rejectValue("newPasswordConfirm", "newPasswordConfirm.invalid"); } //restrict password characteristics if (!password.matches(getValidPasswordRegex())) { errors.rejectValue("newPassword", "newPassword.invalid"); } } }
@Test(groups = "createCustomers", dependsOnGroups="createCustomerIdGeneration", dataProvider = "setupCustomers", dataProviderClass = CustomerDataProvider.class) @Rollback(false) public void createCustomer(Customer customerInfo) { Customer customer = customerService.createCustomerFromId(null); customer.setPassword(customerInfo.getPassword()); customer.setUsername(customerInfo.getUsername()); Long customerId = customer.getId(); assert customerId != null; customer = customerService.saveCustomer(customer); assert customer.getId() == customerId; userIds.add(customer.getId()); userNames.add(customer.getUsername()); }
@Override public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective); Object primaryKey = helper.getPrimaryKey(entity, adminProperties); Customer adminInstance = (Customer) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey); Entity errorEntity = validateUniqueUsername(entity, adminInstance, false); if (errorEntity != null) { return errorEntity; } String passwordBefore = adminInstance.getPassword(); adminInstance.setPassword(null); adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); adminInstance.setPassword(passwordBefore); if (useEmailForLogin) { adminInstance.setUsername(adminInstance.getEmailAddress()); } adminInstance = customerService.saveCustomer(adminInstance); Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null); return adminEntity; } catch (Exception e) { throw new ServiceException("Unable to update entity for " + entity.getType()[0], e); } }
for (Customer ci : custList){ //... String text = ci.getRealName() + ";" + ci.getUserName() + ";" + ci.getPassword() + ";" + ci.getContact() + ";" + ci.getcardType() + ";" + ci.getcardNo(); try { File fileCI = new File("CI.txt"); FileWriter fileWriter = new FileWriter(fileCI); //... }
&& inputPass.equals ( ci.getPassword () ) ) + ci.getPassword () + ";" + ci.getContact () + ";" + ci.getcardType () + ";" + ci.getcardNo ();
public UserDetails createCustomerUserDetails(Customer customer) { List<GrantedAuthority> grantedAuthorities = createGrantedAuthorities(roleService.findCustomerRolesByCustomerId(customer.getId())); CustomerUserDetails userDetails = new CustomerUserDetails(customer.getId(), customer.getUsername(), customer.getPassword(), !customer.isDeactivated(), true, !customer.isPasswordChangeRequired(), true, grantedAuthorities); userDetails.eraseCredentials(); return userDetails; }