Update Attribute
This section provides developers with information on how to update a specified attribute. Documentation for the REST protocol, as well as code samples for Java, PHP, and cURL, are provided below.
REST
The REST noun (and associated message content) for how to update a specified attribute is as follows:
- Relative Noun: AuthenticatedSession/$sessionID/Entity/$entityID/Attribute/$attrID. This is the relative path of the URL that should appear after the OTIS server application name. Below is an example of updating the phoneNumber attribute on the john.doe entity:
AuthenticatedSession/78BD660E0E5F673378BD660E0E5F6733/Entity/john.doe/Attribute/phoneNumber
NOTE: Actual attribute IDs are likely to be full URIs, and would need to be URL encoded. For example, the attribute:http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname
would be encoded asAttribute/http%3A%252F%252Fschemas.xmlsoap.org%252Fws%252F2005%252F05%252Fidentity%252Fclaims%252Fgivenname
IMPORTANT NOTE ON ENCODING: Characters which have special meanings in URLs (such as '/', '?', and '&') may need to be double encoded in order to ensure that they arrive at OTIS still encoded. This is because web servers often decode the URL before handing it to a web service application (like OTIS). In the example above you will see some %252F encodings. If a web server decodes this before handing it to OTIS, it will appear in the URL as %2F (because %25 decodes to %). If we had simply put %2F in the URL, the web server would have decoded it to '/', which would cause OTIS to improperly parse the URL's path component. Similar arguments could be made about encodings for the '?' and '&' characters.
- HTTP Method: PUT.
- Request/Response message details: <AttributeChange> element details.
- Description: Updates the specified attribute (typically adds or deletes values) on the specified entity.
Java
The following is example Java code that demonstrates how to update a specified attribute:
IAttribute stateorprovince = example.getAttribute(new URI("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/stateorprovince"));
ISimpleAttrValue value = (ISimpleAttrValue)stateorprovince.getValues().next();
value.setData("UT");
example.removeAttribute(new URI("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dateofbirth"));
session.applyUpdates();
To view the complete Java sample code for Attribute/Entity nouns, see the Entity/Attribute Java Sample Code page.
The OTIS client Java library may be downloaded from the OTIS download page.
PHP
The following is example PHP code that demonstrates how to update a specified attribute:
//Update an attribute directly (Noun is in the form of AuthenticatedSession/$sessionID/Entity/$entityID/Attribute/$attrID)
echo attributeRequest($URL, $sessionSecret,
"Entity/example/Attribute/http%3A%252F%252Fschemas.xmlsoap.org%252Fws%252F2005%252F05%252Fidentity%252Fclaims%252Femailaddress");
function attributeRequest($URL, $secret, $URI){
$xml =
'<idas:AttributeChange xmlns:idas="http://www.eclipse.org/higgins/idas/rest-xml/2008/6">
<idas:AttributeValue valType="http://www.w3.org/2001/XMLSchema#string">
<idas:SimpleData>quinw@gmail.com</idas:SimpleData>
</idas:AttributeValue>
</idas:AttributeChange>';
$length = strlen($xml);
$putHeader =
"PUT $URL/$URI HTTP/1.1\n".
"Host: wag.bandit-project.org\n".
(($secret) ? ("SessionSecret: " . $secret . "\n") : "") .
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $length\n".
"Connection: Close\n\n".
"$xml\n";
$socket = fsockopen("wag.bandit-project.org", 80);
fputs($socket, $putHeader);
$content = "";
while(!feof($socket))$content .= fgets($socket, 2048);
return $content;
}
//-----------------------------------------------------------------------
//OR: By updating an Entity
$xml =
'<idas:EntityChange xmlns:idas="http://www.eclipse.org/higgins/idas/rest-xml/2008/6">
<idas:AttributeChange attrID="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress">
<idas:AttributeValue valType="http://www.w3.org/2001/XMLSchema#string">
<idas:SimpleData>quinw@gmail.com</idas:SimpleData>
</idas:AttributeValue>
</idas:AttributeChange>
</idas:EntityChange>';
$length = strlen($xml);
$updateHeader =
"PUT $URL/Entity/example HTTP/1.1\n".
"Host: wag.bandit-project.org\n".
(($sessionSecret) ? ("SessionSecret: " . $sessionSecret . "\n") : "") .
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $length\n".
"Connection: Close\n\n".
"$xml\n";
$socket = fsockopen("wag.bandit-project.org", 80);
fputs($socket, $updateHeader);
To view the complete PHP sample code for Attribute/Entity nouns, see the Entity/Attribute PHP Sample Code page.
cURL
The following sample code updates a user's email address (note that this code includes line continuations that work on Linux):
if [ -e secret.hdr ] ; then secret=`cat secret.hdr` ; else secret="nosecret: none" ; fi
curl -b cookies.txt -H "${secret}" -X PUT -d \
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<tns:AttributeChange xmlns:tns=\"http://www.eclipse.org/higgins/idas/rest-xml/2008/6\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.eclipse.org/higgins/idas/rest-xml/2008/6 ../rest-xml.xsd \"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
<tns:AttributeValue valType=\"http://www.w3.org/2001/XMLSchema#string\">
<tns:SimpleData xsi:type=\"xsd:string\">otis1@gmail.com</tns:SimpleData>
</tns:AttributeValue>
<tns:AttributeValue valType=\"http://www.w3.org/2001/XMLSchema#string\">
<tns:SimpleData xsi:type=\"xsd:string\">otis2@gmail.com</tns:SimpleData>
</tns:AttributeValue>
<tns:AttributeValue valType=\"http://www.w3.org/2001/XMLSchema#string\">
<tns:SimpleData xsi:type=\"xsd:string\">otis3@gmail.com</tns:SimpleData>
</tns:AttributeValue>
</tns:AttributeChange>" \
https://wag.bandit-project.org/otis/Entity/otistest/Attribute/http%3A%252F%252Fschemas.xmlsoap.org%252Fws%252F2005%252F05%252Fidentity%252Fclaims%252Femailaddress