private static FramePseudonymizer initMetalPseudonymizerWith(final XMLConfiguration config) throws InvalidKeyException, ClassNotFoundException { Processor processor = new Processor(); List<HierarchicalConfiguration<ImmutableNode>> fields = config.configurationsAt("fields.field"); for (HierarchicalConfiguration field : fields) { List<HierarchicalConfiguration> parameters = field.childConfigurationsAt("algorithm.params"); List<AlgorithmParameter> parameterList = new ArrayList<>(); for (HierarchicalConfiguration parameter : parameters) { parameterList.add(new AlgorithmParameter(parameter.getString("name"), parameter.getString("value"), Class.forName(parameter.getString("type")))); } // Add the transformers processor.addTransformer(Constraints.CONSTRAINT_MAP.get(field.getString("constraint")), field.getString("name"), getParseValueTransformer(ParseValueTransformerFactory.TransformerId.valueOf(field.getString("algorithm.name")), parameterList)); logger.info("Packets containing " + field.getString("name") + " will be pseudonymized based on this constraint: " + field.getString("constraint") + ", with this algorithm "+ field.getString("algorithm.name") ); } // TODO PEF-43: Move and change functionality. if (config.getBoolean("checksum_reset")) { processor.addTransformer(Constraints.IPV4_UDP_DNS, "udpchecksum",new IPv4UDPChecksumCalculator()) .addTransformer(Constraints.IPV6_UDP_DNS, "udpchecksum", new IPv6UDPChecksumCalculator()) .addTransformer(Constraints.IPV4_UDP_DNS, "headerchecksum", new IPv4ChecksumCalculator()) .addTransformer(Constraints.ICMP_DNS, "icmpchecksum", new IPv6UDPChecksumCalculator()); } return new FramePseudonymizer(processor); }
protected ProjectConfig(HierarchicalConfiguration<ImmutableNode> config, @Nullable String metaborgVersion, @Nullable Collection<IExportConfig> sources, @Nullable Collection<LanguageIdentifier> compileDeps, @Nullable Collection<LanguageIdentifier> sourceDeps, @Nullable Collection<LanguageIdentifier> javaDeps) { this(config); if(metaborgVersion != null) { config.setProperty(PROP_METABORG_VERSION, metaborgVersion); } if(sources != null) { config.setProperty(PROP_SOURCES, sources); } if(compileDeps != null) { config.setProperty(PROP_COMPILE_DEPENDENCIES, compileDeps); } if(sourceDeps != null) { config.setProperty(PROP_SOURCE_DEPENDENCIES, sourceDeps); } if(javaDeps != null) { config.setProperty(PROP_JAVA_DEPENDENCIES, javaDeps); } }
/** * Gets the configuration from the given file. * * @param configFile * The configuration file with the configuration. * @return The configuration, or <code>null</code> when no configuration could be retrieved. */ public ConfigRequest<TConfig> getFromConfigFile(FileObject configFile, FileObject rootFolder) { final HierarchicalConfiguration<ImmutableNode> configuration; try { configuration = readConfig(configFile, rootFolder); } catch(ConfigurationException | IOException e) { // @formatter:off final IMessage message = MessageBuilder .create() .withSource(configFile) .withMessage("Unable to read configuration from " + configFile) .withException(e) .build(); // @formatter:on return new ConfigRequest<>(message); } if(configuration != null) { return toConfig(configuration, configFile); } else { return new ConfigRequest<>(); } }
protected LanguageSpecConfig(HierarchicalConfiguration<ImmutableNode> config, ProjectConfig projectConfig, @Nullable LanguageIdentifier id, @Nullable String name, @Nullable Boolean sdfEnabled, @Nullable Sdf2tableVersion sdf2tableVersion, @Nullable Boolean dataDependent, @Nullable String parseTable, @Nullable String completionsParseTable, @Nullable JSGLRVersion jsglrVersion, @Nullable Collection<LanguageContributionIdentifier> langContribs, @Nullable Collection<IGenerateConfig> generates, @Nullable Collection<IExportConfig> exports, @Nullable Collection<String> pardonedLanguages, @Nullable Boolean useBuildSystemSpec) { super(config, projectConfig, id, name, sdfEnabled, parseTable, completionsParseTable, sdf2tableVersion, dataDependent, jsglrVersion, langContribs, generates, exports); if(pardonedLanguages != null) { config.setProperty(PROP_PARDONED_LANGUAGES, pardonedLanguages); } if(useBuildSystemSpec != null) { config.setProperty(PROP_USE_BUILD_SYSTEM_SPEC, useBuildSystemSpec); } }
@SuppressWarnings("unchecked") private <E extends VMwareBalancer<?>> E parseBalancer( HierarchicalConfiguration parent, Class<E> targetClass, Class<? extends E> defaultBalancer, VMwareDatacenterInventory inventory) throws Exception { String balancerClass = parent.getString("balancer[@class]"); Class<?> loadedClass = null; if (balancerClass != null) { loadedClass = this.getClass().getClassLoader() .loadClass(balancerClass); if (!targetClass.isAssignableFrom(loadedClass)) { loadedClass = null; logger.warn("The configured balancer '" + balancerClass + "' is not of type " + targetClass.getSimpleName()); } } if (loadedClass == null) { balancerClass = defaultBalancer.getName(); parent.addProperty("balancer[@class]", balancerClass); loadedClass = defaultBalancer; } HierarchicalConfiguration balancerConfig = parent .configurationAt(ELEMENT_BALANCER); E balancer = (E) loadedClass.newInstance(); balancer.setConfiguration(balancerConfig); balancer.setInventory(inventory); return balancer; }
@Override public void setConfiguration(HierarchicalConfiguration config) { if (config != null) { String storages = config.getString("[@storage]"); if (storages == null || storages.trim().length() == 0) { throw new IllegalArgumentException( "No storage reference defined for balancer"); } String[] elms = storages.split(","); for (String x : elms) { datastoreNames.add(x.toString().trim()); } } }
@Override public void setConfiguration(HierarchicalConfiguration xmlConfig) { if (xmlConfig != null) { String hosts = xmlConfig.getString("[@hosts]"); if (hosts != null) { String[] elms = hosts.split(","); for (String x : elms) { hostNames.add(x.toString().trim()); } } } }
@Test public void testBalancer_noHostsObject() throws Exception { // no host elements should not create an exception HierarchicalConfiguration configuration = Mockito .mock(HierarchicalConfiguration.class); // the mock shall not return a list on getList call Mockito.when(configuration.getList(Matchers.anyString())).thenReturn( null); new EquipartitionHostBalancer().setConfiguration(configuration); // no exception must occur }
@Test(expected = IllegalArgumentException.class) public void testBalancer_noStorageObject() throws Exception { // no storage elements should create an exception HierarchicalConfiguration configuration = Mockito .mock(HierarchicalConfiguration.class); // the mock shall not return a list on getList call Mockito.when(configuration.getList(Matchers.anyString())).thenReturn( null); new EquipartitionStorageBalancer().setConfiguration(configuration); }
protected CommonsConfiguration[] createConfigurations(List<HierarchicalConfiguration<ImmutableNode>> subs) { CommonsConfiguration[] result = new CommonsConfiguration[subs.size()]; for (int i = 0; i < result.length; i++) { result[i] = new CommonsConfiguration((BaseHierarchicalConfiguration) subs.get(i)); } return result; }
private static void testPseudonymizationSettings(final XMLConfiguration config) throws ConfigurationException, IllegalArgumentException, ClassNotFoundException { List<HierarchicalConfiguration<ImmutableNode>> fields = config.configurationsAt("fields.field"); for (HierarchicalConfiguration field : fields) { // Test the name of the field. final String constraint = field.getString("constraint"); final String fieldName = field.getString("name"); final String algorithmName = field.getString("algorithm.name"); if ( (fieldName == null) || (constraint == null) || (algorithmName == null) ) throw new NoSuchElementException("Name of the field, constraint and algoritm needs to be set for each field."); // Test the constraint. if (!Constraints.CONSTRAINT_MAP.containsKey(field.getString("constraint"))) { throw new ConfigurationException(field.getString("constraint") + "should be defined in constraints list (Constraints.java)"); } // TODO PEF-78: Test if the fieldName matches with the context. // TODO PEF-79: No expression support. // Test if the algorithm is part of the configured algorithms. List<HierarchicalConfiguration> parameters = field.childConfigurationsAt("algorithm.params"); List<AlgorithmParameter> parameterList = new ArrayList<>(); //TODO PEF-81: Create here a specific parameter type. for (HierarchicalConfiguration parameter : parameters) { parameterList.add(new AlgorithmParameter(parameter.getString("name"), parameter.getString("value"), Class.forName(parameter.getString("type")))); } final StringBuilder buffer = new StringBuilder(); if (!testParseValueTransformerConfiguration(TransformerId.valueOf(algorithmName), parameterList, buffer)) { throw new ConfigurationException("Error in configuration for algorithm "+ algorithmName + " " + buffer.toString()); } } }
/** * Initializes a new instance of the {@link JacksonConfiguration} class. * * @param factory The Jackson factory to use. * @param config The configuration whose nodes to copy into this configuration. */ protected JacksonConfiguration(final JsonFactory factory, final HierarchicalConfiguration<ImmutableNode> config) { super(config); Preconditions.checkNotNull(factory); this.module = new SimpleModule(); this.mapper = new ObjectMapper(factory); this.mapper.registerModule(this.module); }
@Test public void readConfiguration() throws IOException, ConfigurationException { // Arrange final T sut = create(); final String input = getExampleConfiguration(); // Act final StringReader reader = new StringReader(input); sut.read(reader); final HierarchicalConfiguration<ImmutableNode> objs = sut.configurationAt("listOfObjs(0)", true); // Assert assertThat(sut.getString("name"), is("testName")); assertThat(sut.getString("obj.name"), is("test")); assertThat(sut.getInt("obj.value"), is(1)); assertThat(sut.getString("listOfObjs(0).name"), is("testname")); assertThat(sut.getInt("listOfObjs(0).value"), is(4)); assertThat(sut.getString("listOfObjs(1).name"), is("other")); assertThat(sut.getInt("listOfObjs(1).value"), is(20)); assertThat(sut.getStringArray("listOfObjs.name"), is(new String[]{"testname", "other"})); assertThat(sut.getProperty("nullValue"), is(nullValue())); assertThat(sut.getProperty("emptyList"), is(nullValue())); assertThat(sut.getString("listOfComplexObjs(0).someObj.name"), is("a name")); assertThat(sut.getInt("listOfComplexObjs(0).someObj.value"), is(20)); assertThat(sut.getString("listOfComplexObjs(1).someObj.name"), is("another name")); assertThat(sut.getInt("listOfComplexObjs(1).someObj.value"), is(40)); }
@Override protected ConfigRequest<ISpoofaxLanguageSpecConfig> toConfig(HierarchicalConfiguration<ImmutableNode> config, FileObject configFile) { final SpoofaxProjectConfig projectConfig = new SpoofaxProjectConfig(config); final SpoofaxLanguageSpecConfig languageSpecConfig = new SpoofaxLanguageSpecConfig(config, projectConfig); final MessageBuilder mb = MessageBuilder.create().asError().asInternal().withSource(configFile); final Collection<IMessage> messages = languageSpecConfig.validate(mb); return new ConfigRequest<ISpoofaxLanguageSpecConfig>(languageSpecConfig, messages); }
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(ISpoofaxLanguageSpecConfig config) { if(!(config instanceof IConfig)) { configBuilder.reset(); configBuilder.copyFrom(config); config = configBuilder.build(null); } return ((IConfig) config).getConfig(); }
private LanguageSpecBuildPhase phase(HierarchicalConfiguration<ImmutableNode> config) { final String phaseStr = config.getString("phase"); try { return phaseStr != null ? LanguageSpecBuildPhase.valueOf(phaseStr) : defaultPhase; } catch(IllegalArgumentException e) { logger.warn("Language specification build phase with name {} does not exist, defaulting to {}", e, phaseStr, defaultPhase); return defaultPhase; } }
@Override protected ConfigRequest<IProjectConfig> toConfig(HierarchicalConfiguration<ImmutableNode> config, FileObject configFile) { final ProjectConfig projectConfig = new ProjectConfig(config); final MessageBuilder mb = MessageBuilder.create().asError().asInternal().withSource(configFile); final Collection<IMessage> messages = projectConfig.validate(mb); return new ConfigRequest<IProjectConfig>(projectConfig, messages); }
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(IProjectConfig config) { if(!(config instanceof IConfig)) { configBuilder.reset(); configBuilder.copyFrom(config); config = configBuilder.build((FileObject) null); } return ((IConfig) config).getConfig(); }
public ProjectConfig(HierarchicalConfiguration<ImmutableNode> config) { super(config); // Set metaborgVersion to default if it was not set in the config. if(!config.containsKey(PROP_METABORG_VERSION)) { config.setProperty(PROP_METABORG_VERSION, MetaborgConstants.METABORG_VERSION); } }
protected @Nullable HierarchicalConfiguration<ImmutableNode> configurationAt(String key, boolean supportUpdates) { try { return config.configurationAt(key, supportUpdates); } catch(ConfigurationRuntimeException ex) { return null; } }
/** * Writes the configuration for the given subject. * * @param rootDirectory * The root directory of the subject to set the configuration for. * @param config * The configuration, or <code>null</code> to remove an existing configuration. * @param access */ public void write(FileObject rootDirectory, TConfig config, @Nullable IFileAccess access) throws ConfigException { final FileObject configFile; try { configFile = getConfigFile(rootDirectory); } catch(FileSystemException e) { throw new ConfigException("Unable to locate configuration at root directory " + rootDirectory, e); } if(access != null) { access.write(configFile); } final HierarchicalConfiguration<ImmutableNode> configuration = fromConfig(config); writeConfig(configFile, configuration, rootDirectory); }
@Override protected ConfigRequest<ILanguageComponentConfig> toConfig(HierarchicalConfiguration<ImmutableNode> config, FileObject configFile) { final ProjectConfig projectConfig = new ProjectConfig(config); final LanguageComponentConfig languageComponentConfig = new LanguageComponentConfig(config, projectConfig); final MessageBuilder mb = MessageBuilder.create().asError().asInternal().withSource(configFile); final Collection<IMessage> messages = languageComponentConfig.validate(mb); return new ConfigRequest<ILanguageComponentConfig>(languageComponentConfig, messages); }
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(ILanguageComponentConfig config) { if(!(config instanceof IConfig)) { configBuilder.reset(); configBuilder.copyFrom(config); config = configBuilder.build((FileObject) null); } return ((IConfig) config).getConfig(); }
protected HierarchicalConfiguration<ImmutableNode> cloneConfiguration(IConfig config) { // Clone configuration. final IConfig iconfig = (IConfig) config; final HierarchicalConfiguration<ImmutableNode> apacheConfig = iconfig.getConfig(); final Configuration clonedConfig = ConfigurationUtils.cloneConfiguration(apacheConfig); @SuppressWarnings("unchecked") final HierarchicalConfiguration<ImmutableNode> clonedHierachicalConfig = (HierarchicalConfiguration<ImmutableNode>) clonedConfig; return clonedHierachicalConfig; }
@Override protected ConfigRequest<ILanguageSpecConfig> toConfig(HierarchicalConfiguration<ImmutableNode> config, FileObject configFile) { final ProjectConfig projectConfig = new ProjectConfig(config); final LanguageSpecConfig languageSpecConfig = new LanguageSpecConfig(config, projectConfig); final MessageBuilder mb = MessageBuilder.create().asError().asInternal().withSource(configFile); final Collection<IMessage> messages = languageSpecConfig.validate(mb); return new ConfigRequest<>(languageSpecConfig, messages); }
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(ILanguageSpecConfig config) { if(!(config instanceof IConfig)) { configBuilder.reset(); configBuilder.copyFrom(config); config = configBuilder.build(null); } return ((IConfig) config).getConfig(); }
protected SpoofaxProjectConfig(HierarchicalConfiguration<ImmutableNode> config, String metaborgVersion, Collection<IExportConfig> sources, Collection<LanguageIdentifier> compileDeps, Collection<LanguageIdentifier> sourceDeps, Collection<LanguageIdentifier> javaDeps, Boolean typesmart, NaBL2Config nabl2Config) { super(config, metaborgVersion, sources, compileDeps, sourceDeps, javaDeps); if(typesmart != null) { config.setProperty(PROP_STR_TYPESMART, typesmart); } if(nabl2Config != null) { Optional.ofNullable(configurationAt(PROP_NABL2, true)) .ifPresent(c -> NaBL2ConfigReaderWriter.write(nabl2Config, c)); } }
@Override protected ConfigRequest<ISpoofaxProjectConfig> toConfig(HierarchicalConfiguration<ImmutableNode> config, FileObject configFile) { final SpoofaxProjectConfig projectConfig = new SpoofaxProjectConfig(config); final MessageBuilder mb = MessageBuilder.create().asError().asInternal().withSource(configFile); final Collection<IMessage> messages = projectConfig.validate(mb); return new ConfigRequest<>(projectConfig, messages); }
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(ISpoofaxProjectConfig config) { if(!(config instanceof IConfig)) { configBuilder.reset(); configBuilder.copyFrom(config); config = configBuilder.build((FileObject) null); } return ((IConfig) config).getConfig(); }
public static void write(NaBL2Config nabl2Config, HierarchicalConfiguration<ImmutableNode> config) { if(nabl2Config.incremental()) { config.setProperty(PROP_INCREMENTAL, nabl2Config.incremental()); } if(!nabl2Config.debug().flags().isEmpty()) { config.setProperty(PROP_DEBUG, nabl2Config.debug().flags()); } }
public HostConfig(HierarchicalConfiguration xmlConfig) { this.xmlConfig = xmlConfig; }
public StorageConfig(HierarchicalConfiguration xmlConfig) { this.xmlConfig = xmlConfig; }
public StorageBalancerConfig(HierarchicalConfiguration xmlConfig) { this.xmlConfig = xmlConfig; }
public HostBalancerConfig(HierarchicalConfiguration xmlConfig) { this.xmlConfig = xmlConfig; }
@Override public void setConfiguration(HierarchicalConfiguration xmlConfig) { super.setConfiguration(xmlConfig); }
public SpoofaxLanguageSpecConfig(HierarchicalConfiguration<ImmutableNode> config, SpoofaxProjectConfig projectConfig) { super(config, projectConfig); this.projectConfig = projectConfig; }
public ProjectConfig build(HierarchicalConfiguration<ImmutableNode> configuration) { return new ProjectConfig(configuration, metaborgVersion, sources, compileDeps, sourceDeps, javaDeps); }
@Override protected JacksonConfiguration createNew( @Nullable HierarchicalConfiguration<ImmutableNode> sourceConfiguration) { final JacksonConfiguration config = new YamlConfiguration(sourceConfiguration); config.setConversionHandler(new MetaborgConversionHandler()); return config; }
public AConfig(HierarchicalConfiguration<ImmutableNode> config) { this.config = config; }
@Override public HierarchicalConfiguration<ImmutableNode> getConfig() { return this.config; }