Accessing authentication information

From RavenWiki
Revision as of 18:24, 17 September 2006 by jw35 (talk | contribs) (Created - please extend)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The 'Container managed' Authentication Agents, like mod_ucam_webauth and Ucam WebAuth IIS, make authentication information available to scripts and other dynamic content that they protect. The scripts can use this information to make their own authorisation decisions, customise their output, etc.

Here are some example scripts (that just display a single value) to show how to access this information from various environments and languages. Please feel free to extend it with more examples.

for Apache and mod_ucam_webauth

To see what's available, and the names under which it's stored, see section 3, 'Authentication Information', of the mod_ucam_webauth documentation.

CGI and Perl

The information is put into the environment of the CGI script. Exactly how you access it depends on the language of the script. Here's a Perl example:

#!/usr/bin/perl -T
                                                                                
use strict;
use warnings;
                                                                                
print "Content-type: text/html; charset=ISO-8859-1\n";
print "\n";
                                                                                
print "<html>\n";
print "<head>\n";
print "<title>Demo</title>\n";
print "</head>\n";
print "<body>\n";
print "<p>Hi $ENV{REMOTE_USER}, hope you enjoyed the course</p>\n";
print "</body>\n";
print "</html>\n";

PHP

<html>
<head>
<title>Demo</title>
</head>
<body>
<p>Hi <?php echo $_SERVER['REMOTE_USER'] ?>, hope you enjoyed the
course</p>
</body>
</html>

SHTML

You can't include variables in a plain HTML page because Apache doesn't manipulate such files when serving them. However it has a 'Server Parsed HTML' format, provided by mod_include, which can include variables. Here's an example using that:

                    
<html>
<head>
<title>Demo</title>
</head>
<body>
<p>Hi <!--#echo var=REMOTE_USER -->, hope you enjoyed the course</p>
</body>
</html>