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

com.yammer.dropwizard.auth.oauth.OAuthProvider Maven / Gradle / Ivy

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

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;

/**
 * A Jersey providers for OAuth2 bearer tokens.
 *
 * @param  the principal type
 */
public class OAuthProvider implements InjectableProvider {
    private final Authenticator authenticator;
    private final String realm;

    /**
     * Creates a new {@link OAuthProvider} with the given {@link Authenticator} and realm.
     *
     * @param authenticator    the authenticator which will take the OAuth2 bearer token and convert
     *                         them into instances of {@code T}
     * @param realm            the name of the authentication realm
     */
    public OAuthProvider(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 OAuthInjectable(authenticator, realm, a.required());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy