Java Code Examples for com.thoughtworks.xstream.XStream#allowTypes()

The following examples show how to use com.thoughtworks.xstream.XStream#allowTypes() . These examples are extracted from open source projects. 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 Project: gatf   File: AcceptanceTestContext.java    License: Apache License 2.0 6 votes vote down vote up
private void initTestDataProviderAndGlobalVariables() {
	GatfTestDataConfig gatfTestDataConfig = null;
	if(gatfExecutorConfig.getTestDataConfigFile()!=null) {
		File file = getResourceFile(gatfExecutorConfig.getTestDataConfigFile());
		Assert.assertNotNull("Testdata configuration file not found...", file);
		Assert.assertEquals("Testdata configuration file not found...", file.exists(), true);
		
		XStream xstream = new XStream(new DomDriver("UTF-8"));
        XStream.setupDefaultSecurity(xstream);
        xstream.allowTypes(new Class[]{GatfTestDataConfig.class, GatfTestDataProvider.class});
		xstream.processAnnotations(new Class[]{GatfTestDataConfig.class, GatfTestDataProvider.class});
		xstream.alias("gatf-testdata-provider", GatfTestDataProvider.class);
		xstream.alias("args", String[].class);
		xstream.alias("arg", String.class);
		
		gatfTestDataConfig = (GatfTestDataConfig)xstream.fromXML(file);
		gatfExecutorConfig.setGatfTestDataConfig(gatfTestDataConfig);
	} else {
		gatfTestDataConfig = gatfExecutorConfig.getGatfTestDataConfig();
	}
	
	handleTestDataSourcesAndHooks(gatfTestDataConfig);
}
 
Example 2
Source Project: lams   File: DeployConfig.java    License: GNU General Public License v2.0 5 votes vote down vote up
public DeployConfig(String outputPath) {
this.validationError = "";
xstream = new XStream(new DomDriver());
Class<?>[] classes = new Class[] { DeployToolConfig.class, DeployLibraryConfig.class, LearningLibrary.class,
	ToolActivity.class };
xstream.allowTypes(classes);

this.outputPath = outputPath != null ? outputPath : "";
   }
 
Example 3
Source Project: gatf   File: GatfTestGeneratorUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static GatfConfiguration getConfig(InputStream resource)
{
	XStream xstream = new XStream(new DomDriver("UTF-8"));
       XStream.setupDefaultSecurity(xstream);
       xstream.allowTypes(new Class[]{GatfConfiguration.class});
	xstream.processAnnotations(new Class[]{GatfConfiguration.class});
	xstream.alias("testPaths", String[].class);
	xstream.alias("testPath", String.class);
	xstream.alias("soapWsdlKeyPairs", String[].class);
	xstream.alias("soapWsdlKeyPair", String.class);
	xstream.alias("string", String.class);
	
	GatfConfiguration config = (GatfConfiguration)xstream.fromXML(resource);
	return config;
}
 
Example 4
Source Project: gatf   File: GatfTestGeneratorUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getConfigStr(GatfConfiguration configuration)
{
	XStream xstream = new XStream(new DomDriver("UTF-8"));
       XStream.setupDefaultSecurity(xstream);
       xstream.allowTypes(new Class[]{GatfConfiguration.class});
	xstream.processAnnotations(new Class[]{GatfConfiguration.class});
	xstream.alias("testPaths", String[].class);
	xstream.alias("testPath", String.class);
	xstream.alias("soapWsdlKeyPairs", String[].class);
	xstream.alias("soapWsdlKeyPair", String.class);
	xstream.alias("string", String.class);
	
	return xstream.toXML(configuration);
}
 
Example 5
Source Project: gatf   File: XMLTestCaseFinder.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<TestCase> resolveTestCases(File testCaseFile) throws Exception {
	XStream xstream = new XStream(new DomDriver("UTF-8"));
       XStream.setupDefaultSecurity(xstream);
       xstream.allowTypes(new Class[]{TestCase.class});
	xstream.processAnnotations(new Class[]{TestCase.class});
	xstream.alias("TestCases", List.class);
	List<TestCase> xmlTestCases = (List<TestCase>)xstream.fromXML(testCaseFile);
	return xmlTestCases;
}
 
Example 6
Source Project: gatf   File: GatfTestCaseExecutorUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static GatfExecutorConfig getConfig(InputStream resource) {
    XStream xstream = new XStream(new DomDriver("UTF-8"));
    XStream.setupDefaultSecurity(xstream);
    xstream.allowTypes(new Class[] {GatfExecutorConfig.class, GatfTestDataConfig.class, GatfTestDataProvider.class, 
            SeleniumDriverConfig.class, GatfTestDataSourceHook.class, GatfTestDataSource.class});
    xstream.processAnnotations(new Class[] {GatfExecutorConfig.class, GatfTestDataConfig.class, GatfTestDataProvider.class, 
            SeleniumDriverConfig.class, GatfTestDataSourceHook.class, GatfTestDataSource.class});
    xstream.alias("gatf-testdata-source", GatfTestDataSource.class);
    xstream.alias("gatf-testdata-provider", GatfTestDataProvider.class);
    xstream.alias("gatf-testdata-source-hook", GatfTestDataSourceHook.class);
    xstream.alias("gatfTestDataConfig", GatfTestDataConfig.class);
    xstream.alias("seleniumDriverConfigs", SeleniumDriverConfig[].class);
    xstream.alias("seleniumDriverConfig", SeleniumDriverConfig.class);
    xstream.alias("args", String[].class);
    xstream.alias("arg", String.class);
    xstream.alias("testCaseHooksPaths", String[].class);
    xstream.alias("testCaseHooksPath", String.class);
    xstream.alias("queryStrs", String[].class);
    xstream.alias("queryStr", String.class);
    xstream.alias("distributedNodes", String[].class);
    xstream.alias("distributedNode", String.class);
    xstream.alias("ignoreFiles", String[].class);
    xstream.alias("ignoreFile", String.class);
    xstream.alias("orderedFiles", String[].class);
    xstream.alias("orderedFile", String.class);
    xstream.alias("string", String.class);
    xstream.alias("seleniumScripts", String[].class);
    xstream.alias("seleniumScript", String.class);

    GatfExecutorConfig configuration = (GatfExecutorConfig) xstream.fromXML(resource);
    configuration.setJavaVersion(System.getProperty("java.version"));
    return configuration;
}
 
Example 7
Source Project: gatf   File: GatfTestCaseExecutorUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getConfigStr(GatfExecutorConfig configuration) {
    XStream xstream = new XStream(new DomDriver("UTF-8"));
    XStream.setupDefaultSecurity(xstream);
    xstream.allowTypes(new Class[] {GatfExecutorConfig.class, GatfTestDataConfig.class, GatfTestDataProvider.class, 
            SeleniumDriverConfig.class, GatfTestDataSourceHook.class, GatfTestDataSource.class});
    xstream.processAnnotations(new Class[] {GatfExecutorConfig.class, GatfTestDataConfig.class, GatfTestDataProvider.class, 
            SeleniumDriverConfig.class, GatfTestDataSourceHook.class, GatfTestDataSource.class});
    xstream.alias("gatf-testdata-source", GatfTestDataSource.class);
    xstream.alias("gatf-testdata-provider", GatfTestDataProvider.class);
    xstream.alias("gatf-testdata-source-hook", GatfTestDataSourceHook.class);
    xstream.alias("gatfTestDataConfig", GatfTestDataConfig.class);
    xstream.alias("seleniumDriverConfigs", SeleniumDriverConfig[].class);
    xstream.alias("seleniumDriverConfig", SeleniumDriverConfig.class);
    xstream.alias("args", String[].class);
    xstream.alias("arg", String.class);
    xstream.alias("testCaseHooksPaths", String[].class);
    xstream.alias("testCaseHooksPath", String.class);
    xstream.alias("queryStrs", String[].class);
    xstream.alias("queryStr", String.class);
    xstream.alias("distributedNodes", String[].class);
    xstream.alias("distributedNode", String.class);
    xstream.alias("ignoreFiles", String[].class);
    xstream.alias("orderedFiles", String[].class);
    xstream.alias("string", String.class);
    xstream.alias("seleniumScripts", String[].class);
    xstream.alias("seleniumScript", String.class);

    return xstream.toXML(configuration);
}
 
Example 8
/**
 * Sets up the security framework for the passed <code>XStream</code> object.
 *
 * @param xStream the <code>XStream</code> object to set the security framework up for
 * @see <a
 *     href="https://x-stream.github.io/security.html">https://x-stream.github.io/security.html</a>
 */
private static void setUpSecurityFramework(XStream xStream) {
  // forbid all classes by default
  xStream.addPermission(NoTypePermission.NONE);

  // allow default java stuff
  xStream.addPermission(NullPermission.NULL);
  xStream.addPermission(PrimitiveTypePermission.PRIMITIVES);
  xStream.allowTypeHierarchy(Collection.class);
  xStream.allowTypeHierarchy(Map.class);
  xStream.allowTypes(new Class[] {String.class});

  // allow all saros classes
  xStream.allowTypesByWildcard(new String[] {"saros.**"});
}
 
Example 9
Source Project: tutorials   File: App.java    License: MIT License 5 votes vote down vote up
public static App createHardened(int port) {
    final XStream xstream = new XStream();
    xstream.addPermission(NoTypePermission.NONE);
    xstream.addPermission(NullPermission.NULL);
    xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
    xstream.allowTypes(new Class<?>[] { Person.class });
    return new App(port, xstream);
}
 
Example 10
Source Project: gatf   File: GatfTestGeneratorUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception
  {
  	if(args.length>=1) {
  		if(args.length>1 && args[0].equals("-generator") && !args[1].trim().isEmpty())
  		{
   		InputStream io = new FileInputStream(args[1]);
   		XStream xstream = new XStream(new DomDriver("UTF-8"));
           XStream.setupDefaultSecurity(xstream);
           xstream.allowTypes(new Class[]{GatfConfiguration.class});
   		xstream.processAnnotations(new Class[]{GatfConfiguration.class});
   		xstream.alias("testPaths", String[].class);
   		xstream.alias("testPath", String.class);
   		xstream.alias("soapWsdlKeyPairs", String[].class);
   		xstream.alias("soapWsdlKeyPair", String.class);
   		xstream.alias("string", String.class);
   		
   		GatfConfiguration config = (GatfConfiguration)xstream.fromXML(io);
   		
   		GatfTestGeneratorUtil testGenerator = new GatfTestGeneratorUtil();
   		testGenerator.setDebugEnabled(config.isDebugEnabled());
   		testGenerator.setEnabled(config.isEnabled());
   		testGenerator.setRequestDataType(config.getRequestDataType());
   		testGenerator.setTestPaths(config.getTestPaths());
   		testGenerator.setSoapWsdlKeyPairs(config.getSoapWsdlKeyPairs());
   		testGenerator.setUrlPrefix(config.getUrlPrefix());
   		testGenerator.setResourcepath(config.getResourcepath());
   		testGenerator.setOutDataType(config.getResponseDataType()); 
   		testGenerator.setOverrideSecure(config.isOverrideSecure());
   		testGenerator.setUrlSuffix(config.getUrlSuffix());
   		testGenerator.setUseSoapClient(config.isUseSoapClient());
   		testGenerator.setTestCaseFormat(config.getTestCaseFormat());
   		testGenerator.setPostmanCollectionVersion(config.getPostmanCollectionVersion());
   		testGenerator.setOverrideSecure(config.isOverrideSecure());
   		testGenerator.execute();
  		}
  		else if(args.length>1 && (args[0].equals("-executor") || args[0].equals("-selenium")) && !args[1].trim().isEmpty())
  		{
  			GatfTestCaseExecutorUtil.main(args);
  		}
  		else if(args.length>3 && args[0].equals("-configtool") && !args[1].trim().isEmpty() 
  				&& !args[2].trim().isEmpty() && !args[3].trim().isEmpty())
  		{
  			GatfConfigToolUtil.main(args);
  		}
  		else if(args[0].equals("-listener"))
  		{
  			DistributedGatfListener.main(args);
  		}
  		else
  		{
  			System.out.println("Please specify proper arguments to the program - valid invocation options are, \n" +
  					"java -jar gatf-plugin-{version}.jar -generator {generator-config-file}.xml\n" +
  					"java -jar gatf-plugin-{version}.jar -executor {executor-config-file}.xml\n" +
  					"java -jar gatf-plugin-{version}.jar -configtool {http_port} {ip_address} {project_folder}\n" + 
  					"java -jar gatf-plugin-{version}.jar -listener\n");
  		}
  	}
  	else
  	{
	System.out.println("Invalid invocation - valid invocation options are, \n" +
			"java -jar gatf-plugin-{version}.jar -generator {generator-config-file}.xml\n" +
			"java -jar gatf-plugin-{version}.jar -executor {executor-config-file}.xml\n" +
			"java -jar gatf-plugin-{version}.jar -configtool {http_port} {ip_address} {project_folder}\n" + 
			"java -jar gatf-plugin-{version}.jar -listener\n");
}
System.exit(0);
  }
 
Example 11
private static void initWriterSecurity( XStream chartWriter ) {
  XStream.setupDefaultSecurity( chartWriter );
  Class[] allowedTypes = new Class[]{ MqlQuery.class, Query.class };
  chartWriter.allowTypes( allowedTypes );
  chartWriter.allowTypesByWildcard( new String[]{ "org.pentaho.commons.metadata.mqleditor.beans.**" } );
}