// global authentication method. depends on the ClientType public CouponClientFacade login(String name, String password, ClientType clientType) { Utils.logMessage(this, Severity.DEBUG, clientType + " login invoked with pass = "******"db hash = " + _adminHash); Utils.logMessage(this, Severity.DEBUG, "calculated hash = " + md5HashOfPassword); if (md5HashOfPassword.equals(_adminHash)) { Utils.logMessage(this, Severity.DEBUG, "admin authenticated by md5."); // admin auth success, init AdminFacade and passing the DAO's AdminFacade adminFacade = new AdminFacade(customerDao, companyDao, couponDao); return adminFacade; } Utils.logMessage(this, Severity.ERROR, "admin authentication failed. md5 not match !"); } // login of Company if (clientType == ClientType.COMPANY) { // success auth will return the customer ID Long companyId = companyDao.login(name, password); if (companyId != null && companyId != 0) { // construct a customer with those params Company company = new Company(); company.setId(companyId); company.setCompName(name); company.setPassword(password); // create a CustomerFacade, referring to this company CompanyFacade companyFacade = new CompanyFacade(company); companyFacade.setCompanyDao(companyDao); companyFacade.setCouponDao(couponDao); return companyFacade; } } // login of Customer if (clientType == ClientType.CUSTOMER) { // success auth will return the customer ID Long customerId = customerDao.login(name, password); if (customerId != null && customerId != 0) { // construct a customer with those params Customer customer = new Customer(); customer.setId(customerId); customer.setCustName(name); customer.setPassword(password); // create a CustomerFacade CustomerFacade customerFacade = new CustomerFacade(); // customerFacade need to ref that specific customer ( 1 per client ) customerFacade.setCustomer(customer); // and ref the DAOs ( customer + coupons ) customerFacade.setCustomerDao(customerDao); customerFacade.setCouponDao(couponDao); return customerFacade; } } return null; }