Commit 17b2008c authored by Clément OUDOT's avatar Clément OUDOT

Use Bootstrap for CAS test page (#LEMONLDAP-774)

git-svn-id: svn://svn.forge.objectweb.org/svnroot/lemonldap/branches/lemonldap-ng_version_1_4-bugfixes@3571 1dbb9719-a921-0410-b57f-c3a383c2c641
parent f8520303
......@@ -6,13 +6,25 @@ use CGI;
use AuthCAS;
# Configuration
my $cas_url = 'https://auth.example.com/cas';
my $portal_url = "https://auth.example.com";
my $cas_url = "$portal_url/cas";
my $cas = new AuthCAS( casUrl => $cas_url );
my $cgi = new CGI;
my $pgtUrl = $cgi->url() . "%3Fproxy%3D1";
my $pgtFile = '/tmp/pgt.txt';
my $proxiedService = 'http://webmail';
# CSS
my $css = <<EOT;
html,body{
height:100%;
background:#ddd;
}
#content{
padding:20px;
}
EOT
# Act as a CAS proxy
$cas->proxyMode( pgtFile => '/tmp/pgt.txt', pgtCallbackUrl => $pgtUrl );
......@@ -31,64 +43,123 @@ if ( $cgi->param('proxy') ) {
else {
print $cgi->start_html('CAS sample client');
print "<!DOCTYPE html>\n";
print
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
print "<head>\n";
print "<title>CAS sample client</title>\n";
print
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
print
"<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" />\n";
print "<meta http-equiv=\"cache-control\" content=\"no-cache\" />\n";
print
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n";
print
"<link href=\"$portal_url/skins/bootstrap/css/bootstrap.css\" rel=\"stylesheet\">\n";
print
"<link href=\"$portal_url/skins/bootstrap/css/bootstrap-theme.css\" rel=\"stylesheet\">\n";
print "<style>\n";
print "$css\n";
print "</style>\n";
print
"<script type=\"text/javascript\" src=\"/skins/common/js/jquery-1.10.2.js\"></script>\n";
print
"<script type=\"text/javascript\" src=\"/skins/common/js/jquery-ui-1.10.3.custom.js\"></script>\n";
print
"<script src=\"$portal_url/skins/bootstrap/js/bootstrap.js\"></script>\n";
print "</head>\n";
print "<body>\n";
print "<div id=\"content\" class=\"container\">\n";
print "<div class=\"panel panel-info panel-body\">\n";
print "<div class=\"page-header\">\n";
print "<h1 class=\"text-center\">CAS sample client</h1>\n";
print "</div>\n";
my $ticket = $cgi->param('ticket');
# First time access
unless ($ticket) {
print $cgi->h1("Click below to use CAS");
print $cgi->h2("<a href=\"$login_url\">Simple login</a>");
print $cgi->h2("<a href=\"$login_url&renew=true\">Renew login</a>");
print $cgi->h2("<a href=\"$login_url&gateway=true\">Gateway login</a>");
print
"<h3 class=\"text-center\">Login on <a href=\"$cas_url\">$cas_url</a></h3>\n";
print "<div class=\"text-center\">\n";
print
"<a href=\"$login_url\" class=\"btn btn-info\" role=\"button\">Simple login</a>\n";
print
"<a href=\"$login_url&renew=true\" class=\"btn btn-warning\" role=\"button\">Renew login</a>\n";
print
"<a href=\"$login_url&gateway=true\" class=\"btn btn-success\" role=\"button\">Gateway login</a>\n";
print "</div>\n";
}
# Ticket receveived
else {
print $cgi->h1("CAS login done");
print $cgi->h2("Service ticket: $ticket");
print "<div class=\"panel panel-info\">\n";
print "<div class=\"panel-heading\">\n";
print "<h2 class=\"panel-title text-center\">CAS login result</h2>\n";
print "</div>\n";
print "<div class=\"panel-body\">\n";
print $cgi->h4("Service ticket: $ticket");
# Get user
my $user = $cas->validateST( $cgi->url(), $ticket );
if ($user) {
print $cgi->h2("Authenticated user: $user");
print $cgi->h4("Authenticated user: $user");
}
else {
print $cgi->h2( "Error: " . &AuthCAS::get_errors() );
print "<div class=\"alert alert-danger\"><strong>Error:</strong> "
. &AuthCAS::get_errors()
. "</div>\n";
}
# Get proxy granting ticket
my $pgtId = $cas->{pgtId};
if ($pgtId) {
print $cgi->h2("Proxy granting ticket: $pgtId");
print $cgi->h4("Proxy granting ticket: $pgtId");
# Try to request proxy ticket
my $pt = $cas->retrievePT($proxiedService);
if ($pt) {
print $cgi->h2("Proxy ticket: $pt");
print $cgi->h4("Proxy ticket: $pt");
# Use proxy ticket
my ( $puser, @proxies ) =
$cas->validatePT( $proxiedService, $pt );
print $cgi->h2("Proxied user: $puser");
print $cgi->h2("Proxies used: @proxies");
print $cgi->h4("Proxied user: $puser");
print $cgi->h4("Proxies used: @proxies");
}
else {
print $cgi->h2( "Error: " . &AuthCAS::get_errors() );
print
"<div class=\"alert alert-danger\"><strong>Error:</strong> "
. &AuthCAS::get_errors()
. "</div>\n";
}
}
else {
print $cgi->h2("Error: Unable to get proxy granting ticket");
print
"<div class=\"alert alert-danger\"><strong>Error:</strong> Unable to get proxy granting ticket</div>\n";
}
print $cgi->h2( "<a href=\"" . $cgi->url . "\">Home</a>" );
print "</div>\n";
print "</div>\n";
print
"<div class=\"text-center\"><a class=\"btn btn-info\" role=\"button\" href=\""
. $cgi->url
. "\">Home</a></div>\n";
}
print "</div>\n";
print "</div>\n";
print $cgi->end_html();
# Remove PGT file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment