当前位置: 首页>>代码示例>>Java>>正文


Java AuthDynamicFeature类代码示例

本文整理汇总了Java中io.dropwizard.auth.AuthDynamicFeature的典型用法代码示例。如果您正苦于以下问题:Java AuthDynamicFeature类的具体用法?Java AuthDynamicFeature怎么用?Java AuthDynamicFeature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthDynamicFeature类属于io.dropwizard.auth包,在下文中一共展示了AuthDynamicFeature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configure

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public boolean configure(final FeatureContext featureContext) {
    final UserRepository userRepo = CDI.current().select(UserRepository.class).get();
    final Authenticator<String, User> authenticator = new GoogleAuthenticator(
            authConfig.getClientId(), userRepo, authConfig.getHostedDomain()
    );

    final Authenticator<String, User> cachingAuthenticator = new CachingAuthenticator<>(
            metricRegistry, authenticator, authConfig.getAuthenticationCachePolicy()
    );

    featureContext.register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<User>()
            .setAuthenticator(cachingAuthenticator)
            .setPrefix("Bearer")
            .buildAuthFilter()));
    featureContext.register(new AuthValueFactoryProvider.Binder<>(User.class));

    return true;
}
 
开发者ID:PaperCutSoftware,项目名称:dust-api,代码行数:21,代码来源:AuthenticatorFeature.java

示例2: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(PublicAuthConfiguration conf, Environment environment) throws Exception {
    DataSourceFactory dataSourceFactory = conf.getDataSourceFactory();

    jdbi = new DBIFactory().build(environment, dataSourceFactory, "postgresql");
    initialiseMetrics(conf, environment);

    TokenService tokenService = new TokenService(conf.getTokensConfiguration());

    environment.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<Token>()
                    .setAuthenticator(new TokenAuthenticator(tokenService))
                    .setPrefix("Bearer")
                    .buildAuthFilter()));
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(Token.class));

    environment.jersey().register(new PublicAuthResource(new AuthTokenDao(jdbi), tokenService));
    environment.jersey().register(new HealthCheckResource(environment));
    environment.jersey().register(new ValidationExceptionMapper());
    environment.jersey().register(new TokenNotFoundExceptionMapper());
    environment.healthChecks().register("database", new DatabaseHealthCheck(conf,environment));

    environment.servlets().addFilter("LoggingFilter", new LoggingFilter())
            .addMappingForUrlPatterns(of(REQUEST), true, "/v1" + "/*");
}
 
开发者ID:alphagov,项目名称:pay-publicauth,代码行数:26,代码来源:PublicAuthApp.java

示例3: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(final AuthriteServiceConfiguration configuration,
                final Environment environment) {

    final DBIFactory factory = new DBIFactory();
    final DBI dbi = factory.build(environment, configuration.getDatabase(), "h2");
    final JWTConfiguration jwtConfiguration = configuration.getJwt();
    final JwtTokenManager jwtTokenManager = jwtConfiguration.buildTokenManager();
    final PasswordManagementConfiguration passwordManagement = configuration.getPasswordManagement();
    final UsersService usersService = new UsersService(dbi, jwtTokenManager, passwordManagement);
    final UsersResource usersResource = new UsersResource(usersService, jwtConfiguration);
    environment.jersey().register(usersResource);

    final PlayersResource playersResource = new PlayersResource(dbi);
    environment.jersey().register(playersResource);

    environment.jersey().register(new AuthDynamicFeature(jwtConfiguration.buildAuthFilter()));
    environment.jersey().register(RolesAllowedDynamicFeature.class);

    //Required to use @Auth to inject a custom Principal type into your resource
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
}
 
开发者ID:lewisd32,项目名称:authrite,代码行数:23,代码来源:AuthriteServiceApplication.java

示例4: registerAuthenticator

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
/**
 *
 * @param environment The Dropwizard environment
 * @param authorizer A specific authorizer to use instead of the default PermitAllAuthorizer.  See
 * http://www.dropwizard.io/0.9.1/docs/manual/auth.html for more details
 */
public void registerAuthenticator(Environment environment, Authorizer<Peer> authorizer) {
    Preconditions.checkNotNull(environment, "Illegal call to registerAuthenticator with a null Environment object");
    Authenticator<BasicCredentials, Peer> authenticator;
    if (this.cachePolicy != null) {
        authenticator = createCachingAuthenticator(environment.metrics());
    }
    else {
        authenticator = createAuthenticator();
    }
    environment.jersey().register(new AuthDynamicFeature(
        new BasicCredentialAuthFilter.Builder<Peer>()
            .setAuthenticator(authenticator)
            .setAuthorizer(authorizer)
            .setRealm(this.realm)
            .buildAuthFilter()));
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(Peer.class));
}
 
开发者ID:washingtonpost,项目名称:dropwizard-peer-authenticator,代码行数:25,代码来源:AllowedPeerConfiguration.java

示例5: registerUserAuth

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@VisibleForTesting
void registerUserAuth(UserInfoConfiguration configuration, Environment environment) {
    JwtVerifier jwtVerifier = configuration.getSecurity().getJwtVerification().newInstanceFromConfig();
    environment.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<User>()
                    .setAuthenticator(new OAuth2Authenticator(jwtVerifier))
                    .setAuthorizer(new OAuth2Authorizer())
                    .setPrefix("Bearer")
                    .buildAuthFilter()
    ));
    // Enable the resource protection annotations: @RolesAllowed, @PermitAll & @DenyAll
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    // Enable the @Auth annotation for binding authenticated users to resource method parameters
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
}
 
开发者ID:wdawson,项目名称:dropwizard-auth-example,代码行数:16,代码来源:UserInfoApplication.java

示例6: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(CoreServiceConfig t, Environment e) throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(CoreOAuth2ServiceLoader.class);
    ctx.registerShutdownHook();
    ctx.start();

    e.jersey().register(new JacksonMessageBodyProvider(new GPJacksonSupport().getDefaultMapper()));
    e.jersey().register(new OAuth2ExceptionProvider());

    e.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<GPAuthenticatedPrincipal>()
                    .setAuthenticator(new CoreOAuthAuthenticator(t))
                    .setPrefix("Bearer")
                    .buildAuthFilter()));
    e.jersey().register(RolesAllowedDynamicFeature.class);
    e.jersey().register(new AuthValueFactoryProvider.Binder<>(Principal.class));

    e.healthChecks().register("service-health-check",
            new CoreServiceHealthCheck());

    Map<String, Object> resources = ctx.getBeansWithAnnotation(Path.class);

    for (Map.Entry<String, Object> entry : resources.entrySet()) {
        e.jersey().register(entry.getValue());
    }
}
 
开发者ID:geosdi,项目名称:geoplatform-oauth2-extensions,代码行数:27,代码来源:CoreServiceApp.java

示例7: setupLdapAuth

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
private static void setupLdapAuth(LdapConfiguration ldapConfiguration, Environment environment) {
    final LdapAuthenticator ldapAuthenticator = new LdapAuthenticator(ldapConfiguration);
    final CachingAuthenticator<BasicCredentials, User> cachingAuthenticator =
            new CachingAuthenticator<>(
                    environment.metrics(),
                    TenacityAuthenticator.wrap(
                            new ResourceAuthenticator(ldapAuthenticator), BreakerboxDependencyKey.BRKRBX_LDAP_AUTH),
                    ldapConfiguration.getCachePolicy()
            );
    environment.jersey().register(new AuthDynamicFeature(
                    new BasicCredentialAuthFilter.Builder<User>()
                            .setAuthenticator(cachingAuthenticator)
                            .setRealm("breakerbox")
                            .buildAuthFilter()));
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
}
 
开发者ID:yammer,项目名称:breakerbox,代码行数:17,代码来源:BreakerboxService.java

示例8: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(ExampleAppConfiguration configuration, Environment environment) throws Exception {
    final LdapConfiguration ldapConfiguration = configuration.getLdapConfiguration();

    Authenticator<BasicCredentials, User> ldapAuthenticator = new CachingAuthenticator<>(
            environment.metrics(),
            new ResourceAuthenticator(new LdapAuthenticator(ldapConfiguration)),
            ldapConfiguration.getCachePolicy());

    environment.jersey().register(new AuthDynamicFeature(
            new BasicCredentialAuthFilter.Builder<User>()
                    .setAuthenticator(ldapAuthenticator)
                    .setRealm("LDAP")
                    .buildAuthFilter()));

    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));

    environment.healthChecks().register("ldap", new LdapHealthCheck<>(
            new ResourceAuthenticator(new LdapCanAuthenticate(ldapConfiguration))));
}
 
开发者ID:yammer,项目名称:dropwizard-auth-ldap,代码行数:21,代码来源:ExampleAppTest.java

示例9: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
    public void run(ApiConfig configuration, Environment environment) throws Exception {
        LOGGER.info("api started up");
        injector = guiceBundle.getInjector();
        JerseyEnvironment jersey = environment.jersey();
        register(environment.lifecycle(), REFLECTIONS.getSubTypesOf(Managed.class)); // registers NbdServer


//        injector.getInstance(SessionFactory.class); //init DB
        installCorsFilter(environment);
        //init all Singletons semi-eagerly
        REFLECTIONS.getTypesAnnotatedWith(Singleton.class).forEach(injector::getInstance);
        final Set<Class<?>> resources = REFLECTIONS.getTypesAnnotatedWith(Path.class);
        register(jersey, resources);


        jersey.register(new LoggingExceptionMapper<Throwable>() {
            @Override
            protected String formatErrorMessage(long id, Throwable exception) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                exception.printStackTrace(pw);
                return sw.toString();
            }
        });
        jersey.register(new JsonProcessingExceptionMapper(true));
        jersey.register(new EarlyEofExceptionMapper());


        final TrivialAuthenticator instance = injector.getInstance(TrivialAuthenticator.class);
        environment.jersey().register(new AuthDynamicFeature(
                new BasicCredentialAuthFilter.Builder<Principal>()
                        .setAuthenticator(instance)
                        .setAuthorizer((principal, role) -> false)
                        .buildAuthFilter()));
        environment.jersey().register(RolesAllowedDynamicFeature.class);

    }
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:39,代码来源:MinebdApplication.java

示例10: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(UserServiceConfiguration userServiceConfiguration, Environment environment) throws Exception {


    dbClient = userServiceConfiguration.getDbConfig().build(environment);
    log.info("Connected to db: " + dbClient.getConnectString());
    /*
     * Setup basic authentication against DB table.
     */
    environment.jersey().register(new AuthDynamicFeature(
            new BasicCredentialAuthFilter.Builder<PrincipalUser>()
                    .setAuthenticator(new SimpleAuthenticator(dbClient))
                    .setRealm("amigo_user")
                    .buildAuthFilter()));
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(PrincipalUser.class));

    environment.healthChecks().register("database", new DBHealthCheck(dbClient));
    /*
     * Register resources with jersey.
     */
    final UserResource userResource = new UserResource(dbClient);

    /*
     * Setup jersey environment.
     */
    environment.jersey().setUrlPattern(EndpointUtils.ENDPOINT_ROOT + "/*");
    environment.jersey().register(userResource);
    log.info("Done with all initializations for user service");
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:30,代码来源:UserServiceApplication.java

示例11: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(final SecureTodoConfiguration configuration,
                final Environment environment) {
   final DBIFactory dbiFactory = new DBIFactory();
   final DBI todoJdbi = dbiFactory.build(environment, configuration.getTodoDbDataSourceFactory(), "todoDb");
   final TodoUserDAO todoUserDao = todoJdbi.onDemand(TodoUserDAO.class);
   final TodoItemDAO todoItemDao = todoJdbi.onDemand(TodoItemDAO.class);

   final AccessControlContextFactory accessControlContextFactory = configuration.getAccessControlContextFactory();
   accessControlContextFactory.initialize(environment, configuration.getOaccDbDataSourceFactory(), "oacc");

   environment.jersey().register(new TodoUserResource(new TodoUserService(todoUserDao, accessControlContextFactory)));
   environment.jersey().register(new TodoItemResource(new TodoItemService(todoItemDao)));

   environment.jersey().register(new AuthDynamicFeature(
         new BasicCredentialAuthFilter.Builder<OaccPrincipal>()
               .setAuthenticator(new OaccBasicAuthenticator(accessControlContextFactory))
               .setRealm("OACC Basic Authentication")
               .buildAuthFilter()));
   // to use @Auth to inject a custom Principal type into a resource:
   environment.jersey().register(new AuthValueFactoryProvider.Binder<>(OaccPrincipal.class));

   environment.jersey().register(new AuthorizationExceptionMapper(environment.metrics()));
   environment.jersey().register(new IllegalArgumentExceptionMapper(environment.metrics()));
   environment.jersey().register(new InvalidCredentialsExceptionMapper(environment.metrics()));
   environment.jersey().register(new NotAuthenticatedExceptionMapper(environment.metrics()));
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:28,代码来源:SecureTodoApplication.java

示例12: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(Configuration configuration, Environment environment) {

    environment.jersey().register(new LoginResource());
    environment.jersey().register(new UserResource());

    environment.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<PrincipalImpl>()
                    .setAuthenticator(new TestOAuthAuthenticator()).setPrefix("Bearer")
                    .buildAuthFilter()));
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(PrincipalImpl.class));

    //TODO move this cleanup into the tests
    environment.lifecycle().manage(new Managed() {
        @Override
        public void start() {
        }

        @Override
        public void stop() {
            flushRedis();
        }

        private void flushRedis() {
            try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
                connection.sync().flushdb();
            }
            redisClient.shutdownAsync();
        }
    });

}
 
开发者ID:mokies,项目名称:ratelimitj,代码行数:34,代码来源:RateLimitApplication.java

示例13: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(SystemApiConfiguration config, Environment environment) throws Exception {
    this.environment = environment;

    if (config.forwardHttps()) {
        addHttpsForward(environment.getApplicationContext());
    }
    environment.jersey().register(RolesAllowedDynamicFeature.class);

    final BasicCredentialAuthFilter<UserConfiguration> userBasicCredentialAuthFilter =
            new BasicCredentialAuthFilter.Builder<UserConfiguration>()
                    .setAuthenticator(new BasicAuthenticator(config.getUser()))
                    .setRealm("System-Api")
                    .setAuthorizer(new BasicAuthorizer(config.getUser()))
                    .buildAuthFilter();

    SystemInfo systemInfo = new SystemInfo();

    HardwareAbstractionLayer hal = systemInfo.getHardware();
    OperatingSystem os = systemInfo.getOperatingSystem();

    environment.jersey().register(new AuthDynamicFeature(userBasicCredentialAuthFilter));
    environment.jersey().register(new AuthValueFactoryProvider.Binder(UserConfiguration.class));

    SpeedMeasurementManager speedMeasurementManager = new SpeedMeasurementManager(Executors.newScheduledThreadPool(5), Clock.systemUTC(), 5);
    InfoProvider provider = new InfoProviderFactory(hal, os, SystemInfo.getCurrentPlatformEnum(), config, speedMeasurementManager).provide();
    environment.lifecycle().manage(speedMeasurementManager);

    environment.jersey().register(new SystemResource(provider));
    environment.jersey().register(new DiskStoresResource(provider));
    environment.jersey().register(new GpuResource(provider));
    environment.jersey().register(new MemoryResource(provider));
    environment.jersey().register(new NetworkInterfacesResource(provider));
    environment.jersey().register(new PowerSourcesResource(provider));
    environment.jersey().register(new ProcessesResource(provider));
    environment.jersey().register(new CpuResource(provider));
    environment.jersey().register(new SensorsResource(provider));
    environment.jersey().register(new MotherboardResource(provider));
    environment.jersey().register(new MetaInfoResource(getVersionFromManifest(), getEndpoints(environment), os.getProcessId()));
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:41,代码来源:SystemApiApplication.java

示例14: run

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
@Override
public void run(PublicApiConfig config, Environment environment) throws Exception {
    final Client client = RestClientFactory.buildClient(config.getRestClientConfig());

    ObjectMapper objectMapper = environment.getObjectMapper();
    configureObjectMapper(config, objectMapper);

    environment.healthChecks().register("ping", new Ping());
    environment.jersey().register(new HealthCheckResource(environment));
    environment.jersey().register(new PaymentsResource(config.getBaseUrl(), client, config.getConnectorUrl(), config.getConnectorDDUrl(), objectMapper));
    environment.jersey().register(new PaymentRefundsResource(config.getBaseUrl(), client, config.getConnectorUrl()));
    environment.jersey().register(new RequestDeniedResource());

    RateLimiter rateLimiter = new RateLimiter(config.getRateLimiterConfig().getRate(), config.getRateLimiterConfig().getPerMillis());

    environment.servlets().addFilter("AuthorizationValidationFilter", new AuthorizationValidationFilter(config.getApiKeyHmacSecret()))
            .addMappingForUrlPatterns(of(REQUEST), true, API_VERSION_PATH + "/*");

    environment.servlets().addFilter("RateLimiterFilter", new RateLimiterFilter(rateLimiter, objectMapper))
            .addMappingForUrlPatterns(of(REQUEST), true, API_VERSION_PATH + "/*");

    environment.servlets().addFilter("LoggingFilter", new LoggingFilter())
            .addMappingForUrlPatterns(of(REQUEST), true, API_VERSION_PATH + "/*");

    environment.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<Account>()
                    .setAuthenticator(new AccountAuthenticator(client, config.getPublicAuthUrl()))
                    .setPrefix("Bearer")
                    .buildAuthFilter()));
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(Account.class));

    attachExceptionMappersTo(environment.jersey());

    initialiseMetrics(config, environment);
}
 
开发者ID:alphagov,项目名称:pay-publicapi,代码行数:36,代码来源:PublicApi.java

示例15: setupAuthentication

import io.dropwizard.auth.AuthDynamicFeature; //导入依赖的package包/类
private void setupAuthentication(ApiServerConfig cfg, Environment env) throws Exception {
    final Client client = new RestClientBuilder(env, cfg).build(getName());

    // Health check for oauth2 server presence
    final OAuth2HealthCheck healthCheck = new OAuth2HealthCheck(cfg.getOauth2Config(), client);
    env.healthChecks().register("Oauth2 server", healthCheck);

    // Setting up the oauth2 authenticator
    CookieEncrypter cookieEncrypter = new CookieEncrypter(cfg.getOauth2Config().getCookieSecretKey());
    boolean https = ((DefaultServerFactory)cfg.getServerFactory()).getApplicationConnectors().get(0) instanceof HttpsConnectorFactory;
    cookieEncrypter.setSecureFlag(https);
    OAuth2Authenticator authenticator = new OAuth2Authenticator(cfg.getOauth2Config(), client);

    // Using cache authenticator
    CachingAuthenticator<OAuth2Credentials, User> cachingAuthenticator =
            new CachingAuthenticator<OAuth2Credentials, User>(env.metrics(), authenticator, cfg.getCacheSpec());

    final OAuth2AuthFilter<User> oAuth2AuthFilter =
            new OAuth2AuthFilter.Builder<OAuth2Credentials, User, OAuth2AuthFilter<User>, CachingAuthenticator<OAuth2Credentials, User>>()
                    .setAuthenticator(cachingAuthenticator)
                    .setCookieEncrypter(cookieEncrypter)
                    .build();

    env.jersey().register(new AuthDynamicFeature(oAuth2AuthFilter));
    env.jersey().register(RolesAllowedDynamicFeature.class);
    env.jersey().register(new AuthValueFactoryProvider.Binder<User>(User.class));

    // Register the oauth2 resource that handles client authentication
    final OAuth2Resource or = new OAuth2Resource(client, cfg.getOauth2Config(), cookieEncrypter);
    env.jersey().register(or);
}
 
开发者ID:edeoliveira,项目名称:oauth2-dropwizard,代码行数:32,代码来源:ApiServer.java


注:本文中的io.dropwizard.auth.AuthDynamicFeature类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。