Cisco Cisco Security Manager 4.4 Guia De Especificaciones
Cisco Security Manager 4.4 API Specification (Version 1.1)
OL- 29074-01
Page 176
try
{
//Load the basic properties
FileInputStream fis =
null
;
Properties prop =
new
Properties();
fis =
new
FileInputStream(args[0]);
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>]"
);
}
}
}
8.6 List shared policies assigned to all devices
The following simple sample program implemented in java demonstrates a REST client that iterates over CSM’s
device inventory and lists the directly assigned shared policies on all devices. Use the following client.properties
file:
device inventory and lists the directly assigned shared policies on all devices. Use the following client.properties
file:
USER=admin
PASSWORD=admin
HOST=localhost
XML_REQUEST=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<csm:deviceListByCapabilityRequest xmlns:csm=\"csm\">\
<protVersion>1.0</protVersion>\
<reqId>123</reqId>\
PASSWORD=admin
HOST=localhost
XML_REQUEST=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<csm:deviceListByCapabilityRequest xmlns:csm=\"csm\">\
<protVersion>1.0</protVersion>\
<reqId>123</reqId>\