Cisco Cisco Security Manager 4.5 Guia De Especificaciones
Cisco Security Manager 4.4 API Specification (Version 1.1)
OL- 29074-01
Page 169
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.4 Executing show access-list on a firewall device
The following simple sample program implemented in java demonstrates a REST client using the CSM API to
execute a show access-list command on a firewall device. Use the following client.properties as input (change the
deviceIP to match the IP of a valid device in the server’s inventory) :
execute a show access-list command on a firewall device. Use the following client.properties as input (change the
deviceIP to match the IP of a valid device in the server’s inventory) :
USER=admin
PASSWORD=admin
HOST=localhost
XML_REQUEST=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<csm:execDeviceReadOnlyCLICmdsRequest xmlns:csm=\"csm\">\
<protVersion>1.0</protVersion>\
<reqId>123</reqId>\
<deviceReadOnlyCLICmd>\
<deviceIP>192.168.1.1</deviceIP>\
<cmd>show</cmd>\
<argument>access-list</argument>\
</deviceReadOnlyCLICmd>\
</csm:execDeviceReadOnlyCLICmdsRequest>
# Set LOGIN_REQUIRED to true if the URI supplied
# requires login to be done as a prerequisite.
LOGIN_REQUIRED=true
URI=https://localhost/nbi/utilservice/execDeviceReadOnlyCLICmds
PASSWORD=admin
HOST=localhost
XML_REQUEST=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<csm:execDeviceReadOnlyCLICmdsRequest xmlns:csm=\"csm\">\
<protVersion>1.0</protVersion>\
<reqId>123</reqId>\
<deviceReadOnlyCLICmd>\
<deviceIP>192.168.1.1</deviceIP>\
<cmd>show</cmd>\
<argument>access-list</argument>\
</deviceReadOnlyCLICmd>\
</csm:execDeviceReadOnlyCLICmdsRequest>
# Set LOGIN_REQUIRED to true if the URI supplied
# requires login to be done as a prerequisite.
LOGIN_REQUIRED=true
URI=https://localhost/nbi/utilservice/execDeviceReadOnlyCLICmds
After compiling, use the following command to run the program:
Command Prompt> java RestClient <path_to_client.properties> [<uri>]
Class
RestClient.java
/**
* Sample program to execute a show access
-
list command on a firewall
*/
import
java.io.ByteArrayInputStream;
import
java.io.IOException;
import
java.net.URI;
import
java.security.KeyManagementException;
import
java.security.NoSuchAlgorithmException;
import
java.security.SecureRandom;
import
java.security.cert.X509Certificate;
import
javax.net.ssl.SSLContext;
import
javax.net.ssl.TrustManager;