Firewall: Java Examples

FirewallPolicyExtension example

Create a FirewallPolicyExtension object and set the state and rule IDs:

FirewallPolicyExtension firewallPolicyExtension = new FirewallPolicyExtension();
firewallPolicyExtension.setState(FirewallPolicyExtension.StateEnum.ON);
firewallPolicyExtension.setRuleIDs(ruleIDs);

PolicySettings example

Next, create a PolicySettings object to configure Firewall-related settings. (For detailed information about policy settings, see Configure policy and default policy settings.) For example, you can enable reconnaissance scans:

PolicySettings policySettings = new PolicySettings();
SettingValue settingValue = new SettingValue();
settingValue.setValue("true");
policySettings.setFirewallSettingReconnaissanceEnabled(settingValue);

Modify policy example

At this point, the Firewall policy extension and the policy settings are configured. Next, add them to a Policy object, and use a PoliciesApi object to modify a policy on Deep Security Manager.

Policy policy = new Policy();
policy.setFirewall(firewallPolicyExtension);
policy.setPolicySettings(policySettings);

PoliciesApi policiesApi = new PoliciesApi();
Policy returnedPolicy = policiesApi.modifyPolicy(policyID, policy, Boolean.FALSE, apiVersion);

The policy_id (or policyID) parameter of modifyPolicy identifies the actual policy on Deep Security Manager that is to be modified. This policy is modified according to the policy object that is used as the policy parameter. Any properties of the policy parameter that are not set remain unchanged on the actual policy.

Complete policy example

The following example creates a Policy object, modifies its FirewallPolicyExtension, and configures a policy setting. The policy is then updated on Deep Security Manager.

View source

// Turn on Firewall
FirewallPolicyExtension firewallPolicyExtension = new FirewallPolicyExtension();
firewallPolicyExtension.setState(FirewallPolicyExtension.StateEnum.ON);

// Add rules
firewallPolicyExtension.setRuleIDs(ruleIDs);

// Add to the policy
Policy policy = new Policy();
policy.setFirewall(firewallPolicyExtension);

// Turn on Reconnaissance Scan
PolicySettings policySettings = new PolicySettings();
SettingValue settingValue = new SettingValue();
settingValue.setValue("true");
policySettings.setFirewallSettingReconnaissanceEnabled(settingValue);

// Add to the policy
policy.setPolicySettings(policySettings);

// Update the policy on Deep Security Manager
PoliciesApi policiesApi = new PoliciesApi();
return policiesApi.modifyPolicy(policyId, policy, Boolean.FALSE, apiVersion);
Tip:

Also see the Modify a Policy operation in the API Reference.