// Path: server/src/main/java/com/cloudwise/sap/niping/common/vo/User.java
// @Data
// @Builder
// @AllArgsConstructor
// public class User {
// 	protected String userId;
// 	protected String accountId;
// 	protected String name;
// 	protected String loginName;
// 	private String password;
// 	private String passwordSalt;
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/service/AuthService.java
// @Slf4j
// @Service
// public class AuthService {
// 
//     @Inject
//     private AccessCredentialsDao accessCredentialsDao;
// 
//     @Inject
//     private UserDao userDao;
// 
//     public Optional<AccessCredentials> getCredentialsByToken(String credentials) {
//         AccessCredentials accessCredentials = null;
//         try {
//             accessCredentials = accessCredentialsDao.getCredentialsByToken(credentials);
//         } catch (DBIException e) {
//             log.error("user auth: get credentials by token {} database error: {}", credentials, ExceptionUtils.getMessage(e));
//         }
//         return Optional.ofNullable(accessCredentials);
//     }
// 
//     public Optional<User> validateUser(String loginName, String password) {
//         User user = null;
//         try {
//             user = userDao.getUser(loginName, UserEntity.Status.enable.getStatus());
//             if (null != user && user.getPassword().equals(HashStrategyUtil.computeHash(password, user.getPasswordSalt()))) {
//                 return Optional.of(user);
//             }
//         } catch (DBIException e) {
//             log.error("user auth: get user {} database error: {}", loginName, ExceptionUtils.getMessage(e));
//         } catch (Exception e) {
//             log.error("user auth: validate user {} computeHash error: {}", loginName, ExceptionUtils.getMessage(e));
//         }
//         return Optional.empty();
//     }
// 
//     public String getTokenByAccountId(String accountId) throws NiPingException {
//         String token = null;
//         try {
//             token = accessCredentialsDao.getTokenByAccountId(accountId);
//         } catch (DBIException e) {
//             log.error("user auth: get token by account id {} error: {}", accountId, ExceptionUtils.getMessage(e));
//             throw new NiPingException(DBError);
//         }
//         return token;
//     }
// }


import com.cloudwise.sap.niping.common.vo.User;
import com.cloudwise.sap.niping.service.AuthService;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.basic.BasicCredentials;
import javax.inject.Inject;
import java.util.Optional;
package com.cloudwise.sap.niping.auth;




public class SapBasicAuthenticator implements Authenticator<BasicCredentials, BasicAuthUser> {

    @Inject
// Path: server/src/main/java/com/cloudwise/sap/niping/common/vo/User.java
// @Data
// @Builder
// @AllArgsConstructor
// public class User {
// 	protected String userId;
// 	protected String accountId;
// 	protected String name;
// 	protected String loginName;
// 	private String password;
// 	private String passwordSalt;
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/service/AuthService.java
// @Slf4j
// @Service
// public class AuthService {
// 
//     @Inject
//     private AccessCredentialsDao accessCredentialsDao;
// 
//     @Inject
//     private UserDao userDao;
// 
//     public Optional<AccessCredentials> getCredentialsByToken(String credentials) {
//         AccessCredentials accessCredentials = null;
//         try {
//             accessCredentials = accessCredentialsDao.getCredentialsByToken(credentials);
//         } catch (DBIException e) {
//             log.error("user auth: get credentials by token {} database error: {}", credentials, ExceptionUtils.getMessage(e));
//         }
//         return Optional.ofNullable(accessCredentials);
//     }
// 
//     public Optional<User> validateUser(String loginName, String password) {
//         User user = null;
//         try {
//             user = userDao.getUser(loginName, UserEntity.Status.enable.getStatus());
//             if (null != user && user.getPassword().equals(HashStrategyUtil.computeHash(password, user.getPasswordSalt()))) {
//                 return Optional.of(user);
//             }
//         } catch (DBIException e) {
//             log.error("user auth: get user {} database error: {}", loginName, ExceptionUtils.getMessage(e));
//         } catch (Exception e) {
//             log.error("user auth: validate user {} computeHash error: {}", loginName, ExceptionUtils.getMessage(e));
//         }
//         return Optional.empty();
//     }
// 
//     public String getTokenByAccountId(String accountId) throws NiPingException {
//         String token = null;
//         try {
//             token = accessCredentialsDao.getTokenByAccountId(accountId);
//         } catch (DBIException e) {
//             log.error("user auth: get token by account id {} error: {}", accountId, ExceptionUtils.getMessage(e));
//             throw new NiPingException(DBError);
//         }
//         return token;
//     }
// }


// Path: server/src/main/java/com/cloudwise/sap/niping/auth/SapBasicAuthenticator.java
import com.cloudwise.sap.niping.common.vo.User;
import com.cloudwise.sap.niping.service.AuthService;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.basic.BasicCredentials;
import javax.inject.Inject;
import java.util.Optional;

package com.cloudwise.sap.niping.auth;




public class SapBasicAuthenticator implements Authenticator<BasicCredentials, BasicAuthUser> {

    @Inject
    AuthService authService;