@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)); }
@Override public void run(UpsourceConfiguration configuration, Environment environment) throws Exception { DBIFactory factory = new DBIFactory(); DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "data-source"); GitHub gitHub = GitHub.connectUsingOAuth(configuration.getGitHubOAuthToken()); ImmutableMap.Builder<String, Repository> repositoryBuilder = ImmutableMap.builder(); ImmutableMap.Builder<String, ExecutorService> executorBuilder = ImmutableMap.builder(); configuration.getRepositories().forEach( repository -> { repositoryBuilder.put(repository.getFullName(), repository); executorBuilder.put(repository.getFullName(), Executors.newSingleThreadExecutor()); }); List<String> repoNames = configuration.getRepositories().stream().map(Repository::getFullName). collect(Collectors.toList()); GitHubConnector gitHubConnector = new GitHubConnector(gitHub, repositoryBuilder.build(), executorBuilder.build()); gitHubConnector.handleStartup(); GitHubWebhookResource gitHubWebhookResource = new GitHubWebhookResource(gitHubConnector, ImmutableList.copyOf(repoNames)); environment.jersey().register( gitHubWebhookResource); environment.jersey().register(new GitHubHMACFilter(configuration.getGitHubWebhookSecret())); //environment.jersey().register(new UserResource(jdbi.onDemand(UserDao.class))); environment.jersey().register(DeclarativeLinkingFeature.class); }
@Before public void setupTests() throws IOException { final DataSourceFactory dataSourceFactory = new DataSourceFactory(); dataSourceFactory.setDriverClass("org.h2.Driver"); dataSourceFactory.setUrl("jdbc:h2:mem:date-time-optional-" + System.currentTimeMillis() + "?user=sa"); dataSourceFactory.setInitialSize(1); final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test"); try (Handle h = dbi.open()) { h.execute("CREATE TABLE tasks (" + "id INT PRIMARY KEY, " + "assignee VARCHAR(255) NOT NULL, " + "start_date TIMESTAMP, " + "end_date TIMESTAMP, " + "comments VARCHAR(1024) " + ")"); } dao = dbi.onDemand(TaskDao.class); }