2012-02-25 23:45:20 +01:00
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en"
lang="en" dir="ltr">
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" / >
< title > < / title >
<!-- metadata -->
< meta name = "generator" content = "Offline" / >
< meta name = "version" content = "Offline 0.1" / >
<!-- style sheet links -->
< link rel = "stylesheet" media = "all" type = "text/css" href = "../../../css/all.css" / >
< link rel = "stylesheet" media = "screen" type = "text/css" href = "../../../css/screen.css" / >
< link rel = "stylesheet" media = "print" type = "text/css" href = "../../../css/print.css" / >
< / head >
< body >
< div class = "dokuwiki export" >
2015-06-08 16:57:58 +02:00
< h1 class = "sectionedit1" id = "protect_your_application" > Protect your application< / h1 >
2012-02-25 23:45:20 +01:00
< div class = "level1" >
< / div >
2015-06-08 16:57:58 +02:00
<!-- EDIT1 SECTION "Protect your application" [1 - 40] -->
< h2 class = "sectionedit2" id = "presentation" > Presentation< / h2 >
2012-02-25 23:45:20 +01:00
< div class = "level2" >
< p >
Your application can know the connected user using:
< / p >
< ul >
< li class = "level1" > < div class = "li" > REMOTE_USER environment variable (with local Handler or SetEnvIf trick)< / div >
< / li >
2015-06-08 16:57:58 +02:00
< li class = "level1" > < div class = "li" > HTTP header (in all cases)< / div >
2012-02-25 23:45:20 +01:00
< / li >
< / ul >
< p >
2016-03-22 12:19:17 +01:00
To get more information on user (name, mail, etc.), you have to read < a href = "../../documentation/2.0/writingrulesand_headers.html#headers" class = "wikilink1" title = "documentation:2.0:writingrulesand_headers" > HTTP headers< / a > .
2012-02-25 23:45:20 +01:00
< / p >
< p >
< p > < div class = "notetip" >
2016-03-22 12:19:17 +01:00
If your application is based on < a href = "http://search.cpan.org/perldoc?CGI" class = "urlextern" title = "http://search.cpan.org/perldoc?CGI" rel = "nofollow" > Perl CGI package< / a > , you can simply replace CGI by < a href = "#perl_auto-protected_cgi" title = "documentation:2.0:selfmadeapplication ↵" class = "wikilink1" > Lemonldap::NG::Handler::CGI< / a >
2012-02-25 23:45:20 +01:00
< / div > < / p >
< / p >
< / div >
2015-06-08 16:57:58 +02:00
<!-- EDIT2 SECTION "Presentation" [41 - 542] -->
< h2 class = "sectionedit3" id = "code_snippet" > Code snippet< / h2 >
2012-02-25 23:45:20 +01:00
< div class = "level2" >
< p >
2016-03-22 12:19:17 +01:00
Examples with a < a href = "../../documentation/2.0/writingrulesand_headers.html#headers" class = "wikilink1" title = "documentation:2.0:writingrulesand_headers" > configured header< / a > named ' Auth-User' :
2012-02-25 23:45:20 +01:00
< / p >
< / div >
2015-06-08 16:57:58 +02:00
<!-- EDIT3 SECTION "Code snippet" [543 - 658] -->
< h3 class = "sectionedit4" id = "perl" > Perl< / h3 >
2012-02-25 23:45:20 +01:00
< div class = "level3" >
< pre class = "code file perl" > < a href = "http://perldoc.perl.org/functions/print.html" > < span class = "kw3" > print< / span > < / a > < span class = "st0" > " Connected user: " < / span > < span class = "sy0" > .< / span > < span class = "re0" > $ENV< / span > < span class = "br0" > { < / span > HTTP_AUTH_USER< span class = "br0" > } < / span > < span class = "sy0" > ;< / span > < / pre >
< / div >
2015-06-08 16:57:58 +02:00
<!-- EDIT4 SECTION "Perl" [659 - 742] -->
< h3 class = "sectionedit5" id = "php" > PHP< / h3 >
2012-02-25 23:45:20 +01:00
< div class = "level3" >
< pre class = "code file php" > < span class = "kw1" > print< / span > < span class = "st0" > " Connected user: " < / span > < span class = "sy0" > .< / span > < span class = "re0" > $_SERVER< / span > < span class = "br0" > { < / span > HTTP_AUTH_USER< span class = "br0" > } < / span > < span class = "sy0" > ;< / span > < / pre >
< / div >
2015-06-08 16:57:58 +02:00
<!-- EDIT5 SECTION "PHP" [743 - 828] -->
< h2 class = "sectionedit6" id = "perl_auto-protected_cgi" > Perl auto-protected CGI< / h2 >
2012-02-25 23:45:20 +01:00
< div class = "level2" >
< p >
2015-06-08 16:57:58 +02:00
Using this feature, you don' t have to use virtual host protection: protection is embedded in Lemonldap::NG::Handler::CGI.
2012-02-25 23:45:20 +01:00
< / p >
< p >
2015-06-08 16:57:58 +02:00
Lemonldap::NG::Handler::CGI adds some functions to < a href = "http://search.cpan.org/perldoc?CGI" class = "urlextern" title = "http://search.cpan.org/perldoc?CGI" rel = "nofollow" > CGI< / a > :
2012-02-25 23:45:20 +01:00
< / p >
< ul >
< li class = "level1" > < div class = "li" > authenticate: check if user is authenticated; if not, redirect it to the portal< / div >
< / li >
2015-06-08 16:57:58 +02:00
< li class = "level1" > < div class = "li" > authorize: check if user is authorizated to access to this < abbr title = "Uniform Resource Locator" > URL< / abbr > < / div >
2012-02-25 23:45:20 +01:00
< / li >
< / ul >
< p >
Example:
< / p >
< ul >
< li class = "level1" > < div class = "li" > Code to replace:< / div >
< / li >
< / ul >
< pre class = "code perl" > < span class = "kw1" > my< / span > < span class = "re0" > $cgi< / span > < span class = "sy0" > =< / span > < span class = "kw2" > new< / span > CGI< span class = "sy0" > ;< / span >
< span class = "sy0" > ...< / span > < / pre >
< ul >
< li class = "level1" > < div class = "li" > New code:< / div >
< / li >
< / ul >
2015-06-08 16:57:58 +02:00
< pre class = "code perl" > < span class = "kw1" > my< / span > < span class = "re0" > $cgi< / span > < span class = "sy0" > =< / span > Lemonldap< span class = "sy0" > ::< / span > < span class = "me2" > NG< / span > < span class = "sy0" > ::< / span > < span class = "me2" > Handler< / span > < span class = "sy0" > ::< / span > < span class = "me2" > CGI< / span > < span class = "sy0" > -> < / span > < span class = "kw2" > new< / span > < span class = "br0" > ( < / span > < span class = "br0" > { < / span > < span class = "br0" > } < / span > < span class = "br0" > ) < / span > < span class = "sy0" > ;< / span >
2012-02-25 23:45:20 +01:00
< span class = "re0" > $cgi< / span > < span class = "sy0" > -> < / span > < span class = "me1" > authenticate< / span > < span class = "br0" > ( < / span > < span class = "br0" > ) < / span > < span class = "sy0" > ;< / span >
< span class = "re0" > $cgi< / span > < span class = "sy0" > -> < / span > < span class = "me1" > authorize< / span > < span class = "br0" > ( < / span > < span class = "br0" > ) < / span > < span class = "sy0" > ;< / span >
< span class = "sy0" > ...< / span > < / pre >
< p >
Then you can access to user datas
< / p >
< pre class = "code perl" > < span class = "co1" > # Get attributes (or macros)< / span >
< span class = "kw1" > my< / span > < span class = "re0" > $cn< / span > < span class = "sy0" > =< / span > < span class = "re0" > $cgi< / span > < span class = "sy0" > -> < / span > < span class = "me1" > user< / span > < span class = "sy0" > -> < / span > < span class = "br0" > { < / span > cn< span class = "br0" > } < / span >
< span class = "co1" > # Test if user is member of a Lemonldap::NG group (or LDAP mapped group)< / span >
< span class = "kw1" > if< / span > < span class = "br0" > ( < / span > < span class = "re0" > $cgi< / span > < span class = "sy0" > -> < / span > < span class = "me1" > group< / span > < span class = "br0" > ( < / span > < span class = "st_h" > 'admin'< / span > < span class = "br0" > ) < / span > < span class = "br0" > ) < / span > < span class = "br0" > { < / span >
< span class = "co1" > # special html code for admins< / span >
< span class = "br0" > } < / span >
< span class = "kw1" > else< / span > < span class = "br0" > { < / span >
< span class = "co1" > # another HTML code< / span >
< span class = "br0" > } < / span > < / pre >
< p >
2015-06-08 16:57:58 +02:00
You can test any < abbr title = "Uniform Resource Locator" > URL< / abbr > to see if it' s protected using testUri(). It returns:
2012-02-25 23:45:20 +01:00
< / p >
< ul >
< li class = "level1" > < div class = "li" > 1 if user is authorizated to access to it< / div >
< / li >
< li class = "level1" > < div class = "li" > 0 if not< / div >
< / li >
2015-06-08 16:57:58 +02:00
< li class = "level1" > < div class = "li" > -1 if this < abbr title = "Uniform Resource Locator" > URL< / abbr > is not known by < abbr title = "LemonLDAP::NG" > LL::NG< / abbr > configuration< / div >
2012-02-25 23:45:20 +01:00
< / li >
< / ul >
< pre class = "code perl" > < span class = "kw1" > if< / span > < span class = "br0" > ( < / span > < span class = "re0" > $cgi< / span > < span class = "sy0" > -> < / span > < span class = "me1" > testUri< / span > < span class = "br0" > ( < / span > < span class = "st_h" > 'http://test3.example.com/'< / span > < span class = "br0" > ) < / span > < span class = "br0" > { < / span >
< a href = "http://perldoc.perl.org/functions/print.html" > < span class = "kw3" > print< / span > < / a > < span class = "st_h" > '< a href=" http://test3.example.com/" > click here< /a> '< / span > < span class = "sy0" > ;< / span >
< span class = "br0" > } < / span > < / pre >
< / div >
2015-06-08 16:57:58 +02:00
< / div > <!-- closes <div class="dokuwiki export"> -->