curl -k -u jsmith:passwd
https://myserver.example.com:8443/cli/application/info
?application=JPetStore
セッション鍵を取得するには、通常の手順でサーバーにログインします。その後、Web ブラウザーで UCD_SESSION_KEY という名前のヘッダーの値を探します。その名前の cookie を探すことも、その Web ページに関連付けられているヘッダーのリストを調べることもできます。この情報を確認する方法は、使用しているブラウザーによって異なります。詳細については、使用中の Web ブラウザーの資料を参照してください。
UCD_SESSION_KEY:sessionKey
sessionKey には UCD_SESSION_KEY cookie の値を使用してください。#!/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()
Groovy スクリプトでの 認証の例については、 http://devblog.laraziosi.org/extensibility/index.php/devops-articles/6-getting-started-with-the-ibm-urbancode-deploy-rest-api-and-groovyを参照してください。
以下の Java™ コードは、ユーザー名とパスワードでの認証の簡単な例です。このコードはすべての証明書を受け入れますが、受け入れる証明書を制御するように変更することもできます。
この例では、HttpComponents-Util.jar および uDeployRestClient.jar の各 JAR ファイルが必要です。HttpComponents-Util.jar ファイルは、サーバー上の opt フォルダーにあります。uDeployRestClient.jar ファイルは、UrbanCode Deploy アプリケーション・プラグインなどの、様々なコア・プラグインにあります。
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
keyStoreFileName には、server.xml ファイルにある keystoreFile 属性の名前を使用してください。コマンドでパスワードが求められたら、keystorePass 属性の値を指定します。デフォルト値は changeit です。Keystore type: JKS
Keystore provider: SUN
Your keystore contains 1 entry
Alias name: server
Creation date: Mar 19, 2014
Entry type: PrivateKeyEntry
このコードでは、別名は server です。keytool -exportcert
-alias serverAlias
-keystore keyStoreFileName
-storetype jks
-file server.cert
serverAlias にはサーバーの別名を使用してください。jreLocation¥jre¥bin¥keytool.exe -importcert
-alias serverAlias
-file tomcat.cert
-storetype jks
-keystore jreLocation¥jre¥lib¥security¥cacerts
jreLocation には、JRE または JDK のロケーションを使用します。