Skip to content

Commit 26d8ecc

Browse files
committed
init
0 parents  commit 26d8ecc

9 files changed

Lines changed: 895 additions & 0 deletions

File tree

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
Attributecollector
3+
==================
4+
5+
simplesamlphp auth proc filter, that get attributes from backend database and set to attributes array.
6+
7+
This code is delivered from:
8+
https://forja.rediris.es/svn/confia/attributecollector
9+
10+
Basic configuration
11+
===================
12+
13+
Configure this module as an Auth Proc Filter. More info at
14+
http://rnd.feide.no/content/authentication-processing-filters-simplesamlphp
15+
16+
Example
17+
=======
18+
19+
In the following example the filter is configured for only one hosted IdP
20+
editing the file saml20-idp-hosted
21+
22+
```php
23+
$metadata = array(
24+
25+
'ssp-idp' => array(
26+
27+
...
28+
29+
'authproc' => array(
30+
10 => array(
31+
'existing' => 'preserve',
32+
'class' => 'attributecollector:AttributeCollector',
33+
'uidfield' => 'subject',
34+
'collector' => array(
35+
'class' => 'attributecollector:SQLCollector',
36+
'dsn' => 'pgsql:host=localhost;dbname=ssp-extra',
37+
'username' => 'ssp-extra',
38+
'password' => 'ssp-extra',
39+
'query' => 'SELECT * from extra where subject=:uidfield',
40+
)
41+
)
42+
),
43+
44+
...
45+
46+
)
47+
);
48+
```
49+
50+
Configuration Options explained
51+
===============================
52+
53+
The filter needs the following options:
54+
55+
- class: The filter class. Allways: 'attributecollector:AttributeCollector'
56+
- uidfield: The name of the field used as an unique user identifier. The
57+
configured collector recives this uid so it can search for extra
58+
attributes.
59+
- collector: The configuration of the collector used to retrieve the extra
60+
attributes
61+
62+
The following option is optional:
63+
64+
- existing: Tell the filter what to do when a collected attribute already
65+
exists in the user attributes. Values can be:
66+
'preserve': Ignore collected attribute and preserve the old one.
67+
This one is the default behaviour.
68+
'replace': Ignore original attribute and replace it with the
69+
collected one.
70+
'merge': Merge the collected attribute into the array of the
71+
original one.
72+
73+
Collector Configuration Options explained
74+
=========================================
75+
76+
The collector configuration array needs at least one option:
77+
78+
- class: The collector class.
79+
80+
Some other options may be needed by the collector, refer to the collector
81+
documentation.

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "niif/simplesamlphp-module-attributecollector",
3+
"description": "Collect attributes from backend databases like sql or ldap",
4+
"type": "simplesamlphp-module",
5+
"require": {
6+
"simplesamlphp/composer-module-installer": "~1.0"
7+
}
8+
}

default-enable

Whitespace-only changes.

docs/ldapcollector.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
LDAP Attributes Collector
2+
3+
This class implements a collector that retrieves attributes from a directory
4+
server accessed via LDAP protocol.
5+
6+
It has the following options:
7+
8+
- host: LDAP server host
9+
- port: LDAP server port
10+
- protocol: LDAP protocol
11+
- binddn: The username which should be used when connecting to the LDAP
12+
server.
13+
- password: The password which should be used when connecting to the LDAP
14+
server.
15+
- basedn: DN to start the LDAP search
16+
- attrlist: An associative array of [LDAP attr1 => atr1, LDAP attr2 => atr2].
17+
This parameter is optional. Remove this param to get all attrs
18+
- searchfilter: filter used to search the directory. You can use the special
19+
:uidfield string to refer the value of the field specified as an uidfield in
20+
the processor
21+
22+
Example configuration:
23+
24+
'collector' => array(
25+
'class' => 'attributecollector:LDAPCollector',
26+
'host' => 'myldap.srv',
27+
'port' => 389,
28+
'binddn' => 'cn=myuser',
29+
'password' => 'yaco0909',
30+
'basedn' => 'dc=my,dc=org',
31+
'searchfilter' => 'uid=:uidfield',
32+
'protocol' => 3,
33+
'attrlist' => array(
34+
// LDAP attr => real attr
35+
'objectClass' => 'myClasses',
36+
),
37+
),

docs/sqlcollector.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
SQL Attributes Collector
2+
3+
This class implements a collector that retrieves attributes from a database.
4+
It shoud word against both MySQL and PostgreSQL
5+
6+
It has the following options:
7+
- dsn: The DSN which should be used to connect to the database server. Check the various
8+
database drivers in http://php.net/manual/en/pdo.drivers.php for a description of
9+
the various DSN formats.
10+
- username: The username which should be used when connecting to the database server.
11+
- password: The password which should be used when connecting to the database server.
12+
- query: The sql query for retrieve attributes. You can use the special :uidfield string
13+
to refer the value of the field especified as an uidfield in the processor.
14+
15+
16+
Example - with PostgreSQL database:
17+
18+
'collector' => array(
19+
'class' => 'attributecollector:SQLCollector',
20+
'dsn' => 'pgsql:host=localhost;dbname=simplesaml',
21+
'username' => 'simplesaml',
22+
'password' => 'secretpassword',
23+
'query' => array("SELECT address, phone, country from extraattributes where uid=:uidfield"),
24+
'get_all_query' => array("SELECT address, phone, country from extraattributes),
25+
)
26+
27+
SQLCollector allows to specify several database connections which will
28+
be used sequentially when a connection fails. This can be done
29+
by defining each parameter by using an array.
30+
31+
Example:
32+
'collector' => array(
33+
'class' => 'attributecollector:SQLCollector',
34+
'dsn' => array('oci:dbname=first',
35+
'mysql:host=localhost;dbname=second'),
36+
'username' => array('first', 'second'),
37+
'password' => array('first', 'second'),
38+
'query' => array("SELECT sid as SUBJECT from subjects where uid=:uidfield",
39+
"SELECT sid as SUBJECT from subjects2 where uid=:uidfield AND status='OK'"
40+
),
41+
'get_all_query' => array("SELECT sid as SUBJECT from subjects",
42+
"SELECT sid as SUBJECT from subjects2"
43+
),
44+
)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/**
4+
* Filter to collect attributes from diferent sources.
5+
*/
6+
class sspmod_attributecollector_Auth_Process_AttributeCollector extends SimpleSAML_Auth_ProcessingFilter {
7+
8+
private $existing = 'ignore';
9+
private $collector = NULL;
10+
private $uidfield = NULL;
11+
12+
13+
/**
14+
* Get and initialize the configured collector
15+
*
16+
* @param array $config Configuration information about this filter.
17+
*/
18+
private function getCollector($config) {
19+
if (!array_key_exists("collector", $config) || !array_key_exists("class", $config["collector"])) {
20+
throw new Exception('No collector class specified in configuration');
21+
}
22+
$collectorConfig = $config["collector"];
23+
$collectorClassName = SimpleSAML_Module::resolveClass($collectorConfig['class'], 'Collector', 'sspmod_attributecollector_SimpleCollector');
24+
unset($collectorConfig['class']);
25+
return new $collectorClassName($collectorConfig);
26+
}
27+
28+
/**
29+
* Initialize this filter.
30+
*
31+
* @param array $config Configuration information about this filter.
32+
* @param mixed $reserved For future use.
33+
*/
34+
public function __construct($config, $reserved) {
35+
parent::__construct($config, $reserved);
36+
37+
assert('is_array($config)');
38+
39+
if (!array_key_exists("uidfield", $config)) {
40+
throw new Exception('No uidfield specified in configuration');
41+
}
42+
$this->uidfield = $config["uidfield"];
43+
$this->collector = $this->getCollector($config);
44+
if (array_key_exists("existing", $config)) {
45+
$this->existing = $config["existing"];
46+
}
47+
}
48+
49+
50+
/**
51+
* Apply filter expand attributes with collected ones
52+
*
53+
* @param array &$request The current request
54+
*/
55+
public function process(&$request) {
56+
assert('is_array($request)');
57+
assert('array_key_exists("Attributes", $request)');
58+
59+
if (array_key_exists($this->uidfield, $request['Attributes'])) {
60+
61+
$newAttributes = $this->collector->getAttributes($request['Attributes'], $this->uidfield);
62+
63+
if (is_array($newAttributes)) {
64+
$attributes =& $request['Attributes'];
65+
66+
foreach($newAttributes as $name => $values) {
67+
if (!is_array($values)) {
68+
$values = array($values);
69+
}
70+
if (!array_key_exists($name, $attributes) || $this->existing === 'replace') {
71+
$attributes[$name] = $values;
72+
} else {
73+
if ($this->existing === 'merge') {
74+
$attributes[$name] = array_merge($attributes[$name], $values);
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
83+
?>

0 commit comments

Comments
 (0)