Package io.conducive.server.wiring

Source Code of io.conducive.server.wiring.SimpleAuthenticator

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();
    }
}
TOP

Related Classes of io.conducive.server.wiring.SimpleAuthenticator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.