// Path: src/main/java/com/thoughtworks/go/strongauth/util/Constants.java
// public class Constants {
//     public static final String PLUGIN_ID = "strongauth";
// }
// 
// Path: src/main/java/com/thoughtworks/util/Functional.java
// public static <T, U> Optional<U> flatMap(Optional<? extends T> maybeValue, final Function<T, Optional<U>> transformation) {
//     return maybeValue.isPresent() ? transformation.apply(maybeValue.get()) : Optional.<U>absent();
// }


import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.thoughtworks.go.plugin.api.logging.Logger;
import com.thoughtworks.go.strongauth.util.Constants;
import org.apache.commons.codec.DecoderException;
import java.util.List;
import static com.thoughtworks.util.Functional.flatMap;
import static java.lang.String.format;
package com.thoughtworks.go.strongauth.authentication;




public class Authenticator {

    public final String pluginId = Constants.PLUGIN_ID;
    private static final Logger LOGGER = Logger.getLoggerFor(Authenticator.class);
    private final List<? extends HashProvider> hashProviders;

    public Authenticator(
            final PrincipalDetailSource principalDetailSource,
            final List<? extends HashProvider> hashProviders
    ) {
        this.principalDetailSource = principalDetailSource;
        this.hashProviders = hashProviders;
    }

    private PrincipalDetailSource principalDetailSource;

    public Optional<Principal> authenticate(final String username, final String password) {
        LOGGER.info(format("Login attempt for user %s", username));
        Optional<Principal> maybePrincipal = flatMap(principalDetailSource.byUsername(username), new Function<PrincipalDetail, Optional<Principal>>() {
            @Override
            public Optional<Principal> apply(PrincipalDetail principalDetail) {
                return toPrincipal(principalDetail, password);
            }
        });

        if (!maybePrincipal.isPresent()) {
// Path: src/main/java/com/thoughtworks/go/strongauth/util/Constants.java
// public class Constants {
//     public static final String PLUGIN_ID = "strongauth";
// }
// 
// Path: src/main/java/com/thoughtworks/util/Functional.java
// public static <T, U> Optional<U> flatMap(Optional<? extends T> maybeValue, final Function<T, Optional<U>> transformation) {
//     return maybeValue.isPresent() ? transformation.apply(maybeValue.get()) : Optional.<U>absent();
// }


// Path: src/main/java/com/thoughtworks/go/strongauth/authentication/Authenticator.java
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.thoughtworks.go.plugin.api.logging.Logger;
import com.thoughtworks.go.strongauth.util.Constants;
import org.apache.commons.codec.DecoderException;
import java.util.List;
import static com.thoughtworks.util.Functional.flatMap;
import static java.lang.String.format;

package com.thoughtworks.go.strongauth.authentication;




public class Authenticator {

    public final String pluginId = Constants.PLUGIN_ID;
    private static final Logger LOGGER = Logger.getLoggerFor(Authenticator.class);
    private final List<? extends HashProvider> hashProviders;

    public Authenticator(
            final PrincipalDetailSource principalDetailSource,
            final List<? extends HashProvider> hashProviders
    ) {
        this.principalDetailSource = principalDetailSource;
        this.hashProviders = hashProviders;
    }

    private PrincipalDetailSource principalDetailSource;

    public Optional<Principal> authenticate(final String username, final String password) {
        LOGGER.info(format("Login attempt for user %s", username));
        Optional<Principal> maybePrincipal = flatMap(principalDetailSource.byUsername(username), new Function<PrincipalDetail, Optional<Principal>>() {
            @Override
            public Optional<Principal> apply(PrincipalDetail principalDetail) {
                return toPrincipal(principalDetail, password);
            }
        });

        if (!maybePrincipal.isPresent()) {
            LOGGER.warn(format("Login attempt for user %s failed.", username));