How to search the directory for specific information with the Stanford Web Application Toolkit

From Web Services Wiki

Revision as of 18:25, 8 December 2008 by Ddonahue (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Problem

You want to search for specific information within the directory.

Solution

Use StanfordPerson

If you haven't yet, read How to get information about users in the directory with the Stanford Web Application Toolkit, as it is much more straightforward than manually searching the directory and should suit the needs of most applications. The rest of the solutions in this recipe are intended for advanced users who need specific information not provided by the StanfordPerson class.

Getting a particular attribute associated with one SUNetID

Use the get_attr method of StanfordDirectory to query the directory for one attribute associated with a SUNetID.

// Include StanfordDirectory
include_once("stanford.directory.php");
 
// Initialize StanfordDirectory
$directory = new StanfordDirectory();
 
// Get the 'suregid' attribute (get_attr returns a string)
$suregid = $directory->get_attr('my_sunetid', 'suregid');
 
// Close the connection
$directory->disconnect();

Performing a raw search

Use the search method of the StanfordDirectory class to perform a raw LDAP search.

// Include StanfordDirectory
include_once("stanford.directory.php");
 
// Initialize StanfordDirectory
$directory = new StanfordDirectory();
 
// Construct search query
$query = "uid=my_sunetid";
$attributes = array("suregid");
 
// Get results
$result = $directory->search($query, $attributes);
 
// Check results
if($result) {
 
  // Print out the raw search result (for debugging)
  echo '<pre>';
  print_r($result);
  echo '</pre>';
 
  // Extract the information we want
  $suregid = $result[0]['suregid'][0];
 
}
else {
  echo '<p>Unable to find information</p>';
}
 
// Close the connection
$directory->disconnect();

Discussion

Visibility restrictions in the directory

While using StanfordDirectory and StanfordPerson you will encounter users whose information is incomplete (e.g., a missing e-mail address). This may be because the information is simply not available or because it has been explicitly made private by the user or owner of the data. You may use StanfordYou to modify your own visibility within the directory.

Those who are developing applications that require access to private data must petition for more permissions. View the usage policy for more information.

References

Personal tools