From f9a926ef847b53fcb9feb84f6ed1d89f7261bc7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Thu, 4 Jun 2009 07:15:59 +0000
Subject: [PATCH] Adding library file for creating ARP files for shibboleth

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1511 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/metarefresh/lib/ARP.php | 103 ++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)
 create mode 100644 modules/metarefresh/lib/ARP.php

diff --git a/modules/metarefresh/lib/ARP.php b/modules/metarefresh/lib/ARP.php
new file mode 100644
index 000000000..62f7fa389
--- /dev/null
+++ b/modules/metarefresh/lib/ARP.php
@@ -0,0 +1,103 @@
+<?php
+/*
+ * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
+ * @package simpleSAMLphp
+ * @version $Id$
+ */
+class sspmod_metarefresh_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 .= $this->prefix;
+		$ret .= $name;
+		if (!empty($this->suffix)) $ret .= $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) {
+			#$print_r($metadata); exit;
+			$xml .= $this->getEntryXML($metadata['metadata']);
+		}
+		
+		$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;
+	}
+
+}
+
-- 
GitLab