Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
31cf4312
Commit
31cf4312
authored
9 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Fix several issues with the core:AttributeValueMap filter.
parent
929edf0d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/core/lib/Auth/Process/AttributeValueMap.php
+41
-23
41 additions, 23 deletions
modules/core/lib/Auth/Process/AttributeValueMap.php
with
41 additions
and
23 deletions
modules/core/lib/Auth/Process/AttributeValueMap.php
+
41
−
23
View file @
31cf4312
...
@@ -12,32 +12,32 @@ class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
...
@@ -12,32 +12,32 @@ class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
{
{
/**
/**
* The attribute
name
we should assign values to (ie target
)
* The
name of the
attribute we should assign values to (ie
: the
target
attribute).
*/
*/
private
$targetattribute
;
private
$targetattribute
;
/**
/**
* The attribute
name
we should create values from
* The
name of the
attribute we should create values from
.
*/
*/
private
$sourceattribute
;
private
$sourceattribute
;
/**
/**
* The required $sourceattribute values and target affiliations
* The required $sourceattribute values and target affiliations
.
*/
*/
private
$values
=
array
();
private
$values
=
array
();
/**
/**
* Whether $sourceattribute should be kept
* Whether $sourceattribute should be kept
or not.
*/
*/
private
$keep
=
false
;
private
$keep
=
false
;
/**
/**
* Whether $target attribute values should be replaced by new values
* Whether $target attribute values should be replaced by new values
or not.
*/
*/
private
$replace
=
false
;
private
$replace
=
false
;
/**
/**
* Initialize th
is
filter.
* Initialize th
e
filter.
*
*
* @param array $config Configuration information about this filter.
* @param array $config Configuration information about this filter.
* @param mixed $reserved For future use.
* @param mixed $reserved For future use.
...
@@ -49,35 +49,49 @@ class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
...
@@ -49,35 +49,49 @@ class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
assert
(
'is_array($config)'
);
assert
(
'is_array($config)'
);
//
validat
e configuration
//
pars
e configuration
foreach
(
$config
as
$name
=>
$value
)
{
foreach
(
$config
as
$name
=>
$value
)
{
if
(
is_int
(
$name
))
{
if
(
is_int
(
$name
))
{
// check if this is an option
// check if this is an option
if
(
$value
===
'%replace'
)
{
if
(
$value
===
'%replace'
)
{
$this
->
replace
=
true
;
$this
->
replace
=
true
;
}
elseif
(
$value
===
'%keep'
)
{
}
elseif
(
$value
===
'%keep'
)
{
$this
->
keep
=
true
;
$this
->
keep
=
true
;
}
else
{
}
else
{
throw
new
\SimpleSAML_Error_Exception
(
'Unknown flag : '
.
var_export
(
$value
,
true
));
// unknown configuration option, log it and ignore the error
\SimpleSAML_Logger
::
warning
(
"AttributeValueMap: unknown configuration flag '"
.
var_export
(
$value
,
true
)
.
"'"
);
}
}
continue
;
continue
;
}
}
// set targetattribute
// set
the
target
attribute
if
(
$name
===
'targetattribute'
)
{
if
(
$name
===
'targetattribute'
)
{
$this
->
targetattribute
=
$value
;
$this
->
targetattribute
=
$value
;
}
}
// set sourceattribute
// set
the
source
attribute
if
(
$name
===
'sourceattribute'
)
{
if
(
$name
===
'sourceattribute'
)
{
$this
->
sourceattribute
=
$value
;
$this
->
sourceattribute
=
$value
;
}
}
// set values
// set
the
values
if
(
$name
===
'values'
)
{
if
(
$name
===
'values'
)
{
$this
->
values
=
$value
;
$this
->
values
=
$value
;
}
}
}
}
// now validate it
if
(
!
is_string
(
$this
->
sourceattribute
))
{
throw
new
\SimpleSAML_Error_Exception
(
"AttributeValueMap: 'sourceattribute' configuration option not set."
);
}
if
(
!
is_string
(
$this
->
targetattribute
))
{
throw
new
\SimpleSAML_Error_Exception
(
"AttributeValueMap: 'targetattribute' configuration option not set."
);
}
if
(
!
is_array
(
$this
->
values
))
{
throw
new
\SimpleSAML_Error_Exception
(
"AttributeValueMap: 'values' configuration option is not an array."
);
}
}
}
...
@@ -88,31 +102,34 @@ class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
...
@@ -88,31 +102,34 @@ class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
*/
*/
public
function
process
(
&
$request
)
public
function
process
(
&
$request
)
{
{
\SimpleSAML_Logger
::
debug
(
'AttributeValueMap
- process
'
);
\SimpleSAML_Logger
::
debug
(
'
Processing the
AttributeValueMap
filter.
'
);
assert
(
'is_array($request)'
);
assert
(
'is_array($request)'
);
assert
(
'array_key_exists("Attributes", $request)'
);
assert
(
'array_key_exists("Attributes", $request)'
);
$attributes
=&
$request
[
'Attributes'
];
$attributes
=&
$request
[
'Attributes'
];
// Make sure sourceattribute exists
if
(
!
array_key_exists
(
$this
->
sourceattribute
,
$attributes
))
{
assert
(
'array_key_exists($this->
sourceattribute
, $attributes)'
);
// the
source
attribute
does not exist, nothing to do here
// Make sure the targetattribute is set
return
;
assert
(
'is_string($this->targetattribute)'
);
}
$sourceattribute
=
$attributes
[
$this
->
sourceattribute
];
$sourceattribute
=
$attributes
[
$this
->
sourceattribute
];
$targetvalues
=
array
();
$targetvalues
=
array
();
if
(
is_array
(
$sourceattribute
))
{
if
(
is_array
(
$sourceattribute
))
{
foreach
(
$this
->
values
as
$value
=>
$require
)
{
foreach
(
$this
->
values
as
$value
=>
$values
)
{
if
(
count
(
array_intersect
(
$require
,
$sourceattribute
))
>
0
)
{
if
(
!
is_array
(
$values
))
{
\SimpleSAML_Logger
::
debug
(
'AttributeValueMap - intersect match for '
.
$value
);
$values
=
array
(
$values
);
}
if
(
count
(
array_intersect
(
$values
,
$sourceattribute
))
>
0
)
{
\SimpleSAML_Logger
::
debug
(
"AttributeValueMap: intersect match for '
$value
'"
);
$targetvalues
[]
=
$value
;
$targetvalues
[]
=
$value
;
}
}
}
}
}
}
if
(
count
(
$targetvalues
)
>
0
)
{
if
(
count
(
$targetvalues
)
>
0
)
{
if
(
$this
->
replace
or
!@
is_array
(
$attributes
[
$this
->
targetattribute
]
))
{
if
(
$this
->
replace
||
!
array_key_exists
(
$this
->
targetattribute
,
$attributes
))
{
$attributes
[
$this
->
targetattribute
]
=
$targetvalues
;
$attributes
[
$this
->
targetattribute
]
=
$targetvalues
;
}
else
{
}
else
{
$attributes
[
$this
->
targetattribute
]
=
array_unique
(
array_merge
(
$attributes
[
$this
->
targetattribute
]
=
array_unique
(
array_merge
(
...
@@ -123,6 +140,7 @@ class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
...
@@ -123,6 +140,7 @@ class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
}
}
if
(
!
$this
->
keep
)
{
if
(
!
$this
->
keep
)
{
// no need to keep the source attribute
unset
(
$attributes
[
$this
->
sourceattribute
]);
unset
(
$attributes
[
$this
->
sourceattribute
]);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment