lemonldap-ng-handler 0.5.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,305 @@
1
+ # Lemonldap::NG handler for Node.js
2
+
3
+ Beta [Lemonldap::NG](https://lemonldap-ng.org) handler for node.js
4
+
5
+ ## SYNOPSIS
6
+
7
+ ### lemonldap-ng.ini
8
+ ```ini
9
+ ...
10
+ [node-handler]
11
+
12
+ nodeVhosts = test.example.com, test2.example.com
13
+ ```
14
+
15
+ ### Express app
16
+ ```javascript
17
+ // Variables
18
+ var express = require('express');
19
+ var app = express();
20
+ var handler = require('lemonldap-ng-handler');
21
+
22
+ // initialize handler (optional args)
23
+ handler.init({
24
+ configStorage: {
25
+ "confFile":"test/lemonldap-ng.ini"
26
+ }
27
+ });
28
+
29
+ // and load it
30
+ app.use(handler.run);
31
+
32
+ // Then simply use your express app
33
+ app.get('/', function(req, res) {
34
+ return res.send('Hello ' + req.headers['Auth-User'] + ' !');
35
+ });
36
+ app.listen(3000, function() {
37
+ return console.log('Example app listening on port 3000!');
38
+ });
39
+ ```
40
+
41
+ ### Nginx authorization server
42
+
43
+ FastCGI server:
44
+ ```javascript
45
+ var handler = require('lemonldap-ng-handler');
46
+
47
+ handler.init({
48
+ configStorage: {
49
+ "confFile": "/path/to/lemonldap-ng.ini"
50
+ }
51
+ });
52
+
53
+ handler.nginxServer({
54
+ "mode": "fcgi", // or "http", default: fcgi
55
+ "port": 9090, // default value
56
+ "ip": 'localhost' // default value
57
+ });
58
+ ```
59
+
60
+ Nginx configuration. For more, see [Nginx configuration on LLNG website](https://lemonldap-ng.org/documentation/latest/configvhost#nginx_configuration)
61
+ ```nginx
62
+ server {
63
+ listen 19876;
64
+ server_name test.example.com;
65
+ root /home/xavier/dev/lemonldap/e2e-tests/conf/site;
66
+
67
+ # Internal authentication request
68
+ location = /lmauth {
69
+ internal;
70
+ include /etc/nginx/fastcgi_params;
71
+ fastcgi_pass localhost:9090;
72
+
73
+ # Drop post datas
74
+ fastcgi_pass_request_body off;
75
+ fastcgi_param CONTENT_LENGTH "";
76
+
77
+ # Keep original hostname
78
+ fastcgi_param HOST $http_host;
79
+
80
+ # Keep original request (LLNG server will received /llauth)
81
+ fastcgi_param X_ORIGINAL_URI $request_uri;
82
+ }
83
+
84
+ # Client requests
85
+ location / {
86
+ auth_request /lmauth;
87
+ auth_request_set $lmremote_user $upstream_http_lm_remote_user;
88
+ auth_request_set $lmlocation $upstream_http_location;
89
+ error_page 401 $lmlocation;
90
+ include conf/nginx-lua-headers.conf;
91
+ }
92
+
93
+ }
94
+ ```
95
+
96
+ ## DESCRIPTION
97
+
98
+ Lemonldap::NG is a complete Web-SSO system that can run with reverse-proxies
99
+ or directly on application webservers. It can be used in conjunction with
100
+ OpenID-Connect, CAS and SAML systems as identity or service provider. It can
101
+ also be used as proxy between those federation systems.
102
+
103
+ It manages both authentication and authorization and provides headers for
104
+ accounting. So you can have a full AAA protection. Authorization are built by
105
+ associating a regular expression and a rule. Regular expression is applied on
106
+ the requested URL and the rule calculates if the user is authorized.
107
+
108
+ LLNG is designed in 3 kinds of elements:
109
+ * a portal
110
+ * a manager
111
+ * some handlers for Apache, [Plack family](https://plackperl.org), Node.js
112
+ * some FastCGI servers to provide Nginx handler or
113
+ [SSOaaS](https://lemonldap-ng.org/documentation/2.0/ssoaas):
114
+ * pure Perl (default)
115
+ * uWSGI _(Perl via uwsgi-psgi plugin)_
116
+ * this Node.js module
117
+
118
+ This module provide the Node.js handler and the FastCGI server.
119
+
120
+ See [Lemonldap::NG website](http://lemonldap-ng.org) for more.
121
+
122
+ ## INSTALLATION
123
+
124
+ Of course, you must have a [LemonLDAP::NG](https://lemonldap-ng.org) system
125
+ installed in your organization. To install node handler, use simply:
126
+ ```shell
127
+ npm install lemonldap-ng-handler
128
+ ```
129
+
130
+ ## CONFIGURATION
131
+
132
+ ### Configuration file *(lemonldap-ng.ini)*
133
+
134
+ Node-lemonldap-ng-handler uses LemonLDAP::NG configuration file, sections
135
+ `[configuration]` and `[node-handler]`.
136
+
137
+ > **Note important**: lemonldap-ng-handler can't read multilines in
138
+ lemonldap-ng.ini. You must rewrite them on one line *(even in other sections)*.
139
+
140
+ #### Sections `[all]` and `[configuration]`
141
+
142
+ Nothing to change, but lemonldap-ng-handler isn't compatible with all
143
+ LLNG backends. See below.
144
+
145
+ ##### Loggers
146
+
147
+ lemonldap-ng-handler is compatible with the following
148
+ [loggers](https://lemonldap-ng.org/documentation/2.0/logs):
149
+ * Lemonldap::NG::Common::Logger::Std : use console.log
150
+ * Lemonldap::NG::Common::Logger::Syslog : use Syslog _(install modern-syslog
151
+ to use it)_
152
+ * UWSGI : usable only under uwsgi V8 plugin. Override `logger` in section
153
+ `[nginx-handler]` in your `[lemonldap-ng.ini]` file
154
+
155
+ #### New section `[node-handler]`
156
+
157
+ You can overwrite here LemonLDAP::NG configuration keys. You must set the list
158
+ of virtual hosts handled by node.js in key `nodeVhosts`.
159
+
160
+ Example:
161
+ ```ini
162
+ [node-handler]
163
+ nodeVhosts = test1.example.com, test2.example.com
164
+ ```
165
+
166
+ **Rules and headers must be written in Javascript**, not in Perl. Example:
167
+
168
+ default: $uid == 'dwho'
169
+ ^/deny : deny
170
+
171
+ You'll have a warning in the manager when saving this rules since Perl doesn't
172
+ understand Javascript.
173
+
174
+ > Note that `handler` section isn't read by lemonldap-ng-handler.
175
+
176
+ ### Configuration backends
177
+
178
+ Node-lemonldap-ng-handler is compatible with the following Lemonldap::NG
179
+ backends:
180
+ * [File](https://lemonldap-ng.org/documentation/latest/fileconfbackend)
181
+ * [YAMLFile](https://lemonldap-ng.org/documentation/latest/yamlconfbackend)
182
+ * [REST](https://lemonldap-ng.org/documentation/2.0/restconfbackend)
183
+ * [LDAP](https://lemonldap-ng.org/documentation/latest/ldapconfbackend)
184
+ * [MongoDB](https://lemonldap-ng.org/documentation/latest/mongodbconfbackend)
185
+ _(without authentication neither ssl for now)_
186
+ * [CDBI / RDBI](https://lemonldap-ng.org/documentation/latest/sqlconfbackend)
187
+ _(MySQL, PostgreSQL and SQLite3 only)_. **Note that you must install `nodedbi`
188
+ and needed dependencies**. Example with PostgreSQL _(Debian)_:
189
+ ```
190
+ $ sudo apt-get install libdbi-dev libdbd-pgsql
191
+ $ npm install nodedbi
192
+ ```
193
+
194
+ ### Sessions backends
195
+
196
+ Node-lemonldap-ng-handler is compatible with the following Lemonldap::NG
197
+ backends:
198
+ * File:
199
+ * [Apache::Session::File](https://metacpan.org/pod/Apache::Session::File)
200
+ * [Apache::Session::Browseable::File](https://metacpan.org/pod/Apache::Session::Browseable::File)
201
+ * Redis _(install `redis` to use them)_:
202
+ * [Apache::Session::Redis](https://metacpan.org/pod/Apache::Session::Redis)
203
+ * [Apache::Session::Browseable::Redis](https://metacpan.org/pod/Apache::Session::Browseable::Redis)
204
+ * LDAP backends _(install `ldapjs` to use them)_:
205
+ * [Apache::Session::LDAP](https://metacpan.org/pod/Apache::Session::LDAP)
206
+ * [Apache::Session::Browseable::LDAP](https://metacpan.org/pod/Apache::Session::Browseable::LDAP)
207
+ * SQL backends _(install `nodedbi` to use them)_:
208
+ * [Apache::Session::MySQL](https://metacpan.org/pod/Apache::Session::MySQL)
209
+ * [Apache::Session::Browseable::MySQL](https://metacpan.org/pod/Apache::Session::Browseable::MySQL)
210
+ * [Apache::Session::Postgres](https://metacpan.org/pod/Apache::Session::Postgres)
211
+ * [Apache::Session::Browseable::Postgres](https://metacpan.org/pod/Apache::Session::Browseable::Postgres)
212
+ * [Apache::Session::Browseable::PgHstore](https://metacpan.org/pod/Apache::Session::Browseable::PgHstore)
213
+ * [Apache::Session::Browseable::PgJSON](https://metacpan.org/pod/Apache::Session::Browseable::PgJSON)
214
+ * [Apache::Session::SQLite3](https://metacpan.org/pod/Apache::Session::SQLite3)
215
+ * [Apache::Session::Browseable::SQLite](https://metacpan.org/pod/Apache::Session::Browseable::SQLite)
216
+
217
+ **Note that fo SQL backends, you must install nodedbi and needed dependencies**.
218
+ Example with PostgreSQL _(Debian/Ubuntu)_:
219
+ ```
220
+ $ sudo apt-get install libdbi-dev libdbd-pgsql
221
+ $ npm install nodedbi
222
+ ```
223
+
224
+ ### Special handlers
225
+
226
+ Node-lemonldap-ng-handler can be used as
227
+ * [DevOps handler](https://lemonldap-ng.org/documentation/2.0/devopshandler)
228
+ * [ServiceToken handler](https://lemonldap-ng.org/documentation/2.0/servertoserver)
229
+
230
+ You just have to specify `"type":<type>` in `init()` arguments. Example:
231
+ ```javascript
232
+ handler.init({
233
+ "type": "DevOps",
234
+ "configStorage": {
235
+ "confFile": "/path/to/lemonldap-ng.ini"
236
+ }
237
+ });
238
+ ```
239
+
240
+ ## METHODS
241
+
242
+ ### init()
243
+
244
+ Takes an optional object argument with the following optional keys:
245
+ * configStorage: object
246
+ * type: special handler _(see "Special handlers section")_
247
+
248
+ ### run()
249
+
250
+ Used by express to handle requests. Arguments:
251
+ * req: the express request
252
+ * res: the express response
253
+ * next: next function in stack
254
+
255
+ ### nginxServer
256
+
257
+ Launch Nginx compatible authorization server. Takes an optional object as
258
+ argument. Keys:
259
+ * mode: server mode, "fcgi" or "http", defult to "fcgi"
260
+ * port: port to listen to
261
+ * ip: ip address to listen to
262
+
263
+ ## TODO
264
+
265
+ * Custom functions
266
+ * Think to menu problem
267
+ * REST backends
268
+
269
+ ## CHANGELOG
270
+
271
+ See [CHANGELOG](CHANGELOG.md)
272
+
273
+ ## BUG REPORT AND OTHER ISSUES
274
+
275
+ Use OW2 system to report bug or ask for features:
276
+ [LLNG OW2 GitLab](https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues)
277
+
278
+ > Note: uWGI isn't supported because V8 plugin for uWSGI [isn't compatible
279
+ with async](http://uwsgi.readthedocs.io/en/latest/V8.html#commonjs)
280
+
281
+ ## DOWNLOAD
282
+
283
+ Lemonldap::NG is available at
284
+ https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/tags
285
+
286
+ This library is available at
287
+ https://github.com/LemonLDAPNG/lemonldap-ng-handler
288
+
289
+ ## COPYRIGHT AND LICENSE
290
+
291
+ Copyright (C) 2016-2019 by [Xavier Guimard](mailto:x.guimard@free.fr)
292
+
293
+ This library is free software; you can redistribute it and/or modify
294
+ it under the terms of the GNU General Public License as published by
295
+ the Free Software Foundation; either version 2, or (at your option)
296
+ any later version.
297
+
298
+ This program is distributed in the hope that it will be useful,
299
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
300
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
301
+ GNU General Public License for more details.
302
+
303
+ You should have received a copy of the GNU General Public License
304
+ along with this program. If not, see http://www.gnu.org/licenses/.
305
+
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { LLNG_Session } from '@lemonldap-ng/types';
3
+ import { Handler_Args } from './init';
4
+ import LemonldapNGHandler from './handlerMain';
5
+ import express from 'express';
6
+ import http from 'http';
7
+ declare type Vhost_Config = {
8
+ prot: string;
9
+ host: string;
10
+ path: string;
11
+ port: string;
12
+ headers?: {
13
+ [k: string]: string;
14
+ };
15
+ lb?: boolean;
16
+ };
17
+ declare class LemonldapNGHandlerDevOps extends LemonldapNGHandler {
18
+ constructor(args: Handler_Args);
19
+ grant(req: express.Request | http.IncomingMessage, uri: string, session: LLNG_Session): Promise<boolean>;
20
+ loadVhostConfig(req: express.Request | http.IncomingMessage, vhost: string, lvOpts: Vhost_Config): Promise<boolean>;
21
+ }
22
+ export default LemonldapNGHandlerDevOps;
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import { Request } from 'express';
3
+ import { ParamsDictionary } from 'express-serve-static-core';
4
+ import { IncomingMessage } from 'http';
5
+ import { ParsedQs } from 'qs';
6
+ import LemonldapNGHandlerDevOps from './handlerDevOps';
7
+ declare class LemonldapNGHandlerDevOpsST extends LemonldapNGHandlerDevOps {
8
+ fetchId(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>> | IncomingMessage): string;
9
+ }
10
+ export default LemonldapNGHandlerDevOpsST;
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" />
2
+ import { LLNG_Session } from '@lemonldap-ng/types';
3
+ import HandlerInit from './init';
4
+ import express from 'express';
5
+ import http from 'http';
6
+ export declare type FastCGI_Opts = {
7
+ mode: string | undefined;
8
+ port: number | undefined;
9
+ ip: string | undefined;
10
+ };
11
+ declare class LemonldapNGHandler extends HandlerInit {
12
+ init(): Promise<boolean>;
13
+ /**
14
+ * run(), the access control function
15
+ */
16
+ run(req: express.Request | http.IncomingMessage, res: http.ServerResponse, next: Function): any;
17
+ selfUri(vhost: string, uri: string): string;
18
+ nginxServer(fcgiOpt: FastCGI_Opts): void;
19
+ setError(res: http.ServerResponse, uri: string, code: number, txt: string): void;
20
+ isUnprotected(req: express.Request | http.IncomingMessage, uri: string): number | false;
21
+ resolveAlias(req: express.Request | http.IncomingMessage): string;
22
+ fetchId(req: express.Request | http.IncomingMessage): string;
23
+ retrieveSession(id: string): Promise<LLNG_Session>;
24
+ grant(req: express.Request | http.IncomingMessage, uri: string, session: LLNG_Session): Promise<boolean>;
25
+ sendHeaders(req: express.Request | http.IncomingMessage, session: LLNG_Session): void;
26
+ hideCookie(req: express.Request | http.IncomingMessage): void;
27
+ forbidden(req: express.Request | http.IncomingMessage, res: http.ServerResponse, session: LLNG_Session): void;
28
+ goToPortal(res: http.ServerResponse, uri: string, args?: string): void;
29
+ }
30
+ export default LemonldapNGHandler;
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import express from 'express';
3
+ import http from 'http';
4
+ import LemonldapNGHandler from './handlerMain';
5
+ declare class LemonldapNGHandlerServiceToken extends LemonldapNGHandler {
6
+ fetchId(req: express.Request | http.IncomingMessage): string;
7
+ }
8
+ export default LemonldapNGHandlerServiceToken;
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import express from 'express';
2
+ import http from 'http';
3
+ import { Handler_Args } from './init';
4
+ import LemonldapNGHandler, { FastCGI_Opts } from './handlerMain';
5
+ import LemonldapNGHandlerDevOps from './handlerDevOps';
6
+ declare let currentClass: typeof LemonldapNGHandler | typeof LemonldapNGHandlerDevOps;
7
+ export declare const init: (args: Handler_Args) => Promise<LemonldapNGHandler>;
8
+ export declare const run: (req: express.Request | http.IncomingMessage, res: http.ServerResponse, next: Function) => any;
9
+ export declare const nginxServer: (args: FastCGI_Opts) => void;
10
+ export { currentClass as class };