Previous
The Profiles Administration API was designed as an alternative to Tivoli Directory Integrator (TDI) for managing users in the IBM Connections database repository. The Profiles Administration API serves a different purpose than the regular Profiles API. The regular Profiles API is designed to work with only the authenticated user. The Profiles Administration API can be used to create, update, or delete users similar to the functions of TDI. For some environments, the Profiles Administration API could replace Tivoli Directory Integrator, but typically, the two will work in conjunction.
Much like the other APIs, the Profiles Administration API uses a REST-style interface. As such, the Abdera library provides most of the functionality to work with this API.
Before using the Profiles Administration API, a user has to be mapped to the "admin" role in the Profiles application. Only users with the admin role can use the Profiles Administration API. To add a user to the admin role in the Profiles application, open the WebSphere Application Server Administrative Console. Navigate to the security role mapping form for the Profiles application by selecting
Applications -> Application Types -> WebSphere enterprise applications -> Profiles, and then
Security role to user or group mapping as shown in the following screen:
The following sample code retrieves an existing user using an email address parameter:
Abdera abdera = new Abdera();
AbderaClient client = new AbderaClient(abdera);
AbderaClient.registerTrustManager();
client.addCredentials("http://servername", null, null, new UsernamePasswordCredentials("user","password"));
ClientResponse resp = client.get("http://servername/profiles/admin/atom/profileService.do");
Document<Service> service_doc = resp.getDocument();
Service service = service_doc.getRoot();
Collection collection = service.getCollection("Profiles Administration Workspace", "All User Profiles");
String coll_uri = collection.getResolvedHref().toASCIIString() + "?email=" + emailAddress;
resp = client.get(coll_uri);
switch(resp.getType()) {
case SUCCESS:
Document<Element> doc = resp.getDocument();
doc.writeTo(System.out);
break;
default:
System.out.println("Error: " + resp.getStatusText());
}
The following code creates a user from a profile document:
Abdera abdera = new Abdera();
AbderaClient client = new AbderaClient(abdera);
AbderaClient.registerTrustManager();
client.addCredentials("http://servername", null, null, new UsernamePasswordCredentials("user","password"));
ClientResponse resp = client.get("http://servername/profiles/admin/atom/profileService.do");
Document<Service> service_doc = resp.getDocument();
Service service = service_doc.getRoot();
Collection collection = service.getCollection("Profiles Administration Workspace", "All User Profiles");
String coll_uri = collection.getResolvedHref().toASCIIString() + "?email=user@domain.com";
Entry entry = abdera.newEntry();
entry.setId("ignored");
entry.addCategory("http://www.ibm.com/xmlns/prod/sn/type", "profile", null);
try {
File f = new File("NewProfile.xml");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
StringBuffer sb = new StringBuffer();
String eachLine = br.readLine();
while (eachLine != null) {
sb.append(eachLine);
sb.append("\n");
eachLine = br.readLine();
}
entry.setContent(sb.toString(),Type.XML);
} catch (Exception e) {
e.printStackTrace();
}
resp = client.post(coll_uri, entry);
switch(resp.getType()) {
case SUCCESS:
System.out.println("New profile created.");
break;
default:
System.out.println("Error: " + resp.getStatusText());
}
The Profiles Administration API can also be used to update a user. Note that when updating a user, all attributes should be passed to the API. So, first retrieve the user's profile document. Then after making updates to the profile document, post the new document using the same procedure used to add the user. The following is a sample profile document:
<person xmlns="http://ns.opensocial.org/2008/opensocial">
<com.ibm.snx_profiles.attrib>
<entry>
<key>com.ibm.snx_profiles.base.distinguishedName</key>
<value>
<type>text</type>
<data>CN=Frank Adams,o=Renovations</data>
</value>
</entry>
<entry>
<key>com.ibm.snx_profiles.base.guid</key>
<value>
<type>text</type>
<data>E514AA26290C91108525688600530CA2</data>
</value>
</entry>
<entry>
<key>com.ibm.snx_profiles.base.uid</key>
<value>
<type>text</type>
<data>fadams</data>
</value>
</entry>
<entry>
<key>com.ibm.snx_profiles.base.givenName</key>
<value>
<type>text</type>
<data>Frank</data>
</value>
</entry>
<entry>
<key>com.ibm.snx_profiles.base.surname</key>
<value>
<type>text</type>
<data>Adams</data>
</value>
</entry>
<entry>
<key>com.ibm.snx_profiles.base.email</key>
<value>
<type>text</type>
<data>frank.adams@ibmdemo.com</data>
</value>
</entry>
<entry>
<key>com.ibm.snx_profiles.base.displayName</key>
<value>
<type>text</type>
<data>Frank Adams</data>
</value>
</entry>
</com.ibm.snx_profiles.attrib>
</person>
It is important to note that extension attributes are available through the Profiles Administration API. Extension attributes can be retrieved and updated using the Profiles Administration API.
Parent topic:
9.0 Using the API