All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yammer.dropwizard.auth.basic.BasicAuthProvider Maven / Gradle / Ivy

There is a newer version: 0.6.2
Show newest version
package com.yammer.dropwizard.auth.basic;

import com.sun.jersey.api.model.Parameter;
import com.sun.jersey.core.spi.component.ComponentContext;
import com.sun.jersey.core.spi.component.ComponentScope;
import com.sun.jersey.spi.inject.Injectable;
import com.sun.jersey.spi.inject.InjectableProvider;
import com.yammer.dropwizard.auth.Auth;
import com.yammer.dropwizard.auth.Authenticator;
import com.yammer.dropwizard.logging.Log;

/**
 * A Jersey provider for Basic HTTP authentication.
 *
 * @param     the principal type.
 */
public class BasicAuthProvider implements InjectableProvider {
    static final Log LOG = Log.forClass(BasicAuthProvider.class);

    private final Authenticator authenticator;
    private final String realm;

    /**
     * Creates a new {@link BasicAuthProvider} with the given {@link Authenticator} and realm.
     *
     * @param authenticator    the authenticator which will take the {@link BasicCredentials} and
     *                         convert them into instances of {@code T}
     * @param realm            the name of the authentication realm
     */
    public BasicAuthProvider(Authenticator authenticator, String realm) {
        this.authenticator = authenticator;
        this.realm = realm;
    }

    @Override
    public ComponentScope getScope() {
        return ComponentScope.PerRequest;
    }

    @Override
    public Injectable getInjectable(ComponentContext ic,
                                       Auth a,
                                       Parameter c) {
        return new BasicAuthInjectable(authenticator, realm, a.required());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy