The following examples illustrate some common methods for implementing SPML.
The following example shows a typical AddRequest method.
SpmlClient client = new SpmlClient(); client.setURL("http://example.com:8080/idm/spml"); AddRequest req = new AddRequest(); req.setObjectClass("person"); req.setIdentifier("maurelius"); req.setAttribute("gn", "Marcus"); req.setAttribute("sn", "Aurelius"); req.setAttribute("email", "maurelius@example.com"); SpmlResponse res = client.request(req); if (res.getResult() .equals(SpmlResponse.RESULT_SUCCESS)) System.out.println("Person was successfully created"); |
This section contains two authenticated SPML ModifyRequest examples.
SpmlClient client = new SpmlClient(); client.setURL("http://example.com:8080/idm/spml"); ModifyRequest req = new ModifyRequest(); req.setIdentifier("maurelius"); req.addModification("email", "marcus.aurelius@example.com"); SpmlResponse res = client.request(req); if (res.getResult() .equals(SpmlResponse.RESULT_SUCCESS)) System.out.println("Person was successfully modified");
LighthouseClient client = new LighthouseClient(); client.setURL("http://example.com:8080/idm/spml"); client.setUser("maurelius"); client.setPassword("xyzzy"); ModifyRequest req = new ModifyRequest(); req.setIdentifier("maurelius"); req.addModification("email", "marcus.aurelius@example.com"); SpmlResponse res = client.request(req); if (res.getResult() .equals(SpmlResponse.RESULT_SUCCESS)) System.out.println("Person was successfully modified");
The only difference between these examples is that the second example uses the LighthouseClient class and two additional method calls to client.setUser and client.setPassword. For example, you could use this example to avoid setting a proxy user in Waveset.properties, which results in the audit log reflecting the specified user instead of the proxy user.
This example is authenticated by client.setUser and client.setPassword when the request is sent.
The following example shows a typical SearchRequest method.
SpmlClient client = new SpmlClient(); client.setURL("http://example.com:8080/idm/spml"); SearchRequst req = new SearchRequest(); // specify the attributes to return req.addAttribute("sn"); req.addAttribute("email"); // specify the filter FilterTerm ft = new FilterTerm(); ft.setOperation(FilterTerm.OP_EQUAL); ft.setName("gn"); ft.setValue("Jeff"); req.addFilter(ft); SearchResponse res = (SearchResponse)client.request(req); // display the results List results = res.getResults(); if (results != null) { for (int i = 0 ; i < results.size() ; i++) { SearchResult sr = (SearchResult)results.get(i); System.out.println("Identifier=" + sr.getIdentifierString() + " sn=" + sr.getAttribute("sn") + " email=" + sr.getAttribute("email")); } }