Search firewall rules: Java example
Use the following steps to compile and run the class
-
Create a file named FirstStepsPostExample.java and copy the following example
code to the file.
package com.trendmicro.deepsecurity.docs; import com.trendmicro.deepsecurity.ApiClient; import com.trendmicro.deepsecurity.ApiException; import com.trendmicro.deepsecurity.Configuration; import com.trendmicro.deepsecurity.api.FirewallRulesApi; import com.trendmicro.deepsecurity.auth.ApiKeyAuth; import com.trendmicro.deepsecurity.model.FirewallRule; import com.trendmicro.deepsecurity.model.FirewallRules; import com.trendmicro.deepsecurity.model.SearchCriteria; import com.trendmicro.deepsecurity.model.SearchFilter; public class FirstStepsPostExample { /* * Searches for firewall rules that contain 'DHCP' in the name. */ public static void main(String[] args){ // Create the client ApiClient dsmClient = Configuration.getDefaultApiClient(); dsmClient.setBasePath("https:// 192.168.60.128:4119/api"); ApiKeyAuth DefaultAuthentication = (ApiKeyAuth) dsmClient.getAuthentication("DefaultAuthentication"); DefaultAuthentication.setApiKey("3:fkZjcAuvj9ZWhdXgVvFl4Q3DymDZTKHOE3EDDqYPwdg="); // Create the search criteria SearchCriteria searchCriteria = new SearchCriteria(); searchCriteria.setFieldName("name"); searchCriteria.setStringValue("%DHCP%"); searchCriteria.setStringTest(SearchCriteria.StringTestEnum.EQUAL); searchCriteria.setStringWildcards(true); // Create the search filter SearchFilter searchFilter = new SearchFilter(); searchFilter.addSearchCriteriaItem(searchCriteria); // Use FirewallRulesApi to search FirewallRulesApi fwRulesApi = new FirewallRulesApi(); try { FirewallRules fwrules = fwRulesApi.searchFirewallRules(searchFilter, "v1"); for (FirewallRule fwrule : fwrules.getFirewallRules()){ System.out.println(fwrule.getName()); } } catch (ApiException e) { e.printStackTrace(); } } }
-
Locate the following code and change the URL and API key secret according to
your environment:
-
dsmClient.setBasePath("https://192.168.60.128:4119/api");
-
DefaultAuthentication.setApiKey("3:/tiKl3+6ritnk4tQXipq5ufIls5nCFqoGoUcWl+imTU=");
-
-
To compile the Java class, open a Command Prompt (Windows) or terminal and
enter the following command:
javac -d . -cp <path to java client library> FirstStepsPostExample.java
-
To execute the class, enter the following command:
-
Windows:
java -cp ".;<path to java client library>" com.trendmicro.ds.docs.api_examples.FirstStepsPostExample
-
Windows:
java -cp ".;<:path to java client library>" com.trendmicro.ds.docs.api_examples.FirstStepsPostExample
-