When a user attempts to log into a site and access a protected resource, the agent typically needs to answer the following questions:
The following script illustrates how you can use the Agent API to address and respond to these basic agent questions:
use Netegrity::AgentAPI;
#Define script variables
$agent = "agent1";
$secret = "oursecret";
$ip = "127.0.0.1";
$respath = "/mysite/hr/payroll.htm";
$username = "userid";
$pwd = "userpwd";
print "\nStep 1. Connecting to Policy Server...\n";
$agentapi = Netegrity::AgentAPI‑>New($agent, $secret);
$serverconfig = $agentapi‑>AddServerConfig($ip);
$status=$agentapi‑>Connect();
die "FATAL: Connect() failed with error code " .
$status unless($status==SM_AGENTAPI_YES);
$resource = $agentapi‑>GetResource($respath);
print "\nStep 2. Is the resource protected?\n";
if ($resource‑>IsProtected == SM_AGENTAPI_YES) {
print "Resource ".$respath." is protected.\n\n";
print "\nStep 3. User login...\n";
$user = $agentapi‑>CreateUser($username, $pwd);
print "Logging in user ".$user‑>Name().".\n";
$status = $user‑>Login($resource);
if($status==SM_AGENTAPI_YES) {
print $user‑>Name() . " logged in successfully!\n\n";
print "\nStep 4. User authorized for the resource?\n";
$status = $user‑>IsAuthorized($resource);
if($status==SM_AGENTAPI_YES) {
print $user‑>Name()." is authorized for " .
$respath . "\n\n";
}
else {
print $user‑>Name()." is not authorized for " .
$respath . "\n\n";
}
}
else {
print "Couldn't log in user " . $username . ".\n\n";
}
}
else {
print "Resource ".$respath." is not protected.\n\n";
}
| Copyright © 2010 CA. All rights reserved. | Email CA about this topic |