io.dropwizard.configuration.YamlConfigurationFactory Java Examples

The following examples show how to use io.dropwizard.configuration.YamlConfigurationFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testConfigurationAuth1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getAuth().getWebac().getEnabled(), "WebAC wasn't enabled!");
    assertEquals(100L, config.getAuth().getWebac().getCacheSize(), "Incorrect auth/webac/cacheSize value!");
    assertEquals(10L, config.getAuth().getWebac().getCacheExpireSeconds(), "Incorrect webac cache expiry!");
    assertTrue(config.getAuth().getBasic().getEnabled(), "Missing basic auth support!");
    assertEquals("users.auth", config.getAuth().getBasic().getUsersFile(), "Incorrect basic auth users file!");
    assertEquals("trellis", config.getAuth().getRealm(), "Incorrect auth realm!");

    config.getAuth().setRealm("foo");
    assertEquals("foo", config.getAuth().getRealm(), "Incorrect auth realm!");
    assertTrue(config.getAuth().getJwt().getEnabled(), "JWT not enabled!");
    assertEquals("xd1GuAwiP2+M+pyK+GlIUEAumSmFx5DP3dziGtVb1tA+/8oLXfSDMDZFkxVghyAd28rXImy18TmttUi+g0iomQ==",
            config.getAuth().getJwt().getKey(), "Incorrect JWT key!");

    assertEquals("password", config.getAuth().getJwt().getKeyStorePassword(), "Incorrect JWT keystore password!");
    assertEquals("/tmp/trellisData/keystore.jks", config.getAuth().getJwt().getKeyStore(), "Wrong keystore loc!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("foo"), "'foo' missing from JWT key ids!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("bar"), "'bar' missing from JWT key ids!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("trellis"), "'trellis' missing from JWT key ids!");
    assertEquals(3, config.getAuth().getJwt().getKeyIds().size(), "Incorrect JWT Key id count!");
}
 
Example #2
Source File: MacroBaseConfTest.java    From macrobase with Apache License 2.0 6 votes vote down vote up
@Test
public void testParsing() throws Exception {
    ConfigurationFactory<MacroBaseConf> cfFactory = new YamlConfigurationFactory<>(MacroBaseConf.class,
                                                                               null,
                                                                               Jackson.newObjectMapper(),
                                                                               "");
    MacroBaseConf conf = cfFactory.build(new File("src/test/resources/conf/simple.yaml"));


    assertEquals((Double) 0.1, conf.getDouble("this.is.a.double"));
    assertEquals((Integer) 100, conf.getInt("this.is.an.integer"));
    assertEquals((Long) 10000000000000L, conf.getLong("this.is.a.long"));
    assertEquals("Test", conf.getString("this.is.a.string"));

    List<String> stringList = Lists.newArrayList("T1", "T2", "T3", "T4");
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.without.spaces").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.with.mixed.spaces").toArray());
}
 
Example #3
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testGetWebacService() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    when(mockResourceService.get(any())).thenAnswer(inv -> completedFuture(mockResource));
    when(mockResource.getMetadataGraphNames()).thenReturn(singleton(Trellis.PreferAccessControl));

    assertNotNull(TrellisUtils.getWebacService(config, mockResourceService), "WebAC configuration not present!");

    config.getAuth().getWebac().setEnabled(false);

    assertNull(TrellisUtils.getWebacService(config, mockResourceService),
            "WebAC config persists after disabling it!");

    config.getAuth().getWebac().setEnabled(true);

    final ResourceService mockRS = mock(ResourceService.class, inv -> {
        throw new TrellisRuntimeException("expected");
    });
    assertThrows(TrellisRuntimeException.class, () -> TrellisUtils.getWebacService(config, mockRS));
    config.getAuth().getWebac().setEnabled(false);
    assertNull(TrellisUtils.getWebacService(config, mockRS),
            "WebAC config persists after disabling it!");
}
 
Example #4
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testGetAuthFilters() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setKeyStore(null);

    final List<ContainerRequestFilter> filters = TrellisUtils.getAuthFilters(config);
    assertFalse(filters.isEmpty(), "Auth filters are missing!");
    assertEquals(2L, filters.size(), "Incorrect auth filter count!");

    config.getAuth().getBasic().setEnabled(false);
    config.getAuth().getJwt().setEnabled(false);

    assertTrue(TrellisUtils.getAuthFilters(config).isEmpty(), "Auth filters should have been disabled!");
}
 
Example #5
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationAssets1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    assertEquals("org/trellisldp/rdfa/resource.mustache", config.getAssets().getTemplate(), "Bad assets/template");
    assertEquals("http://example.com/image.icon", config.getAssets().getIcon(), "Bad assets/icon value!");
    assertTrue(config.getAssets().getJs().contains("http://example.com/scripts1.js"), "Missing assets/js value!");
    assertTrue(config.getAssets().getCss().contains("http://example.com/styles1.css"), "Missing assets/css value!");
}
 
Example #6
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetNoJwtAuthenticator() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setKeyStore(null);
    config.getAuth().getJwt().setKey("");
    config.getAuth().getJwt().setJwks(null);
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof NullAuthenticator,
            "JWT auth not disabled!");
}
 
Example #7
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationNotifications() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertFalse(config.getNotifications().getEnabled(), "Notifications unexpectedly enabled!");
    assertEquals(NotificationsConfiguration.Type.NONE, config.getNotifications().getType(),
            "Incorrect notification type!");
    assertEquals("example.com:12345", config.getNotifications().getConnectionString(), "Incorrect connection URL!");
    assertEquals("foo", config.getNotifications().any().get("some.other.value"), "Incorrect custom property!");
    assertEquals("test-topic", config.getNotifications().getTopicName(), "Incorrect topic name!");

}
 
Example #8
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationLocations() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("http://localhost:8080/", config.getBaseUrl(), "Incorrect baseUrl!");
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hubUrl!");
}
 
Example #9
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationAuth1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getAuth().getWebac().getEnabled(), "WebAC should be enabled!");
    assertEquals(200L, config.getAuth().getWebac().getCacheSize(), "Incorrect auth/webac/cacheSize");
    assertEquals(15L, config.getAuth().getWebac().getCacheExpireSeconds(), "Bad auth/webac/cache expiry!");
    assertTrue(config.getAuth().getBasic().getEnabled(), "basic auth not enabled!");
    assertEquals("users.auth", config.getAuth().getBasic().getUsersFile(), "Incorrect basic users file!");
    assertEquals("trellis", config.getAuth().getRealm(), "Incorrect auth realm!");
    assertEquals("openid", config.getAuth().getScope(), "Incorrect auth scope!");

    config.getAuth().setRealm("foobar");
    config.getAuth().setScope("baz");
    assertEquals("foobar", config.getAuth().getRealm(), "Incorrect auth/basic/realm value!");
    assertEquals("baz", config.getAuth().getScope(), "Incorrect auth scope!");
    assertTrue(config.getAuth().getJwt().getEnabled(), "auth/jwt not enabled!");
    assertEquals("Mz4DGzFLQysSGC98ESAnSafMLbxa71ls/zzUFOdCIJw9L0J8Q0Gt7+yCM+Ag73Tm5OTwpBemFOqPFiZ5BeBo4Q==",
            config.getAuth().getJwt().getKey(), "Incorrect auth/jwt/key");

    assertEquals("password", config.getAuth().getJwt().getKeyStorePassword(), "Wrong auth/jwt/keyStorePassword");
    assertEquals("/tmp/trellisData/keystore.jks", config.getAuth().getJwt().getKeyStore(), "Wrong keystore path!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("baz"), "'baz' not in auth/jwt/keyIds");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("bar"), "'bar' not in auth/jwt/keyIds");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("trellis"), "'trellis' not in auth/jwt/keyIds");
    assertEquals(3, config.getAuth().getJwt().getKeyIds().size(), "Incorrect count of auth/jwt/keyIds");
    assertEquals("https://www.trellisldp.org/testing/jwks.json", config.getAuth().getJwt().getJwks(),
            "Wrong jwks value!");
}
 
Example #10
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationCORS1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getCors().getEnabled(), "CORS not enabled!");
    assertTrue(config.getCors().getAllowOrigin().contains("*"), "'*' not in CORS allow-origin!");
    assertTrue(config.getCors().getAllowHeaders().contains("Link"), "Link not in CORS allow-headers");
    assertTrue(config.getCors().getAllowMethods().contains("PUT"), "PUT not in CORS allow-methods!");
    assertTrue(config.getCors().getExposeHeaders().contains("Memento-Datetime"),
            "memento-datetime missing from CORS expose-headers!");
    assertEquals(180, config.getCors().getMaxAge(), "Incorrect max-age value in CORS headers!");
    assertTrue(config.getCors().getAllowCredentials(), "Incorrect allow-credentials setting in CORS headers!");
}
 
Example #11
Source File: AbstractConfigurationTest.java    From dropwizard-pac4j with Apache License 2.0 5 votes vote down vote up
protected Pac4jFactory getPac4jFactory(
        Collection<Pac4jFeatureSupport> featuresSupported,
        String resourceName) throws Exception {
    ObjectMapper om = Jackson.newObjectMapper();
    Bootstrap<?> b = mock(Bootstrap.class);
    when(b.getObjectMapper()).thenReturn(om);

    for (Pac4jFeatureSupport fs : featuresSupported) {
        fs.setup(b);
    }

    return new YamlConfigurationFactory<>(Pac4jFactory.class,
            Validators.newValidator(), om, "dw").build(
                    new File(Resources.getResource(resourceName).toURI()));
}
 
Example #12
Source File: UpgradeCommand.java    From irontest with Apache License 2.0 5 votes vote down vote up
private IronTestConfiguration getIronTestConfiguration(String ironTestHome) throws IOException, ConfigurationException {
    Path configYmlFilePath = Paths.get(ironTestHome, "config.yml");
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    Validator validator = Validators.newValidator();
    YamlConfigurationFactory<IronTestConfiguration> factory =
            new YamlConfigurationFactory<>(IronTestConfiguration.class, validator, objectMapper, "dw");
    IronTestConfiguration configuration = factory.build(configYmlFilePath.toFile());
    return configuration;
}
 
Example #13
Source File: LdapLookupConfigTest.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
@Test public void parsesLDAPLookupCorrectly() throws Exception {
  File yamlFile = new File(Resources.getResource("fixtures/keywhiz-ldap-lookup-test.yaml").getFile());
  Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
  ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();

  LdapLookupConfig lookupConfig =
      new YamlConfigurationFactory<>(LdapLookupConfig.class, validator, objectMapper, "dw")
          .build(yamlFile);

  assertThat(lookupConfig.getRequiredRoles()).containsOnly("keywhizAdmins");
  assertThat(lookupConfig.getRoleBaseDN()).isEqualTo("ou=ApplicationAccess,dc=test,dc=com");
  assertThat(lookupConfig.getUserBaseDN()).isEqualTo("ou=people,dc=test,dc=com");
  assertThat(lookupConfig.getUserAttribute()).isEqualTo("uid");
}
 
Example #14
Source File: KeywhizTestRunner.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
static Injector createInjector() {
  KeywhizService service = new KeywhizService();
  Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(service);
  service.initialize(bootstrap);

  File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
  Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
  ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();
  KeywhizConfig config;
  try {
    config = new YamlConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw")
        .build(yamlFile);
  } catch (IOException | ConfigurationException e) {
    throw Throwables.propagate(e);
  }

  Environment environment = new Environment(service.getName(),
      objectMapper,
      validator,
      bootstrap.getMetricRegistry(),
      bootstrap.getClassLoader());

  Injector injector = Guice.createInjector(new ServiceModule(config, environment));

  service.setInjector(injector);
  return injector;
}
 
Example #15
Source File: AdminConsoleAppBuilder.java    From soabase with Apache License 2.0 5 votes vote down vote up
public AdminConsoleAppBuilder<T> withConfigurationClass(final Class<T> configurationClass)
{
    factoryFactory = new ConfigurationFactoryFactory<T>()
    {
        @Override
        public ConfigurationFactory<T> create(Class<T> klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix)
        {
            return new YamlConfigurationFactory<>(configurationClass, validator, objectMapper, propertyPrefix);
        }
    };
    return this;
}
 
Example #16
Source File: YamlInstanceDiscovery.java    From breakerbox with Apache License 2.0 5 votes vote down vote up
public YamlInstanceDiscovery(Path path,
                             Validator validator,
                             ObjectMapper objectMapper) {
    this.path = path;
    this.configurationFactory = new YamlConfigurationFactory<>(
            YamlInstanceConfiguration.class,
            validator,
            objectMapper,
            "dw");
    parseYamlInstanceConfiguration();
}
 
Example #17
Source File: WithConfiguration.java    From breakerbox with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTest() throws Exception {
    azureTableConfiguration = new YamlConfigurationFactory<>(
            AzureTableConfiguration.class,
            Validation.buildDefaultValidatorFactory().getValidator(),
            Jackson.newObjectMapper(),
            "dw.").build(new File(Resources.getResource("azure-test.yml").toURI()));
}
 
Example #18
Source File: DaoProviderUtil.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static PersistenceConfig createConfiguration(File configFile) {
  YamlConfigurationFactory<PersistenceConfig> factory =
      new YamlConfigurationFactory<>(PersistenceConfig.class,
          Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(),
          "");
  PersistenceConfig configuration;
  try {
    configuration = factory.build(configFile);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  return configuration;
}
 
Example #19
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationGeneral1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("Trellis", config.getDefaultName(), "Incorrect app name!");

    // Cache tests
    assertEquals(86400, config.getCache().getMaxAge(), "Incorrect cache/maxAge value!");
    assertFalse(config.getCache().getNoCache(), "Unexpected cache/noCache value!");
    assertTrue(config.getCache().getMustRevalidate(), "Missing cache/mustRevalidate value!");

    // JSON-LD tests
    assertEquals(48L, config.getJsonld().getCacheExpireHours(), "Incorrect jsonld/cacheExpireHours");
    assertEquals(10L, config.getJsonld().getCacheSize(), "Incorrect jsonld/cacheSize");
    assertTrue(config.getJsonld().getContextDomainWhitelist().isEmpty(), "Incorrect jsonld/contextDomainWhitelist");
    assertTrue(config.getJsonld().getContextWhitelist().contains("http://example.com/context.json"),
            "Incorrect jsonld/contextWhitelist value!");

    // Hub tests
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hubUrl");

    // Relative IRI configuration
    assertTrue(config.getUseRelativeIris(), "Incorrect relative IRI configuration");

    // Auth tests
    assertTrue(config.getAuth().getAdminUsers().contains("zoyd"), "zoyd missing from auth/adminUsers");
    assertTrue(config.getAuth().getAdminUsers().contains("wheeler"), "wheeler missing from auth/adminUsers");

    // Other tests
    assertEquals("my.cluster.address", config.any().get("cassandraAddress"), "Incorrect custom property!");
    assertEquals(245994, config.any().get("cassandraPort"), "Incorrect custom Integer property!");
    @SuppressWarnings("unchecked")
    final Map<String, Object> extraConfig = (Map<String, Object>) config.any().get("extraConfigValues");
    assertTrue((Boolean) extraConfig.get("first"), "Incorrect boolean nested custom properties!");
    @SuppressWarnings("unchecked")
    final List<String> list = (List<String>) extraConfig.get("second");
    assertEquals(newArrayList("val1", "val2"), list, "Incorrect nested custom properties as a List!");
}
 
Example #20
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationGeneral1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("Trellis", config.getDefaultName(), "Incorrect default name!");
    assertEquals(86400, config.getCache().getMaxAge(), "Incorrect maxAge!");
    assertTrue(config.getCache().getMustRevalidate(), "Incorrect cache/mustRevalidate value!");
    assertFalse(config.getCache().getNoCache(), "Incorrect cache/noCache value!");
    assertEquals(10L, config.getJsonld().getCacheSize(), "Incorrect jsonld/cacheSize value!");
    assertEquals(48L, config.getJsonld().getCacheExpireHours(), "Incorrect jsonld/cacheExpireHours value!");
    assertFalse(config.getIsVersioningEnabled(), "Incorrect versioning value!");
    assertTrue(config.getJsonld().getContextDomainWhitelist().isEmpty(), "Incorrect jsonld/contextDomainWhitelist");
    assertTrue(config.getJsonld().getContextWhitelist().contains("http://example.org/context.json"),
            "Incorrect jsonld/contextWhitelist value!");
    assertNull(config.getResources(), "Unexpected resources value!");
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hub value!");
    assertEquals(2, config.getBinaryHierarchyLevels(), "Incorrect binaryHierarchyLevels value!");
    assertEquals(1, config.getBinaryHierarchyLength(), "Incorrect binaryHierarchyLength value!");
    assertEquals("my.cluster.node", config.any().get("cassandraAddress"), "Incorrect custom value!");
    assertEquals(245993, config.any().get("cassandraPort"), "Incorrect custom value (2)!");
    @SuppressWarnings("unchecked")
    final Map<String, Object> extraConfig = (Map<String, Object>) config.any().get("extraConfigValues");
    assertTrue((Boolean) extraConfig.get("one"), "Invalid nested custom values as boolean!");
    @SuppressWarnings("unchecked")
    final List<String> list = (List<String>) extraConfig.get("two");
    assertEquals(newArrayList("value1", "value2"), list, "Invalid nested custom values as list!");
}
 
Example #21
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticatorNoKeystore() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    final String nonexistent = resourceFilePath("config1.yml").replaceAll("config1.yml", "nonexistent.yml");
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(nonexistent);
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
            "JWT auth not disabled!");
}
 
Example #22
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticatorBadKeystore() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(resourceFilePath("config1.yml"));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
            "JWT auth not disabled!");
}
 
Example #23
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticatorFederated() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(resourceFilePath("keystore.jks"));
    config.getAuth().getJwt().setKeyIds(asList("trellis", "trellis-ec", "trellis-public"));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof FederatedJwtAuthenticator,
            "JWT auth not enabled!");
}
 
Example #24
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticatorNoKeyIds() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(resourceFilePath("keystore.jks"));
    config.getAuth().getJwt().setKeyIds(asList("foo", "bar"));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
            "JWT auth not disabled!");
}
 
Example #25
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticator() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(resourceFilePath("keystore.jks"));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
            "JWT auth not enabled!");
}
 
Example #26
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwksAuthenticator() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwksAuthenticator,
            "JWT auth not enabled!");
}
 
Example #27
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationCORS1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getCors().getEnabled(), "CORS isn't enabled!");
    assertTrue(config.getCors().getAllowOrigin().contains("*"), "CORS origin not '*'");
    assertTrue(config.getCors().getAllowHeaders().contains("Link"), "Link not in CORS allow-headers!");
    assertTrue(config.getCors().getAllowMethods().contains("PATCH"), "PATCH not in CORS allow-methods!");
    assertTrue(config.getCors().getExposeHeaders().contains("Location"), "Location not in CORS expose-headers!");
    assertEquals(180, config.getCors().getMaxAge(), "incorrect max-age in CORS headers!");
    assertTrue(config.getCors().getAllowCredentials(), "CORS allow-credentials not set!");
}
 
Example #28
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationNamespaces1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("/tmp/trellisData/namespaces.json", config.getNamespaces(), "Incorrect namespace location!");
}
 
Example #29
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationLocations() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("/tmp/trellisData/binaries", config.getBinaries(), "Incorrect binary location!");
    assertEquals("/tmp/trellisData/mementos", config.getMementos(), "Incorrect memento location!");
    assertEquals("http://localhost:8080/", config.getBaseUrl(), "Incorrect base URL!");
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hub URL!");

    final String resources = "http://triplestore.example.com/";
    config.setResources(resources);
    assertEquals(resources, config.getResources(), "Incorrect resource location!");
}
 
Example #30
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationNotifications() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertFalse(config.getNotifications().getEnabled(), "Notifications aren't enabled!");
    assertEquals(NotificationsConfiguration.Type.NONE, config.getNotifications().getType(),
            "Incorrect notification type!");
    assertEquals("example.com:1234", config.getNotifications().getConnectionString(), "Incorrect connect string!");
    assertEquals("foo", config.getNotifications().any().get("some.other.value"), "Incorrect custom value!");
    assertEquals("test", config.getNotifications().getTopicName(), "Incorrect topic name!");
    assertEquals("true", config.getNotifications().any().get("use.queue"), "Incorrect custom value!");
}