Java 类io.dropwizard.auth.basic.BasicAuthFactory 实例源码

项目: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);
}
项目: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   
private BasicAuthFactory<String> createBasicAuthFactory(AuthConfiguration config,
                                                        MetricRegistry metrics) {
  Authenticator<BasicCredentials, String> authenticator = createAuthenticator(config);

  Optional<String> cacheSpec = config.getCacheSpec();
  if (cacheSpec.isPresent()) {
    CacheBuilderSpec spec = CacheBuilderSpec.parse(cacheSpec.get());
    authenticator = new CachingAuthenticator<>(metrics, authenticator, spec);
  }

  return new BasicAuthFactory<>(authenticator, config.getRealm(), String.class);
}
项目: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);
}