curl -k -u jsmith:passwd
https://myserver.example.com:8443/cli/application/info
?application=JPetStore
To retrieve a session key, log in to the server as usual. Then, in the web browser, find the value of the header that is named UCD_SESSION_KEY. You can look for the cookie with that name or look at the list of headers that are associated with the web page. The way that you view this information depends on what browser you are using. See the documentation for your web browser for more information.
UCD_SESSION_KEY:sessionKey
Use
the value of the UCD_SESSION_KEY cookie as sessionKey.#!/usr/bin/env python
import urllib2
import json
import base64
import sys
if not len(sys.argv) == 3:
print 'usage: script <username> <password>'
exit(1)
username = sys.argv[1]
password = sys.argv[2]
epass = base64.b64encode(username + ':' + password)
print 'base64 encoded: ' + epass
baseUrl = 'ucdeploy.example.org:8443'
url = 'https://' + baseUrl + '/cli/application/info' + '?application=JPetStore'
opener = urllib2.build_opener(urllib2.HTTPHandler)
req = urllib2.Request(url)
req.add_header('Authorization', 'Basic '+epass)
req.get_method = lambda: 'GET'
resp = opener.open(req)
print resp.read()
import groovyx.net.http.RESTClient
client = new RESTClient( 'https://ucdeploy.example.org:8443/cli/application/info?application=JPetStore' )
client.headers['Authorization'] = 'Basic '+"jsmith:passwd".bytes.encodeBase64()
def resp = client.get( path : 'application' )
println "Status: "+resp.status
assert resp.status == 200
println "ContentType: "+ resp.contentType
println resp.data
The following Java code is a simple example of authenticating with a user name and password. The code accepts all certificates, but you can modify the code to control what certificates are accepted.
This example requires the HttpComponents-Util.jar and uDeployRestClient.jar JAR files. The file HttpComponents-Util.jar is available in the opt folder on the server. The file uDeployRestClient.jar is available in many core plug-ins, such as the UrbanCode Deploy Applications plug-in.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.log4j.Logger;
import com.urbancode.commons.httpcomponentsutil.HttpClientBuilder;
public class RESTExample {
public static void main(String[] args) {
// suppress log4j messages from UCD library
Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
HttpClientBuilder clientBuilder = new HttpClientBuilder();
clientBuilder.setUsername("admin");
clientBuilder.setPassword("admin");
// for SSL enabled servers, accept all certificates
clientBuilder.setTrustAllCerts(true);
DefaultHttpClient client = clientBuilder.buildClient();
try {
HttpGet request = new HttpGet(new URI(
"https://ucdeploy.example.org:8443/cli/application/info?application=JPetStore"));
try {
HttpResponseresp = client.execute(request);
BufferedReaderbr = new BufferedReader (
new InputStreamReader(resp.getEntity().getContent()));
String currentLine = new String();
while ((currentLine = br.readLine()) != null){
System.out.print(currentLine);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
sslProtocol="TLS"
keystoreFile="conf/tomcat.keystore"
keystorePass="changeit" />
keytool -v -list -keystore keyStoreFileName
Use
the name of the keystoreFile attribute from the server.xml file
for keyStoreFileName. When the
command prompts you for a password, specify the value of the keystorePass attribute.
The default value is changeit.Keystore type: JKS
Keystore provider: SUN
Your keystore contains 1 entry
Alias name: server
Creation date: Mar 19, 2014
Entry type: PrivateKeyEntry
In this code, the alias is server.keytool -exportcert
-alias serverAlias
-keystore keyStoreFileName
-storetype jks
-file server.cert
Use the alias of the server for serverAlias.jreLocation\jre\bin\keytool.exe -importcert
-alias serverAlias
-file tomcat.cert
-storetype jks
-keystore jreLocation\jre\lib\security\cacerts
Use
the location of the JRE or JDK for jreLocation.