From eae7b85248b749623b934fc88d7aef964ad23ba4 Mon Sep 17 00:00:00 2001
From: Lasse Birnbaum Jensen <lasse@sdu.dk>
Date: Thu, 12 Jun 2008 07:07:20 +0000
Subject: [PATCH] Implemented issue 99.
 http://code.google.com/p/simplesamlphp/issues/detail?id=99

!! IMPORTANT !!
This patch may break existing configurations if custom attributealter functions are used.

To use the new implementation attributealter function must be placed in a specific file for that function.

Example: attributealter function insertorgname which insert a static organization name in the attribute set.

Function must be placed in file attributealter/insertorgname.php and have the following content.

attributealter/insertorgname.php
<?php

function attributealter_insertorgname($attributes,$spid = null, $idpid=null) {
$attributes['orgname']=array('static name');
}





git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@636 44740490-163a-0410-bde0-09ae8108e29a
---
 attributealter/edupersontargetid.php          | 10 +++++
 .../{alterfunctions.php => groups.php}        | 38 +------------------
 attributealter/realm.php                      | 19 ++++++++++
 attributealter/test.php                       |  5 +++
 lib/SimpleSAML/XML/AttributeFilter.php        |  6 +--
 5 files changed, 38 insertions(+), 40 deletions(-)
 create mode 100644 attributealter/edupersontargetid.php
 rename attributealter/{alterfunctions.php => groups.php} (64%)
 create mode 100644 attributealter/realm.php
 create mode 100644 attributealter/test.php

diff --git a/attributealter/edupersontargetid.php b/attributealter/edupersontargetid.php
new file mode 100644
index 000000000..b1d4e2ccb
--- /dev/null
+++ b/attributealter/edupersontargetid.php
@@ -0,0 +1,10 @@
+<?php
+function attributealter_edupersontargetedid(&$attributes, $spEntityId = null, $idpEntityId = null) {
+	assert('$spEntityId !== NULL');
+	assert('$idpEntityId !== NULL');
+
+	$userid = SimpleSAML_Utilities::generateUserIdentifier($idpEntityId, $spEntityId, $attributes);
+
+	$attributes['eduPersonTargetedID'] = array($userid);
+}
+?>
\ No newline at end of file
diff --git a/attributealter/alterfunctions.php b/attributealter/groups.php
similarity index 64%
rename from attributealter/alterfunctions.php
rename to attributealter/groups.php
index 3e3ec46b2..00d649008 100644
--- a/attributealter/alterfunctions.php
+++ b/attributealter/groups.php
@@ -1,8 +1,4 @@
 <?php
-
-
-
-
 function encodeIllegalChars($input) {
 	return preg_replace("/[^a-zA-Z0-9_@=.]/", "_", $input);
 }
@@ -72,36 +68,4 @@ function attributealter_groups(&$attributes, $spentityid = null, $idpentityid =
 	$attributes['groups'] = $groups;
 
 }
-
-
-
-function attributealter_test(&$attributes, $spentityid = null, $idpentityid = null) {
-	$attributes['injected'] = array('newvalue');
-}
-
-function attributealter_realm(&$attributes, $spentityid = null, $idpentityid = null) {
-
-	$attributename = 'eduPersonPrincipalName';
-#	$attributename = 'edupersonprincipalname';
-	if (array_key_exists($attributename, $attributes)) {
-		$eduppn = $attributes[$attributename][0];
-		$splitted = explode('@', $eduppn);
-		if (count($splitted) > 1) {
-			$attributes['realm'] = array($splitted[1]);
-		} else {
-			SimpleSAML_Logger::debug('attributealter_realm: Wrong format on ' . $attributename . ' (not including @)');
-		}
-	} else {
-		SimpleSAML_Logger::debug('attributealter_realm: Could not find ' . $attributename);
-	}
-
-}
-
-function attributealter_edupersontargetedid(&$attributes, $spEntityId = null, $idpEntityId = null) {
-	assert('$spEntityId !== NULL');
-	assert('$idpEntityId !== NULL');
-
-	$userid = SimpleSAML_Utilities::generateUserIdentifier($idpEntityId, $spEntityId, $attributes);
-
-	$attributes['eduPersonTargetedID'] = array($userid);
-}
+?>
\ No newline at end of file
diff --git a/attributealter/realm.php b/attributealter/realm.php
new file mode 100644
index 000000000..a279d50b1
--- /dev/null
+++ b/attributealter/realm.php
@@ -0,0 +1,19 @@
+<?php
+function attributealter_realm(&$attributes, $spentityid = null, $idpentityid = null) {
+
+	$attributename = 'eduPersonPrincipalName';
+#	$attributename = 'edupersonprincipalname';
+	if (array_key_exists($attributename, $attributes)) {
+		$eduppn = $attributes[$attributename][0];
+		$splitted = explode('@', $eduppn);
+		if (count($splitted) > 1) {
+			$attributes['realm'] = array($splitted[1]);
+		} else {
+			SimpleSAML_Logger::debug('attributealter_realm: Wrong format on ' . $attributename . ' (not including @)');
+		}
+	} else {
+		SimpleSAML_Logger::debug('attributealter_realm: Could not find ' . $attributename);
+	}
+
+}
+?>
\ No newline at end of file
diff --git a/attributealter/test.php b/attributealter/test.php
new file mode 100644
index 000000000..6f3c0f8bb
--- /dev/null
+++ b/attributealter/test.php
@@ -0,0 +1,5 @@
+<?php
+function attributealter_test(&$attributes, $spentityid = null, $idpentityid = null) {
+	$attributes['injected'] = array('newvalue');
+}
+?>
\ No newline at end of file
diff --git a/lib/SimpleSAML/XML/AttributeFilter.php b/lib/SimpleSAML/XML/AttributeFilter.php
index bc359ad8d..39d19d32a 100644
--- a/lib/SimpleSAML/XML/AttributeFilter.php
+++ b/lib/SimpleSAML/XML/AttributeFilter.php
@@ -93,8 +93,8 @@ class SimpleSAML_XML_AttributeFilter {
 	 */
 	public function alter($rule, $spentityid = null, $idpentityid = null) {
 		
-		$alterfile = $this->configuration->getBaseDir() . 'attributealter/alterfunctions.php';
-		if (!file_exists($alterfile)) throw new Exception('Could not find attributemap file: ' . $alterfile);
+		$alterfile = $this->configuration->getBaseDir() . 'attributealter/' . $rule . '.php';
+		if (!file_exists($alterfile)) throw new Exception('Could not find attributealter file: ' . $alterfile);
 		
 		include_once($alterfile);
 		
@@ -103,7 +103,7 @@ class SimpleSAML_XML_AttributeFilter {
 		if (function_exists($function)) {
 			$function($this->attributes, $spentityid, $idpentityid);
 		} else {
-			throw new Exception('Could not find attribute alter fucntion: ' . $function);
+			throw new Exception('Could not find attribute alter fucntion: ' . $function . ' in file ' .$alterfile);
 		}
 		
 	}
-- 
GitLab