After you retrieve an AgentSession object, you can perform session management operations. You can retrieve information about a session, such as session timeout values, the session ID, and the session specification.
The session specification can be used to identify a session across multiple sites, such as for single sign-on operations. You can also retrieve a reason code for a failed authentication or authorization attempt by calling GetReason().
Example: Login in a user
The following example logs in a user, gets a response to the login attempt, retrieves a session object for the user's session, and prints out various details about the session:
use Netegrity::AgentAPI;
#Define script variables
$agent = "agent1";
$secret = "oursecret";
$ip = "127.0.0.1";
$respath = "/mysite/hr/payroll.htm";
$username = "userid";
$pwd = "userpwd";
#Establish the connection and create needed objects
$agentapi = Netegrity::AgentAPI‑>New($agent, $secret);
$serverconfig = $agentapi‑>AddServerConfig($ip);
$agentapi‑>Connect();
$user = $agentapi‑>CreateUser($username, $pwd);
print "Logging in user ".$user‑>Name().".\n";
$resource = $agentapi‑>GetResource($respath);
#Log in the user
$status = $user‑>Login($resource);
if($status==SM_AGENTAPI_YES) {
print $user‑>Name() . " logged in successfully!\n\n";
#Get the login response
$response=$user‑>GetResponse();
#Get the session object
$session=$response‑>GetSession();
if ($session != undef) {
print "Printing session details:\n";
print "Session reason=".$session‑>GetReason()."\n";
print "Session IdleTimeout=".$session‑>IdleTimeout()."\n";
print "Session Maxtimeout=".$session‑>MaxTimeout()."\n";
print "Session ID=".$session‑>GetID()."\n";
print "Session specification=".$session‑>GetSpec()."\n\n";
}
}
else {
print "Couldn't log in user " . $username . "\n\n";
}
| Copyright © 2010 CA. All rights reserved. | Email CA about this topic |