Cisco Cisco Security Manager 4.5 Guia De Especificação

Página de 217
 
 
 
  
 
Cisco Security Manager 4.4 API Specification (Version 1.1) 
 
OL- 29074-01 
Page  165
 
 
 
 
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 = 
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>"
+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){ex.printStackTrace(); 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>]"
); 
 
 
   
8.3  Fetch CLI configuration of a firewall 
 
The following simple sample program implemented in java demonstrates a REST client program that uses the CSM 
API to fetch the raw CLI configuration of a firewall from CSM’s database.  Use the following client.properties as 
input (change the name of the device to match the device name in the server’s inventory)  :  
 
USER=admin 
PASSWORD=admin 
HOST=localhost 
XML_REQUEST=<?xml version=\"1.0\" encoding=\"utf-8\"?>\ 
<n:deviceConfigByNameRequest xmlns:n=\"csm\"  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\ 
   <protVersion>1.0</protVersion>\ 
   <reqId>123</reqId>\ 
   <name>firewall_device</name>\ 
</n:deviceConfigByNameRequest> 
 
# Set LOGIN_REQUIRED to true if the URI supplied  
# requires login to be done as a prerequisite. 
LOGIN_REQUIRED=true 
URI=https://localhost/nbi/configservice/getDeviceConfigByName 
  
After compiling, use the following command to run the program: