Skip to content

Commit 61870d5

Browse files
Added parsing of attribute list and name and description in AttributeConsumerService element. improved expire handling...
git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1288 44740490-163a-0410-bde0-09ae8108e29a
1 parent fee9f91 commit 61870d5

4 files changed

Lines changed: 83 additions & 31 deletions

File tree

lib/SimpleSAML/Metadata/SAMLBuilder.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public function __construct($entityId, $maxCache = NULL, $maxDuration = NULL) {
3939
$this->maxDuration = $maxDuration;
4040

4141
$this->document = new DOMDocument();
42+
4243
$this->entityDescriptor = $this->createElement('EntityDescriptor');
44+
# $this->entityDescriptor->setAttribute('xmlns:xml', 'http://www.w3.org/XML/1998/namespace');
4345
$this->entityDescriptor->setAttribute('entityID', $entityId);
4446

4547
$this->document->appendChild($this->entityDescriptor);
@@ -228,9 +230,9 @@ public function addMetadataSP20($metadata) {
228230
$e->setAttribute('protocolSupportEnumeration', 'urn:oasis:names:tc:SAML:2.0:protocol');
229231

230232

231-
$this->addExtensions($metadata);
233+
# $this->addExtensions($metadata);
232234

233-
$this->addCertificate($e, $metadata);
235+
# $this->addCertificate($e, $metadata);
234236

235237
if (array_key_exists('SingleLogoutService', $metadata)) {
236238
$t = $this->createElement('SingleLogoutService');
@@ -258,7 +260,8 @@ public function addMetadataSP20($metadata) {
258260
$e->appendChild($t);
259261
}
260262

261-
if (array_key_exists('name', $metadata) || array_key_exists('attributes', $metadata)) {
263+
264+
if ( array_key_exists('name', $metadata) || array_key_exists('attributes', $metadata)) {
262265
/**
263266
* Add an AttributeConsumingService element with information as name and description and list
264267
* of requested attributes
@@ -308,7 +311,7 @@ public function addMetadataSP20($metadata) {
308311

309312
$this->entityDescriptor->appendChild($e);
310313

311-
$this->addOrganizationInfo($metadata);
314+
# $this->addOrganizationInfo($metadata);
312315

313316
if (array_key_exists('contacts', $metadata) && is_array($metadata['contacts']) ) {
314317
foreach($metadata['contacts'] AS $contact) {
@@ -349,9 +352,9 @@ public function addMetadataIdP20($metadata) {
349352
$e->setAttribute('WantAuthnRequestSigned', 'true');
350353
}
351354

352-
$this->addExtensions($metadata);
355+
# $this->addExtensions($metadata);
353356

354-
$this->addCertificate($e, $metadata);
357+
# $this->addCertificate($e, $metadata);
355358

356359
if (array_key_exists('SingleLogoutService', $metadata)) {
357360
$t = $this->createElement('SingleLogoutService');
@@ -380,7 +383,7 @@ public function addMetadataIdP20($metadata) {
380383

381384
$this->entityDescriptor->appendChild($e);
382385

383-
$this->addOrganizationInfo($metadata);
386+
# $this->addOrganizationInfo($metadata);
384387

385388
if (array_key_exists('contacts', $metadata) && is_array($metadata['contacts']) ) {
386389
foreach($metadata['contacts'] AS $contact) {
@@ -415,7 +418,7 @@ public function addMetadataSP11($metadata) {
415418
$e = $this->createElement('SPSSODescriptor');
416419
$e->setAttribute('protocolSupportEnumeration', 'urn:oasis:names:tc:SAML:1.1:protocol');
417420

418-
$this->addCertificate($e, $metadata);
421+
# $this->addCertificate($e, $metadata);
419422

420423
if (array_key_exists('NameIDFormat', $metadata)) {
421424
$t = $this->createElement('NameIDFormat');
@@ -446,7 +449,7 @@ public function addMetadataIdP11($metadata) {
446449
$e = $this->createElement('IDPSSODescriptor');
447450
$e->setAttribute('protocolSupportEnumeration', 'urn:oasis:names:tc:SAML:1.1:protocol');
448451

449-
$this->addCertificate($e, $metadata);
452+
# $this->addCertificate($e, $metadata);
450453

451454
if (array_key_exists('NameIDFormat', $metadata)) {
452455
$t = $this->createElement('NameIDFormat');

lib/SimpleSAML/Metadata/SAMLParser.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ public function getMetadata20SP() {
618618
$ret['NameIDFormat'] = $spd['nameIDFormats'][0];
619619
}
620620

621+
if (array_key_exists('attributes', $spd)) {
622+
$ret['attributes'] = $spd['attributes'];
623+
}
621624

622625
/* Add certificate data. Only the first valid certificate will be added. */
623626
foreach($spd['keys'] as $key) {
@@ -818,6 +821,13 @@ private function processSPSSODescriptor($element, $expireTime) {
818821
$sp['assertionConsumerServices'][] = self::parseAssertionConsumerService($child);
819822
}
820823

824+
/* Find all the attributes and SP name... */
825+
#$sp['attributes'] = array();
826+
$attcs = SimpleSAML_Utilities::getDOMChildren($element, 'AttributeConsumingService', '@md');
827+
if (count($attcs) > 0) {
828+
self::parseAttributeConsumerService($attcs[0], &$sp);
829+
}
830+
821831

822832
$this->spDescriptors[] = $sp;
823833
}
@@ -973,6 +983,37 @@ private static function parseAssertionConsumerService($element) {
973983
}
974984

975985

986+
/**
987+
* This function parses AttributeConsumerService elements.
988+
*/
989+
private static function parseAttributeConsumerService($element, &$sp) {
990+
assert('$element instanceof DOMElement');
991+
assert('is_array($sp)');
992+
993+
$elements = SimpleSAML_Utilities::getDOMChildren($element, 'ServiceName', '@md');
994+
foreach($elements AS $child) {
995+
$language = $child->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang');
996+
if(empty($language)) $language = 'en';
997+
$sp['name'][$language] = SimpleSAML_Utilities::getDOMText($child);
998+
}
999+
1000+
$elements = SimpleSAML_Utilities::getDOMChildren($element, 'ServiceDescription', '@md');
1001+
foreach($elements AS $child) {
1002+
$language = $child->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang');
1003+
if(empty($language)) $language = 'en';
1004+
$sp['description'][$language] = SimpleSAML_Utilities::getDOMText($child);
1005+
}
1006+
1007+
$elements = SimpleSAML_Utilities::getDOMChildren($element, 'RequestedAttribute', '@md');
1008+
foreach($elements AS $child) {
1009+
$attrname = $child->getAttribute('Name');
1010+
if (!array_key_exists('attributes', $sp)) $sp['attributes'] = array();
1011+
$sp['attributes'][] = $attrname;
1012+
}
1013+
1014+
}
1015+
1016+
9761017
/**
9771018
* This function parses SingleLogoutService elements.
9781019
*

modules/metarefresh/hooks/hook_cron.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ function metarefresh_hook_cron(&$croninfo) {
2323
if (!in_array($croninfo['tag'], $set['cron'])) continue;
2424

2525
SimpleSAML_Logger::info('cron [metarefresh]: Executing set [' . $setkey . ']');
26-
27-
$maxcache = NULL; if (array_key_exists('maxcache', $set)) $maxcache = $set['maxcache'];
28-
$maxduration = NULL; if (array_key_exists('maxduration', $set)) $maxcache = $set['maxduration'];
29-
$metaloader = new sspmod_metarefresh_MetaLoader($maxcache, $maxduration);
26+
27+
$expire = NULL;
28+
if (array_key_exists('expireAfter', $set)) $expire = time() + $set['expireAfter'];
29+
30+
$metaloader = new sspmod_metarefresh_MetaLoader($expire);
3031

3132
foreach($set['sources'] AS $source) {
3233
SimpleSAML_Logger::debug('cron [metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']');

modules/metarefresh/lib/MetaLoader.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ class sspmod_metarefresh_MetaLoader {
99

1010
private $metadata;
1111

12-
private $maxcache;
13-
private $maxduration;
12+
private $expire;
1413

1514
/**
1615
* Constructor
1716
*
1817
* @param array $sources Sources...
1918
* @param
2019
*/
21-
public function __construct($maxcache = NULL, $maxduration = NULL) {
22-
$this->maxcache = $maxcache;
23-
$this->maxduration = $maxduration;
20+
public function __construct($expire = NULL) {
21+
$this->expire = $expire;
2422

2523
$this->metadata = array();
2624
}
@@ -41,7 +39,7 @@ public function loadSource($source) {
4139
continue;
4240
}
4341
}
44-
42+
4543
// TODO: $ca is always null
4644
if($ca !== NULL) {
4745
if(!$entity->validateCA($ca)) {
@@ -52,12 +50,10 @@ public function loadSource($source) {
5250
$template = NULL;
5351
if (array_key_exists('template', $source)) $template = $source['template'];
5452

55-
$expireDuration = time() + min($this->maxcache, $this->maxduration);
56-
57-
$this->addMetadata($source['src'], $entity->getMetadata1xSP(), 'shib13-sp-remote', $template, $expireDuration);
58-
$this->addMetadata($source['src'], $entity->getMetadata1xIdP(), 'shib13-idp-remote', $template, $expireDuration);
59-
$this->addMetadata($source['src'], $entity->getMetadata20SP(), 'saml20-sp-remote', $template, $expireDuration);
60-
$this->addMetadata($source['src'], $entity->getMetadata20IdP(), 'saml20-idp-remote', $template, $expireDuration);
53+
$this->addMetadata($source['src'], $entity->getMetadata1xSP(), 'shib13-sp-remote', $template);
54+
$this->addMetadata($source['src'], $entity->getMetadata1xIdP(), 'shib13-idp-remote', $template);
55+
$this->addMetadata($source['src'], $entity->getMetadata20SP(), 'saml20-sp-remote', $template);
56+
$this->addMetadata($source['src'], $entity->getMetadata20IdP(), 'saml20-idp-remote', $template);
6157
}
6258
}
6359

@@ -100,7 +96,7 @@ public function dumpMetadataStdOut() {
10096
* @param $metadata The metadata.
10197
* @param $type The metadata type.
10298
*/
103-
private function addMetadata($filename, $metadata, $type, $template = NULL, $expireDuration) {
99+
private function addMetadata($filename, $metadata, $type, $template = NULL) {
104100

105101
if($metadata === NULL) {
106102
return;
@@ -118,12 +114,23 @@ private function addMetadata($filename, $metadata, $type, $template = NULL, $exp
118114
$this->metadata[$type] = array();
119115
}
120116

121-
if (!array_key_exists('expire', $metadata)) {
122-
$metadata['expire'] = $expireDuration;
123-
} else {
124-
if ($expireDuration < $metadata['expire'])
125-
$metadata['expire'] = $expireDuration;
117+
// If expire is defined in constructor...
118+
if (!empty($this->expire)) {
119+
120+
// If expire is already in metadata
121+
if (array_key_exists('expire', $metadata)) {
122+
123+
// Override metadata expire with more restrictive global config-
124+
if ($this->expire < $metadata['expire'])
125+
$metadata['expire'] = $this->expire;
126+
127+
// If expire is not already in metadata use global config
128+
} else {
129+
$metadata['expire'] = $this->expire;
130+
}
126131
}
132+
133+
127134

128135
$this->metadata[$type][] = array('filename' => $filename, 'metadata' => $metadata);
129136
}

0 commit comments

Comments
 (0)