Java 类io.dropwizard.auth.AuthFactory 实例源码

项目:dropwizard-auth-jwt    文件:JwtAuthFactoryTest.java   
public JWTAuthTestResourceConfig() {
    super(true, new MetricRegistry());

    final Authenticator<String, String> authenticator = new Authenticator<String, String>() {
        @Override
        public Optional<String> authenticate(String credentials) throws AuthenticationException {
            if ("good-one".equals(credentials)) {
                return Optional.of("good-one");
            }

            if ("bad-one".equals(credentials)) {
                throw new AuthenticationException("server ran out of entropy");
            }

            return Optional.absent();
        }
    };

    register(AuthFactory.binder(new JwtAuthFactory<>(authenticator, REALM, String.class).prefix(PREFIX)));
    register(AuthResource.class);
}
项目:el-bombillo    文件:ServiceRegistryApplication.java   
@Override
public void run(final ServiceRegistryConfiguration configuration, final Environment environment) throws Exception {
    final DataSourceFactory database = configuration.getDatabase();

    // execute DB migrations
    final Flyway flyway = new Flyway();
    flyway.setDataSource(database.getUrl(), database.getUser(), database.getPassword());
    log.debug("execute database migrations");
    flyway.migrate();
    log.info("database migrations successfully executed");

    // create DBI instance
    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, database, "postgresql");

    environment.jersey().register(AuthFactory.binder(new BasicAuthFactory<>(
                    new ServiceRegistryAuthenticator(configuration.getCredentials()), "Realm", ServiceRegistryCaller.class))
    );
    environment.jersey().register(new ServiceResource(jdbi.onDemand(ServiceDAO.class)));
}
项目:AugumentedSzczecin_java    文件:AugmentedApplication.java   
private void registerAuthorizationProviders(final AugmentedConfiguration augmentedConfiguration, final Environment environment) {
    final UserDao userDao = injector.getInstance(UserDao.class);
    final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(userDao);
    final CachingAuthenticator cachingAuthenticator = new CachingAuthenticator(environment.metrics(), basicAuthenticator,
            augmentedConfiguration.getAuthCacheBuilder());
    final Binder authBinder = AuthFactory.binder(new BasicAuthFactory(cachingAuthenticator, "Basic auth", User.class));
    environment.jersey().register(authBinder);
}
项目:microservices-comparison    文件:DropwizardApplication.java   
@Override
public void run(DropwizardServerConfiguration configuration, Environment environment) throws Exception {
    environment.healthChecks().register("template", guiceBundle.getInjector().getInstance(TemplateHealthCheck.class));
    environment.jersey().register(guiceBundle.getInjector().getInstance(HelloWorldResource.class));
    environment.jersey().register(guiceBundle.getInjector().getInstance(CarsResource.class));
    environment.jersey().register(guiceBundle.getInjector().getInstance(CarResource.class));
    environment.jersey().register(AuthFactory.binder(
            new OAuthFactory<>(guiceBundle.getInjector().getInstance(FacebookTokenAuthenticator.class),
                    getName() + "-Realm",
                    User.class)));
}
项目:biblio-server    文件:BiblioApplication.java   
@Override
public void run(BiblioConfiguration configuration, Environment environment) throws Exception {
    final IdGenerator idGenerator = new IdGenerator();
    environment.jersey().register(new UnexpectedExceptionMapper(idGenerator));
    environment.jersey().register(AuthenticationErrorMapper.class);
    environment.jersey().register(UnauthorizedExceptionMapper.class);
    environment.jersey().register(IllegalArgumentExceptionMapper.class);

    final CacheConfiguration cacheConfig = configuration.getCacheConfiguration();
    final JedisPool pool = new JedisPool(new GenericObjectPoolConfig(), cacheConfig.getAddress(),
            cacheConfig.getPort(), cacheConfig.getSessionExpiration(), cacheConfig.getPassword(), Protocol.DEFAULT_DATABASE);

    final Jedis jedis = pool.getResource();
    pool.returnResource(jedis);

    final UserDao userDao = new UserDao(hibernate.getSessionFactory());
    final BookDao bookDao = new BookDao(hibernate.getSessionFactory());

    final SessionDao sessionDao = new SessionDao(pool, configuration.getCacheConfiguration());

    environment.jersey().register(new UserResource(userDao, sessionDao));
    environment.jersey().register(new BarCodeResource(bookDao));
    environment.jersey().register(new BookResource(bookDao));
    environment.jersey().register(new IsbnResource(bookDao));
    environment.jersey().register(new LendResource());

    environment.jersey().register(
            AuthFactory.binder(
                    new TokenAuthFactory<>(
                            new UserAuthenticator(userDao, sessionDao),
                            "SECURITY REALM",
                            User.class)));

}
项目:el-bombillo    文件:AccountServiceApplication.java   
@Override
public void run(final AccountServiceConfiguration configuration, final Environment environment) throws Exception {
    final DataSourceFactory database = configuration.getDatabase();
    this.executeDatabaseMigrations(database);

    // create DBI instance
    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, database, "postgresql");

    // create a HTTP client
    final Client client = new JerseyClientBuilder(environment).using(configuration.getHttpClient()).build("httpClient");

    // setup listener which will register this service within the service registry
    final AccountServiceLifecycleListener accountServiceLifecycleListener = new AccountServiceLifecycleListener(configuration.getServiceInformation(), configuration.getRegistryService(), client);
    environment.lifecycle().addServerLifecycleListener(accountServiceLifecycleListener);
    environment.healthChecks().register("registry", new ServiceRegistryHealthCheck(accountServiceLifecycleListener));
    environment.admin().addTask(new ServiceRegistryTask(accountServiceLifecycleListener));

    // enable the linking feature of jersey
    environment.jersey().getResourceConfig().packages(getClass().getPackage().getName()).register(DeclarativeLinkingFeature.class);

    // register authenticator
    environment.jersey().register(AuthFactory.binder(new BasicAuthFactory<>(
                    new AccountServiceAuthenticator(configuration.getServiceInformation()), "Realm", AccountServiceCaller.class))
    );

    // register REST resources
    environment.jersey().register(new AccountResource(jdbi.onDemand(AccountDAO.class)));
}
项目:dropwizard-api-key-bundle    文件:ApiKeyBundle.java   
@Override
public void run(T bundleConfiguration, Environment environment) throws Exception {
  ApiKeyConfiguration configuration = bundleConfiguration.getApiKeyConfiguration();

  Optional<AuthConfiguration> basic = configuration.getBasicConfiguration();
  checkState(basic.isPresent(), "A basic-http configuration option must be specified");

  AuthFactory<?, String> factory = createBasicAuthFactory(basic.get(), environment.metrics());
  environment.jersey().register(AuthFactory.binder(factory));
}
项目:amos-ss15-proj2    文件:CroudTripApplication.java   
@Override
public void run(CroudTripConfig configuration, Environment environment) throws Exception {
    Injector injector = Guice.createInjector(
            new DbModule(hibernateBundle.getSessionFactory()),
               new DirectionsModule(configuration),
            new GcmModule(configuration.getGoogleAPIKey()),
            new TripsModule(),
            new PlacesModule( configuration ));

    // start managed instances (manually since deployment via WAR file does not seem to work)
    injector.getInstance(TripReservationGarbageCollectionExecutor.class).start();
    injector.getInstance(RunningTripQueryGarbageCollectionExecutor.class).start();
    injector.getInstance(DisableTripOffersExecutor.class).start();
       injector.getInstance(ExpireTripOffersExecutor.class).start();
    injector.getInstance(ExpireJoinTripRequestsExecutor.class).start();

    // setup REST api
       environment.jersey().register(injector.getInstance(UsersResource.class));
    environment.jersey().register(injector.getInstance(UsersHeadResource.class));
    environment.jersey().register(injector.getInstance(AvatarsResource.class));
    environment.jersey().register(injector.getInstance(TripsResource.class));
    environment.jersey().register(injector.getInstance(VehicleResource.class));
    environment.jersey().register(injector.getInstance(GcmRegistrationResource.class));
    environment.jersey().register(injector.getInstance(LogsResource.class));
    environment.jersey().register(injector.getInstance(NotFoundExceptionMapper.class));
    environment.jersey().register(injector.getInstance(JsonExceptionMapper.class));
    environment.jersey().register(injector.getInstance(RouteNotFoundExceptionMapper.class));
    environment.jersey().register(injector.getInstance(ThrowableExceptionMapper.class));
    environment.jersey().register(AuthFactory.binder(new BasicAuthFactory<>(
            injector.getInstance(BasicAuthenticator.class),
            "all secret",
            User.class)));

    // register a set of "default" users
    SessionFactory sessionFactory = injector.getInstance(SessionFactory.class);
    UserManager userManager = injector.getInstance(UserManager.class);

    Session session = null;
    try {
        session = sessionFactory.openSession();
        ManagedSessionContext.bind(session);
        for (UserDescription user : configuration.getUsers()) {
            if (!userManager.findUserByEmail(user.getEmail()).isPresent()) {
                userManager.addUser(user);
            }
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (session != null) {
            session.flush();
            session.close();
        }
    }
}
项目:DJBot    文件:DjApplication.java   
@Override
public void run(DjConfiguration configuration,
                Environment environment) {

    final HttpClient client = new HttpClientBuilder(environment).using(configuration.getHttpClientConfiguration())
            .build("http-client");

    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "postgresql");
    final DbMetaDAO meta = jdbi.onDemand(DbMetaDAO.class);
    int currentDbVersion = 1; //if this is ever incremented, you need to fix the below code to be a "real" migration system!

    if(!meta.songqueueTableExists()) {
        //we are creating a fresh new db
        meta.createSongqueueTable();
        meta.createMetaTable();
        meta.insertDbVersion(currentDbVersion);
    }

    if(!meta.metaTableExists()) {
        //we are updating from version 0 of the db when there was no meta table
        meta.createMetaTable();
        meta.insertDbVersion(currentDbVersion);
        meta.addSiteColumn();

        meta.populateLegacySoundcloudIds();
        meta.populateLegacyYoutubeIds();
    }

    jdbi.close(meta);

    final SongQueueDAO dao = jdbi.onDemand(SongQueueDAO.class);
    DjResource resource = new DjResource(configuration, client, dao);
    environment.jersey().register(resource);

    final ChannelCheck channelCheck = new ChannelCheck(resource);

    if(configuration.isDjbotPublic()) {
        String adminUsername = configuration.getAdminUsername();
        String adminPassword = configuration.getAdminPassword();
        if(StringUtils.isBlank(adminUsername) || StringUtils.isBlank(adminPassword)) {
            throw new RuntimeException("Djbot is set to public, so it needs an adminUsername and adminPassword");
        }

        environment.jersey().register(AuthFactory.binder(
                new BasicAuthFactory<User>(
                        new ConfiguredUserAuthenticator(adminUsername, adminPassword),
                        "djBotRealm",
                        User.class )));

    }

    environment.healthChecks().register("currentSong", channelCheck);
}
项目:oregami-server    文件:OregamiApplication.java   
private Binder createAuthProvider() {
    JsonWebTokenParser tokenParser = new DefaultJsonWebTokenParser();
    final HmacSHA512Verifier tokenVerifier = new HmacSHA512Verifier(AuthHelper.authKey);
    Binder authProvider = AuthFactory.binder(new JWTAuthFactory<>(new ExampleAuthenticator(), "realm", User.class, tokenVerifier, tokenParser));
    return authProvider;
}