Revision: 2158
Author: olavmrk
Date: Mon Feb  1 01:47:00 2010
Log: core: Add ScopeAttribute filter.
http://code.google.com/p/simplesamlphp/source/detail?r=2158

Added:
 /trunk/modules/core/docs/authproc_scopeattribute.txt
 /trunk/modules/core/lib/Auth/Process/ScopeAttribute.php

=======================================
--- /dev/null
+++ /trunk/modules/core/docs/authproc_scopeattribute.txt Mon Feb 1 01:47:00 2010
@@ -0,0 +1,40 @@
+`core:ScopeAttribute`
+=====================
+
+A filter which combines two attributes into a scoped attribute.
+
+Parameters
+----------
+
+`scopeAttribute`
+:   The attribute that contains the scope.
+
+: If the attribute contains a '@', we will take the scope from the part following the '@'.
+    Otherwise, we will use the entire value.
+
+: If the attribute is multi-valued, we will add all the scopes to the target.
+
+
+`sourceAttribute`
+:   The attribute that contains the values we shall add the scope to.
+
+: This attribute can be multi-valued, in which case we will add all the values.
+
+`targetAttribute`
+:   The attribute we shall add the scoped attributes to.
+
+: If the attribute already exists, the new values will be merged into the existing attribute.
+
+
+Example
+-------
+
+Add eduPersonScopedAffiliation based on eduPersonAffiliation and eduPersonPrincipalName.
+
+    10 => array(
+        'class' => 'core:ScopeAttribute',
+        'scopeAttribute' => 'eduPersonPrincipalName',
+        'sourceAttribute' => 'eduPersonAffiliation',
+        'targetAttribute' => 'eduPersonScopedAffiliation',
+    ),
+
=======================================
--- /dev/null
+++ /trunk/modules/core/lib/Auth/Process/ScopeAttribute.php Mon Feb 1 01:47:00 2010
@@ -0,0 +1,97 @@
+<?php
+
+/**
+ * Add a scoped variant of an attribute.
+ *
+ * @package simpleSAMLphp
+ * @version $Id$
+ */
+class sspmod_core_Auth_Process_ScopeAttribute extends SimpleSAML_Auth_ProcessingFilter {
+
+       /**
+        * The attribute we extract the scope from.
+        *
+        * @var string
+        */
+       private $scopeAttribute;
+
+
+       /**
+        * The attribute we want to add scope to.
+        *
+        * @var string
+        */
+       private $sourceAttribute;
+
+
+       /**
+        * The attribute we want to add the scoped attributes to.
+        *
+        * @var string
+        */
+       private $targetAttribute;
+
+
+       /**
+        * Initialize this filter, parse configuration
+        *
+        * @param array $config  Configuration information about this filter.
+        * @param mixed $reserved  For future use.
+        */
+       public function __construct($config, $reserved) {
+               parent::__construct($config, $reserved);
+               assert('is_array($config)');
+
+ $config = SimpleSAML_Configuration::loadFromArray($config, 'ScopedAttributes');
+
+               $this->scopeAttribute = $config->getString('scopeAttribute');
+               $this->sourceAttribute = $config->getString('sourceAttribute');
+               $this->targetAttribute = $config->getString('targetAttribute');
+       }
+
+
+       /**
+        * Apply filter to rename attributes.
+        *
+        * @param array &$request  The current request
+        */
+       public function process(&$request) {
+               assert('is_array($request)');
+               assert('array_key_exists("Attributes", $request)');
+
+               $attributes =& $request['Attributes'];
+
+               if (!isset($attributes[$this->scopeAttribute])) {
+                       return;
+               }
+
+               if (!isset($attributes[$this->sourceAttribute])) {
+                       return;
+               }
+
+               if (!isset($attributes[$this->targetAttribute])) {
+                       $attributes[$this->targetAttribute] = array();
+               }
+
+               foreach ($attributes[$this->scopeAttribute] as $scope) {
+
+                       if (strpos($scope, '@') !== FALSE) {
+                               $scope = explode('@', $scope, 2);
+                               $scope = $scope[1];
+                       }
+
+                       foreach ($attributes[$this->sourceAttribute] as $value) 
{
+                               $value = $value . '@' . $scope;
+
+                               if (in_array($value, 
$attributes[$this->targetAttribute], TRUE)) {
+                                       /* Already present. */
+                                       continue;
+                               }
+
+                               $attributes[$this->targetAttribute][] = $value;
+                       }
+               }
+
+       }
+
+}

--
You received this message because you are subscribed to the Google Groups 
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simplesamlphp-commits?hl=en.

Reply via email to