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:
curl -H "Accept: text/plain" http://localhost:8080/openptk-server/logout 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:
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:
Engine Resources:
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:
Change attributes of a Subject:CHANGE TITLE AND EMAIL
CHANGE FORGOTTEN PASSWORD QUESTIONS AND ANSWERS
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:Resetcurl -X GET -v -H "Accept: application/json" http://localhost:8080/openptk-server/resources/contexts/Employees-Embed-JDBC/subjects/ja1324/password/reset Changecurl -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 PasswordThe "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 OneJSON
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
$ more cookies.txt
Phase TwoJSON
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
Phase ThreeChange 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
Update Forgotten Password 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 |
Release 2.x > Samples >