Release 2.x‎ > ‎Samples‎ > ‎

cURL

Introduction

This page demonstrates several examples of using the OpenPTK RESTful interface with the cURL command line utility. The examples below show how to use the HTTP Accept header to request each of the 4 representation outputs supported (JSON, XML, HTML, and text).

Login and Logout:

If a login is not performed prior to performing an operation, an anonymous session will be generated for the request (assuming that anonymous is enabled).

curl -H "Accept: text/plain" http://localhost:8080/openptk-server/login?user=ja1324\&password=Passw0rd\&clientid=identitycentral


curl -H "Accept: text/plain" http://localhost:8080/openptk-server/logout

Login to a specific clientid and store the cookie in a file 

curl -v -c cookies.txt -H "Accept: text/plain" http://localhost:8080/openptk-server/login?user=ja1324\&password=password\&clientid=identitycentral

Get current session from the client used for authentication

curl -X GET -v -b cookies.txt -H "Accept: application/json" http://localhost:8080/openptk-server/resources/sessioninfo

The request above will return the principle id and the context for the current user:

{ "response" : { "uri" : "http:\/\/localhost:8080\/openptk-server\/resources\/sessioninfo", "length" : "1", "sessions" : { "session" : { "uniqueid" : "396afa60-1858-41c9-8ba6-634c7b9d8acc", "type" : "ANON", "principal" : { "uniqueid" : null, "contextid" : null } } } } }

The above will allow the currently logged user to obtain thier REST URI for updates by:

<baseURI>/resources/<contextid>/subjects/<uniqueid>

Where in the above example:

<baseURI>http://localhost:8080/openptk-server
<contextid>Employees-MySQL-JDBC
<uniqueid>ja1324

Engine Resources:

curl -v -c cookies.txt -H "Accept: text/plain" http://localhost:8080/openptk-server/login?user=openptkconfig\&password=password\&clientid=identitycentral

curl -b cookies.txt -H "Accept: text/plain" http://localhost:8080/openptk-server/resources/engine 

Data Encoding:

JSON:

curl -H "Accept: application/json" http://localhost:8080/openptk-server/resources/contexts 

curl -H "Accept: application/json" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC 

curl -H "Accept: application/json" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects 

curl -H "Accept: application/json" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/\?search=John 

curl -H "Accept: application/json" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324

XML:

curl -H "Accept: application/xml" http://localhost:8080/openptk-server/resources/contexts 

curl -H "Accept: application/xml" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC 

curl -H "Accept: application/xml" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ 

curl -H "Accept: application/xml" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/\?search=John 

curl -H "Accept: application/xml" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324

HTML:

curl -H "Accept: text/html" http://localhost:8080/openptk-server/resources/contexts 

curl -H "Accept: text/html" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC 

curl -H "Accept: text/html" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ 

curl -H "Accept: text/html" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/?search=John 

curl -H "Accept: text/html" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324

Plain Text:

curl -H "Accept: text/plain" http://localhost:8080/openptk-server/resources/contexts/ 

curl -H "Accept: text/plain" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC 

curl -H "Accept: text/plain" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ 

curl -H "Accept: text/plain" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/?search=John 

curl -H "Accept: text/plain" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324

Create, Update and Delete Examples:

Create a Subject:

curl -X POST -v -H "Content-Type: application/json" -d '{"subject" : { "attributes" : { "lastname" : "User", "title" : "REST User", "firstname" : "Curl", "telephone" : "123-456-7890", "email" : "curl@openptk.org" }}}' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects 
curl -X POST -v -H "Content-Type: application/xml" -d '<subject><attributes><lastname type="string">User</lastname><title type="string">REST User</title><firstname type="string">Curl</firstname><telephone type="string">123-456-7890</telephone><email type="string">curl@openptk.org</email></attributes></subject>' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects 

Change attributes of a Subject:

CHANGE TITLE AND EMAIL

curl -X PUT -v -H "Content-Type: application/json" -d '{ "subject" : { "attributes" : { "title" : "Jersey (JSR-311) Expert", "email" : "restful@openptk.org" } } }' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324 
curl -X PUT -v -H "Content-Type: application/xml" -d '<subject><attributes><title type="string">Jersey (JSR-311) Expert</title><email type="string">restful@openptk.org</email></attributes></subject>' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324
CHANGE FORGOTTEN PASSWORD QUESTIONS AND ANSWERS

curl -X PUT -v -H "Content-Type: application/json" -d '{ "subject" : { "attributes" : { "forgottenPasswordAnswers" : [ "Smith","Chicago","1234" ], "forgottenPasswordQuestions" : [ "Mothers Maiden Name","City you were born","Last 4 digits of Frequent Flyer" ] } } }' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324 
curl -X PUT -v -H "Content-Type: application/xml" -d '<subject><attributes><forgottenPasswordQuestions type="string"><values><value>Mothers Maiden Name</value><value>City you were born</value><value>Last 4 digits of Frequent Flyer</value></values></forgottenPasswordQuestions><forgottenPasswordAnswers type="string"><values><value>Smith</value><value>Chicago</value><value>1234</value></values></forgottenPasswordAnswers></attributes></subject>' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324

Delete a Subject:

curl -X DELETE -v http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/cuser

Password Management:

Reset

curl -X GET -v -H "Accept: application/json" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/reset

Change

curl -X PUT -v -H "Content-Type: application/json" -d '{ "subject" : { "attributes" : { "password" : "Passw0rd" }}}' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/change 

curl -X PUT -v -H "Content-Type: application/xml" -d '<subject><attributes><password type="string">Passw0rd</password></attributes></subject>' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/change

Forgot Password

The "Forgotten Password" process involves three phases. Each phase of the process requires the same anonymous session ID to be used in order to validate the answers after the questions are returned. The phases include:

Phase Description
One Getting the forgotten questions for the specified user (the subject)
The server gets the questions, from the configured Service/Operation, and returns them using the specified "Accept" data format.
Two Answering the question.
The client returns, back to the server, the initial questions and the answers (in the related order).
The server passes the questions and answers to the configured Service/Operation and gets back true/false. The server returns a success or failure back to the client indicating if the answers were correct, or not.
Three The client can now send the new password to the server. The server sends the new password to the configured Service/Operation

Phase One

JSON
curl -c cookies.txt -v -H "Accept: application/json" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/forgot/questions
XML
curl -c cookies.txt -v -H "Accept: application/xml" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/forgot/questions

Example: Oracle Identity Manager 11g Service

curl -c cookies.txt -v -H "Accept: application/json" http://oim11g:7001/openptk-server/resources/contexts/User-Oracle-OIMClient/subjects/sfehrman/password/forgot/questions
* About to connect() to oim11g port 7001 (#0)
*   Trying 192.168.1.107... connected
* Connected to oim11g (192.168.1.107) port 7001 (#0)
> GET /openptk-server/resources/contexts/User-Oracle-OIMClient/subjects/sfehrman/password/forgot/questions HTTP/1.1
> User-Agent: curl/7.16.4 (i386-apple-darwin9.0) libcurl/7.16.4 OpenSSL/0.9.7l zlib/1.2.3
> Host: oim11g:7001
> Accept: application/json
> 
< HTTP/1.1 200 OK
< Date: Fri, 04 Mar 2011 19:14:33 GMT
< Transfer-Encoding: chunked
< Content-Type: application/json
* Added cookie JSESSIONID="HTw6Nx6Z3PvFnnpF2J70YvLQKf27pvvD9w6pz7Tk9vRnQjJTGzTG!345360256" for domain oim11g, path /, expire 0
< Set-Cookie: JSESSIONID=HTw6Nx6Z3PvFnnpF2J70YvLQKf27pvvD9w6pz7Tk9vRnQjJTGzTG!345360256; path=/; HttpOnly
* Added cookie OPENPTKSESSIONID="d0b9b0a4-9124-4e40-954d-57ec8b25935a" for domain oim11g, path /, expire 0
< Set-Cookie: OPENPTKSESSIONID=d0b9b0a4-9124-4e40-954d-57ec8b25935a; path=/
< X-ORACLE-DMS-ECID: 0000Iu2IjE8Fw000jzwkno1DIRSa0001Wy
< X-Powered-By: Servlet/2.5 JSP/2.1
< 
{
    "response" : {
        "uri" : "http:\/\/oim11g:7001\/openptk-server\/resources\/contexts\/User-Oracle-OIMClient\/subjects\/sfehrman\/password\/forgot\/questions",
        "subject" : {
            "uniqueid" : "SFEHRMAN",
            "attributes" : {
                "forgottenPasswordQuestions" : ["What is your favorite color?","What is your mother's maiden name?","What is the city of your birth?"]
            }
        },
        "state" : "SUCCESS"
    }
}

* Connection #0 to host oim11g left intact
* Closing connection #0
View the contents of the cookie:
$ more cookies.txt 
# Netscape HTTP Cookie File # http://curlm.haxx.se/rfc/cookie_spec.html # This file was generated by libcurl! Edit at your own risk. oim11g FALSE / FALSE 0 JSESSIONID HTw6Nx6Z3PvFnnpF2J70YvLQKf27pvvD9w6pz7Tk9vRnQjJTGzTG!345360256 oim11g FALSE / FALSE 0 OPENPTKSESSIONID d0b9b0a4-9124-4e40-954d-57ec8b25935a

Phase Two

JSON
curl -X PUT -v -b cookies.txt -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "subject" : { "attributes" : { "forgottenPasswordQuestions" : ["Mothers Maiden Name","City you were born","Last 4 digits of Frequent Flyer"], "forgottenPasswordAnswers" : ["Smith","Chicago","1234"] }}}' http://localhost:8080/openptk-server/resources/contextsEmployees-Embed-JDBC/subjects/ja1324/password/forgot/answers
XML
curl -X PUT -v -b cookies.txt -H "Accept: application/xml" -H "Content-Type: application/xml" -d '<subject><attributes><forgottenPasswordQuestions type="string"><values><value>Mothers Maiden Name</value><value>City you were born</value><value>Last 4 digits of Frequent Flyer</value></values></forgottenPasswordQuestions><forgottenPasswordAnswers type="string"><values><value>Smith</value><value>Chicago</value><value>1234</value></values></forgottenPasswordAnswers></attributes></subject>' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/forgot/answers

Example: Oracle Identity Manager 11g Service

curl -X PUT -v -b cookies.txt -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "subject" : { "attributes" : { "forgottenPasswordQuestions" : ["What is your favorite color?","What is your mothers maiden name?","What is the city of your birth?"], "forgottenPasswordAnswers" : ["blue","smith","chicago"] }}}' http://oim11g:7001/openptk-server/resources/contexts/User-Oracle-OIMClient/subjects/sfehrman/password/forgot/answers

* About to connect() to oim11g port 7001 (#0) * Trying 192.168.1.107... connected * Connected to oim11g (192.168.1.107) port 7001 (#0) > PUT /openptk-server/resources/contexts/User-Oracle-OIMClient/subjects/sfehrman/password/forgot/answers HTTP/1.1 > User-Agent: curl/7.16.4 (i386-apple-darwin9.0) libcurl/7.16.4 OpenSSL/0.9.7l zlib/1.2.3 > Host: oim11g:7001 > Cookie: OPENPTKSESSIONID=d32b5799-d1c4-49fb-b6d5-06396e215ad8; JSESSIONID=TfvJNx2Sd56YQ81y0dBJZZhhyVWVJmQsLPYLjxwKsrKHMx4nQy1k!345360256 > Accept: application/json > Content-Type: application/json > Content-Length: 227 > < HTTP/1.1 200 OK < Date: Fri, 04 Mar 2011 19:32:37 GMT < Transfer-Encoding: chunked < Content-Type: application/json < X-ORACLE-DMS-ECID: 0000Iu2MrvCFw000jzwkno1DIRSa0001X1 < X-Powered-By: Servlet/2.5 JSP/2.1 < { "response" : { "uri" : "http:\/\/oim11g:7001\/openptk-server\/resources\/contexts\/User-Oracle-OIMClient\/subjects\/sfehrman\/password\/forgot\/answers", "status" : "Input matches answers", "state" : "SUCCESS" } } * Connection #0 to host oim11g left intact * Closing connection #0

Phase Three

Change the password with an http PUT on the password/change uri for a subject.

curl -X PUT -v -b cookies.txt -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "subject" : { "attributes" : { "password" : "Passw0rd" }}}' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/forgot/change 

curl -X PUT -v -b cookies.txt -H "Accept: application/json" -H "Content-Type: application/xml" -d '<subject><attributes><password type="string">Passw0rd</password></attributes></subject>' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/forgot/change

Example: Oracle Identity Manager 11g Service

curl -X PUT -v -b cookies.txt -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "subject" : { "attributes" : { "password" : "Passw0rd" }}}' http://oim11g:7001/openptk-server/resources/contexts/User-Oracle-OIMClient/subjects/sfehrman/password/forgot/change

* About to connect() to oim11g port 7001 (#0) * Trying 192.168.1.107... connected * Connected to oim11g (192.168.1.107) port 7001 (#0) > PUT /openptk-server/resources/contexts/User-Oracle-OIMClient/subjects/sfehrman/password/forgot/change HTTP/1.1 > User-Agent: curl/7.16.4 (i386-apple-darwin9.0) libcurl/7.16.4 OpenSSL/0.9.7l zlib/1.2.3 > Host: oim11g:7001 > Cookie: OPENPTKSESSIONID=d32b5799-d1c4-49fb-b6d5-06396e215ad8; JSESSIONID=TfvJNx2Sd56YQ81y0dBJZZhhyVWVJmQsLPYLjxwKsrKHMx4nQy1k!345360256 > Accept: application/json > Content-Type: application/json > Content-Length: 60 > < HTTP/1.1 200 OK < Date: Fri, 04 Mar 2011 19:35:47 GMT < Transfer-Encoding: chunked < Content-Type: application/json < X-ORACLE-DMS-ECID: 0000Iu2NaCkFw000jzwkno1DIRSa0001X4 < X-Powered-By: Servlet/2.5 JSP/2.1 < { "response" : { "uniqueid" : "sfehrman", "state" : "SUCCESS", "status" : "Password Changed", "status" : "Password Changed" } } * Connection #0 to host oim11g left intact * Closing connection #0

Update Forgotten Password Questions:


Be Advsed
Some of the OpenPTK Service / Operation implementations may not support the setting of Forgotten Questions.
JSON
curl -X PUT -v -H "Content-Type: application/json" -d '{"subject" : { "attributes" : {"forgottenPasswordQuestions" : ["Mothers Maiden Name","City you were born","Last 4 digits of Frequent Flyer"], "forgottenPasswordAnswers" : ["Smith","Denver","5555"]}}}' http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324