Cisco Cisco Security Manager 4.7 Guía Del Usuario
![Cisco](https://files.manualsbrain.com/attachments/7380d0050044647c30f5c24bbbf5d0c0b6d9bb84/common/fit/150/50/faa183d287233c52228cfea3dbc2a127fe780f60564fcb0955d9c3d1cd23/brand_logo.png)
Cisco Security Manager 4.7 API Specification (Version 2.0)
OL- 32164-01
Page 230
prop.load(fis);
String host = prop.getProperty(
String host = prop.getProperty(
"HOST"
);
String payload = prop.getProperty(
"XML_REQUEST"
);
String username = prop.getProperty(
"USER"
);
String password = prop.getProperty(
"PASSWORD"
);
String path = prop.getProperty(
"URI"
);
//If URI is not passed on commandline see if its defined in properties file
URI uri =
new
URI( (args.
length
== 2)?args[1] : path);
String temp = prop.getProperty(
"LOGIN_REQUIRED"
);
boolean
autoLogin =
false
;
if
(
null
!= temp && temp.trim().length() != 0){
autoLogin = Boolean.valueOf(temp);
}
RestClient client =
}
RestClient client =
new
RestClient();
if
(uri.toString().endsWith(
"login"
)){
client.doPost(uri, payload, host,
false
);
}
else
{
//Step 1 :
if
(autoLogin){
String login_payload =
"<?xml version=\"1.0\" encoding=\"UTF-
8\"?><csm:loginRequest
xmlns:csm=\"csm\"><protVersion>1.0</protVersion><reqId>123</reqId><username>"
xmlns:csm=\"csm\"><protVersion>1.0</protVersion><reqId>123</reqId><username>"
+username+
"</usernam
e><password>"
+password+
"</password></csm:loginRequest>"
;
client.doPost(
new
URI(
"https://"
+host+
"/nbi/login"
), login_payload, host,
false
);
}
//Step 2:
client.doPost(uri, payload, host,
true
);
}
}
}
catch
(Exception ex){
System.
out
.println(ex.getMessage()); usage();}
}
public
static
void
usage(){
System.
out
.println(
"Please check the data entered in the properties file"
);
System.
out
.println(
"Usage : "
);
System.
out
.println(
"java RestClient <path_to_client.properties> [<uri>]"
);
}
}
}
9.5 Fetch CSM defined firewall policy
The following simple sample program implemented in java demonstrates a REST client that fetches the CSM
firewall policy as it is defined in the CSM UI. Use the following client.properties file (Change the gid value to
match the GID of a device in the server’s inventory) :
firewall policy as it is defined in the CSM UI. Use the following client.properties file (Change the gid value to
match the GID of a device in the server’s inventory) :
USER=admin
PASSWORD=admin
HOST=localhost
XML_REQUEST=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<csm:policyConfigByDeviceGIDRequest xmlns:csm=\"csm\">\
<protVersion>1.0</protVersion>\
<reqId>123</reqId>\
<gid>00000000-0000-0000-0000-004294967307</gid>\
<policyType>DeviceAccessRuleFirewallPolicy</policyType>\
</csm:policyConfigByDeviceGIDRequest>
# Set LOGIN_REQUIRED to true if the URI supplied
# requires login to be done as a prerequisite.
PASSWORD=admin
HOST=localhost
XML_REQUEST=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<csm:policyConfigByDeviceGIDRequest xmlns:csm=\"csm\">\
<protVersion>1.0</protVersion>\
<reqId>123</reqId>\
<gid>00000000-0000-0000-0000-004294967307</gid>\
<policyType>DeviceAccessRuleFirewallPolicy</policyType>\
</csm:policyConfigByDeviceGIDRequest>
# Set LOGIN_REQUIRED to true if the URI supplied
# requires login to be done as a prerequisite.