Step 2: Get user information
Now that we have a list of users, we can use websignon to lookup information about each user, such as their name, department, etc. An example response from websignon will look something like this:
urn:mace:dir:attribute-def:eduPersonTargetedID=gqu2d8w3ha5ofg6i2r8nssco
logindisabled=FALSE
warwickitsclass=Staff
warwickyearofstudy=0
lastname=Mannion
id=0672089
staff=true
urn:websignon:usertype=Staff
student=false
urn:mace:dir:attribute-def:eduPersonScopedAffiliation=member@warwick.ac.uk
deptcode=IN
name=Mathew Mannion
warwickstatuscode=C
dept=Information Technology Services
dn=cn=cuscav,ou=CU,o=Warwick
warwickcoursecode=G503
warwickenrolementstatus=F
member=true
deptshort=IT Services
urn:websignon:usersource=WarwickNDS
warwickfinalyear=Y
urn:mace:dir:attribute-def:eduPersonAffiliation=member
warwickcategory=U
firstname=Mathew
returnType=4
email=M.Mannion@warwick.ac.uk
warwickattendancemode=F
user=cuscav
We can very quickly call this API and get some user information out:
/**
* Retrieve user information for the specified usercode.
*
* Note: This is a very simplistic way of accessing the response from
* websignon, and is used only for demonstration purposes. A better
* parsing solution should be used in a production environment.
*/
public User getUserInformation(String usercode) {
// The URL to get the information from
String url =
"https://websignon.warwick.ac.uk/sentry?requestType=4&user=" + usercode;
Request request = new Request(url, GET);
// set the user-agent string to something identifiable so that if there
// is a problem with the way I am calling the API I can be contacted.
request.addHeader("User-Agent",
"Mat Mannion (M.Mannion@warwick.ac.uk), IT Services, x74433");
String response = doHTTPCall(request);
Map params = map(response, '=');
User user = new User();
['id','user','student','staff','name','dept','warwickcategory','warwickyearofstudy'].each(String parameter) {
user[parameter] = params[parameter];
};
return user;
}