File: ARP.php

package info (click to toggle)
simplesamlphp 1.13.1-2%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,304 kB
  • sloc: php: 65,124; xml: 629; python: 376; sh: 193; perl: 185; makefile: 43
file content (106 lines) | stat: -rw-r--r-- 2,907 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
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
<?php
/*
 * @author Andreas Åkre Solberg <andreas.solberg@uninett.no>
 * @package simpleSAMLphp
 */
class sspmod_aggregator_ARP {


	private $metadata;
	private $attributes;
	private $prefix;
	private $suffix;

	/**
	 * Constructor
	 *
	 * @param 
	 */
	public function __construct($metadata, $attributemap, $prefix, $suffix) {
		$this->metadata = $metadata;
		
		$this->prefix = $prefix;
		$this->suffix = $suffix;
		
		if (isset($attributemap)) $this->loadAttributeMap($attributemap);
	}
	
	private function loadAttributeMap($attributemap) {
		$config = SimpleSAML_Configuration::getInstance();
		include($config->getPathValue('attributemap', 'attributemap/') . $attributemap . '.php');
		$this->attributes = $attributemap;
		
	#	print_r($attributemap); exit;
	}

	private function surround($name) {
		$ret = '';
		if (!empty($this->prefix)) $ret .= htmlspecialchars($this->prefix);
		$ret .= $name;
		if (!empty($this->suffix)) $ret .= htmlspecialchars($this->suffix);
		return $ret;
	}

	private function getAttributeID($name) {
		if (empty($this->attributes)) {
			return $this->surround($name);
		} 
		if (array_key_exists($name, $this->attributes)) {
			return $this->surround($this->attributes[$name]);
		}
		return $this->surround($name);
	}

	public function getXML() {
		
		$xml = '<?xml version="1.0" encoding="UTF-8"?>
<AttributeFilterPolicyGroup id="urn:mace:funet.fi:haka:kalmar" xmlns="urn:mace:shibboleth:2.0:afp"
    xmlns:basic="urn:mace:shibboleth:2.0:afp:mf:basic" xmlns:saml="urn:mace:shibboleth:2.0:afp:mf:saml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:mace:shibboleth:2.0:afp classpath:/schema/shibboleth-2.0-afp.xsd
                        urn:mace:shibboleth:2.0:afp:mf:basic classpath:/schema/shibboleth-2.0-afp-mf-basic.xsd
                        urn:mace:shibboleth:2.0:afp:mf:saml classpath:/schema/shibboleth-2.0-afp-mf-saml.xsd">
';
		
		
		foreach($this->metadata AS $metadata) {
			#echo '<pre>'; print_r($metadata); # exit;
			if (isset($metadata['saml20-sp-remote'])) {
				#echo '<pre>'; print_r($metadata); exit;
				$xml .= $this->getEntryXML($metadata['saml20-sp-remote']);
			}
			
		}
		
		$xml .= '</AttributeFilterPolicyGroup>';
		return $xml;
	}

	private function getEntryXML($entry) {
		$entityid = $entry['entityid'];
		return '	<AttributeFilterPolicy id="' . $entityid . '">
		<PolicyRequirementRule xsi:type="basic:AttributeRequesterString" value="' . $entityid . '" />
' . $this->getEntryXMLcontent($entry) . '
	</AttributeFilterPolicy>
';
	}
	
	private function getEntryXMLcontent($entry) {
		$ids = array();
		if (!array_key_exists('attributes', $entry)) 
			return '';
		
		$ret = '';
		foreach($entry['attributes'] AS $a) {
			
			$ret .= '			<AttributeRule attributeID="' . $this->getAttributeID($a) . '">
				<PermitValueRule xsi:type="basic:ANY" />
			</AttributeRule>
';
			
		}
		return $ret;
	}

}