plugincustom.html 10.8 KB
Newer Older
Clément OUDOT's avatar
Clément OUDOT committed
1 2 3 4 5 6
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8" />
  <title>documentation:2.0:plugincustom</title>
<meta name="generator" content="DokuWiki"/>
Xavier Guimard's avatar
Xavier Guimard committed
7
<meta name="robots" content="index,follow"/>
Clément OUDOT's avatar
Clément OUDOT committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
<meta name="keywords" content="documentation,2.0,plugincustom"/>
<link rel="search" type="application/opensearchdescription+xml" href="lib/exe/opensearch.html" title="LemonLDAP::NG"/>
<link rel="start" href="plugincustom.html"/>
<link rel="contents" href="plugincustom.html" title="Sitemap"/>
<link rel="stylesheet" type="text/css" href="lib/exe/css.php.t.bootstrap3.css"/>
<!-- //if:usedebianlibs
  <link rel="stylesheet" type="text/css" href="/javascript/bootstrap/css/bootstrap.min.css" />
//elsif:useexternallibs
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></script>
//elsif:cssminified
  <link rel="stylesheet" type="text/css" href="/static/bwr/bootstrap/dist/css/bootstrap.min.css" />
//else -->
  <link rel="stylesheet" type="text/css" href="/static/bwr/bootstrap/dist/css/bootstrap.css" />
<!-- //endif -->
<script type="text/javascript">/*<![CDATA[*/var NS='documentation:2.0';var JSINFO = {"id":"documentation:2.0:plugincustom","namespace":"documentation:2.0"};
/*!]]>*/</script>
<script type="text/javascript" charset="utf-8" src="lib/exe/js.php.t.bootstrap3.js"></script>
<!-- //if:usedebianlibs
<script type="text/javascript" src="/javascript/jquery/jquery.min.js"></script>
//elsif:useexternallibs
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
//elsif:jsminified
<script type="text/javascript" src="/static/bwr/jquery/dist/jquery.min.js"></script>
//else -->
<script type="text/javascript" src="/static/bwr/jquery/dist/jquery.js"></script>
<!-- //endif -->
<!-- //if:usedebianlibs
  <script type="text/javascript" src="/javascript/jquery-ui/jquery-ui.min.js"></script>
//elsif:useexternallibs
  <script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
//elsif:jsminified
  <script type="text/javascript" src="/static/bwr/jquery-ui/jquery-ui.min.js"></script>
//else -->
  <script type="text/javascript" src="/static/bwr/jquery-ui/jquery-ui.js"></script>
<!-- //endif -->
</head>
<body>
<div class="dokuwiki export container">
<!-- TOC START -->
<div id="dw__toc">
<h3 class="toggle">Table of Contents</h3>
<div>

<ul class="toc">
<li class="level1"><div class="li"><a href="#presentation">Presentation</a></div></li>
<li class="level1"><div class="li"><a href="#example">Example</a></div>
<ul class="toc">
<li class="level2"><div class="li"><a href="#plugin_perl_module">Plugin Perl module</a></div></li>
<li class="level2"><div class="li"><a href="#configuration">Configuration</a></div></li>
</ul></li>
</ul>
</div>
</div>
<!-- TOC END -->

<h1 class="sectionedit1" id="write_a_custom_plugin">Write a custom plugin</h1>
<div class="level1">

</div>
<!-- EDIT1 SECTION "Write a custom plugin" [1-37] -->
<h2 class="sectionedit2" id="presentation">Presentation</h2>
<div class="level2">

<p>
You can now write a custom portal plugin that will hook in the authentication process:
</p>
<ul>
<li class="level1"><div class="li"> <code>beforeAuth</code>: method called before authentication process</div>
</li>
<li class="level1"><div class="li"> <code>betweenAuthAndData</code>: method called after authentication and before setting “sessionInfo” provisionning</div>
</li>
<li class="level1"><div class="li"> <code>afterData</code>: method called after “sessionInfo” provisionning</div>
</li>
<li class="level1"><div class="li"> <code>endAuth</code>: method called when session is validated (after cookie build)</div>
</li>
<li class="level1"><div class="li"> <code>authCancel</code>: method called when user click on “cancel” during auth process</div>
</li>
<li class="level1"><div class="li"> <code>forAuthUser</code>: method called for already authenticated users</div>
</li>
<li class="level1"><div class="li"> <code>beforeLogout</code>: method called before logout</div>
</li>
</ul>

<p>
The plugin can also define new routes and call actions on them.
</p>

<p>
See also <code>Lemonldap::NG::Portal::Main::Plugin</code> man page.
</p>

</div>
<!-- EDIT2 SECTION "Presentation" [38-794] -->
<h2 class="sectionedit3" id="example">Example</h2>
<div class="level2">

</div>
<!-- EDIT3 SECTION "Example" [795-815] -->
<h3 class="sectionedit4" id="plugin_perl_module">Plugin Perl module</h3>
<div class="level3">

<p>
Create for example the MyPlugin module:
</p>
<pre class="code">vi /usr/share/perl5/Lemonldap/NG/Portal/MyPlugin.pm</pre>
<pre class="code file perl"><a href="http://perldoc.perl.org/functions/package.html"><span class="kw3">package</span></a> Lemonldap<span class="sy0">::</span><span class="me2">NG</span><span class="sy0">::</span><span class="me2">Portal</span><span class="sy0">::</span><span class="me2">MyPlugin</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">use</span> Mouse<span class="sy0">;</span>
<span class="kw2">use</span> Lemonldap<span class="sy0">::</span><span class="me2">NG</span><span class="sy0">::</span><span class="me2">Portal</span><span class="sy0">::</span><span class="me2">Main</span><span class="sy0">::</span><span class="me2">Constants</span><span class="sy0">;</span>
extends <span class="st_h">'Lemonldap::NG::Portal::Main::Plugin'</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">use</span> constant beforeAuth <span class="sy0">=&gt;</span> <span class="st_h">'verifyIP'</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">sub</span> init <span class="br0">&#123;</span>
          <span class="kw1">my</span> <span class="br0">&#40;</span><span class="re0">$self</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="co5">@_</span><span class="sy0">;</span>
          <span class="re0">$self</span><span class="sy0">-&gt;</span><span class="me1">addUnauthRoute</span><span class="br0">&#40;</span> mypath <span class="sy0">=&gt;</span> <span class="st_h">'hello'</span><span class="sy0">,</span> <span class="br0">&#91;</span> <span class="st_h">'GET'</span><span class="sy0">,</span> <span class="st_h">'PUT'</span> <span class="br0">&#93;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
          <span class="re0">$self</span><span class="sy0">-&gt;</span><span class="me1">addAuthRoute</span><span class="br0">&#40;</span> mypath <span class="sy0">=&gt;</span> <span class="st_h">'welcome'</span><span class="sy0">,</span> <span class="br0">&#91;</span> <span class="st_h">'GET'</span><span class="sy0">,</span> <span class="st_h">'PUT'</span> <span class="br0">&#93;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
          <a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="nu0">1</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw2">sub</span> verifyIP <span class="br0">&#123;</span>
          <span class="kw1">my</span> <span class="br0">&#40;</span><span class="re0">$self</span><span class="sy0">,</span> <span class="re0">$req</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="co5">@_</span><span class="sy0">;</span>
          <a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> PE_ERROR <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$req</span><span class="sy0">-&gt;</span><span class="me1">address</span> <span class="sy0">!~</span> <span class="co2">/^10/</span><span class="br0">&#41;</span><span class="sy0">;</span>
          <a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> PE_OK<span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw2">sub</span> hello <span class="br0">&#123;</span>
          <span class="kw1">my</span> <span class="br0">&#40;</span><span class="re0">$self</span><span class="sy0">,</span> <span class="re0">$req</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="co5">@_</span><span class="sy0">;</span>
          <span class="sy0">...</span>
          <a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="re0">$self</span><span class="sy0">-&gt;</span><span class="me1">p</span><span class="sy0">-&gt;</span><span class="me1">sendJSONresponse</span><span class="br0">&#40;</span><span class="re0">$req</span><span class="sy0">,</span> <span class="br0">&#123;</span> hello <span class="sy0">=&gt;</span> <span class="nu0">1</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw2">sub</span> welcome <span class="br0">&#123;</span>
          <span class="kw1">my</span> <span class="br0">&#40;</span><span class="re0">$self</span><span class="sy0">,</span> <span class="re0">$req</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="co5">@_</span><span class="sy0">;</span>
          <span class="sy0">...</span>
          <a href="http://perldoc.perl.org/functions/return.html"><span class="kw3">return</span></a> <span class="re0">$self</span><span class="sy0">-&gt;</span><span class="me1">p</span><span class="sy0">-&gt;</span><span class="me1">sendHtml</span><span class="br0">&#40;</span><span class="re0">$req</span><span class="sy0">,</span> <span class="st_h">'template'</span><span class="sy0">,</span> params <span class="sy0">=&gt;</span> <span class="br0">&#123;</span> WELCOME <span class="sy0">=&gt;</span> <span class="nu0">1</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="nu0">1</span><span class="sy0">;</span></pre>

</div>
<!-- EDIT4 SECTION "Plugin Perl module" [816-1767] -->
<h3 class="sectionedit5" id="configuration">Configuration</h3>
<div class="level3">

<p>
Declare the plugin in lemonldap-ng.ini:
</p>
<pre class="code">vi /etc/lemonldap-ng/lemonldap-ng.ini</pre>
<pre class="code file perl"><span class="br0">&#91;</span>portal<span class="br0">&#93;</span>
customPlugins <span class="sy0">=</span> Lemonldap<span class="sy0">::</span><span class="me2">NG</span><span class="sy0">::</span><span class="me2">Portal</span><span class="sy0">::</span><span class="me2">MyPlugin</span>
<span class="sy0">;</span>customPlugins <span class="sy0">=</span> Lemonldap<span class="sy0">::</span><span class="me2">NG</span><span class="sy0">::</span><span class="me2">Portal</span><span class="sy0">::</span><span class="me2">MyPlugin1</span><span class="sy0">,</span> Lemonldap<span class="sy0">::</span><span class="me2">NG</span><span class="sy0">::</span><span class="me2">Portal</span><span class="sy0">::</span><span class="me2">MyPlugin2</span><span class="sy0">,</span> <span class="sy0">...</span></pre>

</div>
<!-- EDIT5 SECTION "Configuration" [1768-] --></div>
</body>
</html>