package io.conducive.server.wiring;
import io.conducive.server.db.UserDAO;
import io.conducive.shared.model.User;
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.yammer.dropwizard.auth.Authenticator;
import com.yammer.dropwizard.auth.basic.BasicCredentials;
/**
* Basic authentication. Not good enough for production environment -- should switch to digest as default.
*/
public class SimpleAuthenticator implements Authenticator<BasicCredentials, User> {
@Inject
UserDAO dao;
@Override
public Optional<User> authenticate(BasicCredentials credentials) {
final User user = dao.getUser(credentials.getUsername(), credentials.getPassword().substring(0, 64), credentials.getPassword().substring(64));
if (user != null) {
return Optional.of(user);
}
return Optional.absent();
}
}