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
0
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
810e11de
Commit
810e11de
authored
6 years ago
by
Tim van Dijen
Browse files
Options
Downloads
Patches
Plain Diff
PSR2 / whitspace
parent
44d75c12
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/smartattributes/lib/Auth/Process/SmartID.php
+116
-113
116 additions, 113 deletions
modules/smartattributes/lib/Auth/Process/SmartID.php
modules/smartattributes/lib/Auth/Process/SmartName.php
+71
-58
71 additions, 58 deletions
modules/smartattributes/lib/Auth/Process/SmartName.php
with
187 additions
and
171 deletions
modules/smartattributes/lib/Auth/Process/SmartID.php
+
116
−
113
View file @
810e11de
<?php
<?php
class
sspmod_smartattributes_Auth_Process_SmartID
extends
SimpleSAML_Auth_ProcessingFilter
{
class
sspmod_smartattributes_Auth_Process_SmartID
extends
SimpleSAML_Auth_ProcessingFilter
{
/**
/**
* Which attributes to use as identifiers?
* Which attributes to use as identifiers?
*
*
* IMPORTANT: If you use the (default) attributemaps (twitter2name, facebook2name,
* IMPORTANT: If you use the (default) attributemaps (twitter2name, facebook2name,
* etc., be sure to comment out the entries that map xxx_targetedID to
* etc., be sure to comment out the entries that map xxx_targetedID to
* eduPersonTargetedID, or there will be no way to see its origin any more.
* eduPersonTargetedID, or there will be no way to see its origin any more.
*/
*/
private
$_candidates
=
array
(
private
$_candidates
=
array
(
'eduPersonTargetedID'
,
'eduPersonTargetedID'
,
'eduPersonPrincipalName'
,
'eduPersonPrincipalName'
,
'openid'
,
'openid'
,
'facebook_targetedID'
,
'facebook_targetedID'
,
'twitter_targetedID'
,
'twitter_targetedID'
,
'windowslive_targetedID'
,
'windowslive_targetedID'
,
'linkedin_targetedID'
,
'linkedin_targetedID'
,
);
);
/**
/**
* The name of the generated ID attribute.
* The name of the generated ID attribute.
*/
*/
private
$_id_attribute
=
'smart_id'
;
private
$_id_attribute
=
'smart_id'
;
/**
/**
* Whether to append the AuthenticatingAuthority, separated by '!'
* Whether to append the AuthenticatingAuthority, separated by '!'
* This only works when SSP is used as a gateway.
* This only works when SSP is used as a gateway.
*/
*/
private
$_add_authority
=
true
;
private
$_add_authority
=
true
;
/**
/**
* Whether to prepend the CandidateID, separated by ':'
* Whether to prepend the CandidateID, separated by ':'
*/
*/
private
$_add_candidate
=
true
;
private
$_add_candidate
=
true
;
/**
/**
* Attributes which should be added/appended.
* Attributes which should be added/appended.
*
*
* Associative array of arrays.
* Associative array of arrays.
*/
*/
private
$attributes
=
array
();
private
$attributes
=
array
();
public
function
__construct
(
$config
,
$reserved
)
{
public
function
__construct
(
$config
,
$reserved
)
parent
::
__construct
(
$config
,
$reserved
);
{
parent
::
__construct
(
$config
,
$reserved
);
assert
(
is_array
(
$config
));
assert
(
is_array
(
$config
));
if
(
array_key_exists
(
'candidates'
,
$config
))
{
$this
->
_candidates
=
$config
[
'candidates'
];
if
(
array_key_exists
(
'candidates'
,
$config
))
{
if
(
!
is_array
(
$this
->
_candidates
))
{
$this
->
_candidates
=
$config
[
'candidates'
];
throw
new
Exception
(
'SmartID authproc configuration error: \'candidates\' should be an array.'
);
if
(
!
is_array
(
$this
->
_candidates
))
{
}
throw
new
Exception
(
'SmartID authproc configuration error: \'candidates\' should be an array.'
);
}
}
}
if
(
array_key_exists
(
'id_attribute'
,
$config
))
{
$this
->
_id_attribute
=
$config
[
'id_attribute'
];
if
(
array_key_exists
(
'id_attribute'
,
$config
))
{
if
(
!
is_string
(
$this
->
_id_attribute
))
{
$this
->
_id_attribute
=
$config
[
'id_attribute'
];
throw
new
Exception
(
'SmartID authproc configuration error: \'id_attribute\' should be a string.'
);
if
(
!
is_string
(
$this
->
_id_attribute
))
{
}
throw
new
Exception
(
'SmartID authproc configuration error: \'id_attribute\' should be a string.'
);
}
}
}
if
(
array_key_exists
(
'add_authority'
,
$config
))
{
$this
->
_add_authority
=
$config
[
'add_authority'
];
if
(
array_key_exists
(
'add_authority'
,
$config
))
{
if
(
!
is_bool
(
$this
->
_add_authority
))
{
$this
->
_add_authority
=
$config
[
'add_authority'
];
throw
new
Exception
(
'SmartID authproc configuration error: \'add_authority\' should be a boolean.'
);
if
(
!
is_bool
(
$this
->
_add_authority
))
{
}
throw
new
Exception
(
'SmartID authproc configuration error: \'add_authority\' should be a boolean.'
);
}
}
}
if
(
array_key_exists
(
'add_candidate'
,
$config
))
{
$this
->
_add_candidate
=
$config
[
'add_candidate'
];
if
(
array_key_exists
(
'add_candidate'
,
$config
))
{
if
(
!
is_bool
(
$this
->
_add_candidate
))
{
$this
->
_add_candidate
=
$config
[
'add_candidate'
];
throw
new
Exception
(
'SmartID authproc configuration error: \'add_candidate\' should be a boolean.'
);
if
(
!
is_bool
(
$this
->
_add_candidate
))
{
}
throw
new
Exception
(
'SmartID authproc configuration error: \'add_candidate\' should be a boolean.'
);
}
}
}
}
}
private
function
addID
(
$attributes
,
$request
)
{
private
function
addID
(
$attributes
,
$request
)
{
$state
=
$request
[
'saml:sp:State'
];
$state
=
$request
[
'saml:sp:State'
];
foreach
(
$this
->
_candidates
as
$idCandidate
)
{
foreach
(
$this
->
_candidates
as
$idCandidate
)
{
if
(
isset
(
$attributes
[
$idCandidate
][
0
]))
{
if
(
isset
(
$attributes
[
$idCandidate
][
0
]))
{
if
((
$this
->
_add_authority
)
&&
(
isset
(
$state
[
'saml:AuthenticatingAuthority'
][
0
])))
{
if
((
$this
->
_add_authority
)
&&
(
isset
(
$state
[
'saml:AuthenticatingAuthority'
][
0
])))
{
return
(
$this
->
_add_candidate
?
$idCandidate
.
':'
:
''
)
.
$attributes
[
$idCandidate
][
0
]
.
'!'
.
$state
[
'saml:AuthenticatingAuthority'
][
0
];
return
(
$this
->
_add_candidate
?
$idCandidate
.
':'
:
''
)
.
$attributes
[
$idCandidate
][
0
]
.
'!'
.
$state
[
'saml:AuthenticatingAuthority'
][
0
];
}
else
{
}
else
{
return
(
$this
->
_add_candidate
?
$idCandidate
.
':'
:
''
)
.
$attributes
[
$idCandidate
][
0
];
return
(
$this
->
_add_candidate
?
$idCandidate
.
':'
:
''
)
.
$attributes
[
$idCandidate
][
0
];
}
}
}
}
}
}
/*
/*
* At this stage no usable id_candidate has been detected.
* At this stage no usable id_candidate has been detected.
*/
*/
throw
new
SimpleSAML_Error_Exception
(
'This service needs at least one of the following
throw
new
SimpleSAML_Error_Exception
(
'This service needs at least one of the following
attributes to identity users: '
.
implode
(
', '
,
$this
->
_candidates
)
.
'. Unfortunately not
attributes to identity users: '
.
implode
(
', '
,
$this
->
_candidates
)
.
'. Unfortunately not
one of them was detected. Please ask your institution administrator to release one of
one of them was detected. Please ask your institution administrator to release one of
them, or try using another identity provider.'
);
them, or try using another identity provider.'
);
}
}
/**
/**
* Apply filter to add or replace attributes.
* Apply filter to add or replace attributes.
*
*
* Add or replace existing attributes with the configured values.
* Add or replace existing attributes with the configured values.
*
*
* @param array &$request The current request
* @param array &$request The current request
*/
*/
public
function
process
(
&
$request
)
public
function
process
(
&
$request
)
{
{
assert
(
is_array
(
$request
));
assert
(
is_array
(
$request
));
assert
(
array_key_exists
(
'Attributes'
,
$request
));
assert
(
array_key_exists
(
'Attributes'
,
$request
));
$ID
=
$this
->
addID
(
$request
[
'Attributes'
],
$request
);
$id
=
$this
->
addID
(
$request
[
'Attributes'
],
$request
);
if
(
isset
(
$ID
))
$request
[
'Attributes'
][
$this
->
_id_attribute
]
=
array
(
$ID
);
if
(
isset
(
$id
))
{
}
$request
[
'Attributes'
][
$this
->
_id_attribute
]
=
array
(
$id
);
}
}
}
}
This diff is collapsed.
Click to expand it.
modules/smartattributes/lib/Auth/Process/SmartName.php
+
71
−
58
View file @
810e11de
...
@@ -6,71 +6,84 @@
...
@@ -6,71 +6,84 @@
* @author Andreas Åkre Solberg, UNINETT AS.
* @author Andreas Åkre Solberg, UNINETT AS.
* @package SimpleSAMLphp
* @package SimpleSAMLphp
*/
*/
class
sspmod_smartattributes_Auth_Process_SmartName
extends
SimpleSAML_Auth_ProcessingFilter
{
class
sspmod_smartattributes_Auth_Process_SmartName
extends
SimpleSAML_Auth_ProcessingFilter
{
/**
* Attributes which should be added/appended.
*
* Assiciative array of arrays.
*/
private
$attributes
=
array
();
/**
* Attributes which should be added/appended.
*
* Assiciative array of arrays.
*/
private
$attributes
=
array
();
private
function
getFullName
(
$attributes
)
{
if
(
isset
(
$attributes
[
'displayName'
]))
{
return
$attributes
[
'displayName'
][
0
];
}
private
function
getFullName
(
$attributes
)
{
if
(
isset
(
$attributes
[
'cn'
]))
{
if
(
isset
(
$attributes
[
'displayName'
]))
if
(
count
(
explode
(
' '
,
$attributes
[
'cn'
][
0
]))
>
1
)
{
return
$attributes
[
'displayName'
][
0
];
return
$attributes
[
'cn'
][
0
];
}
if
(
isset
(
$attributes
[
'cn'
]))
{
}
if
(
count
(
explode
(
' '
,
$attributes
[
'cn'
][
0
]))
>
1
)
return
$attributes
[
'cn'
][
0
];
}
if
(
isset
(
$attributes
[
'sn'
])
&&
isset
(
$attributes
[
'givenName'
]))
return
$attributes
[
'givenName'
][
0
]
.
' '
.
$attributes
[
'sn'
][
0
];
if
(
isset
(
$attributes
[
'cn'
]))
if
(
isset
(
$attributes
[
'sn'
])
&&
isset
(
$attributes
[
'givenName'
]))
{
return
$attributes
[
'cn'
][
0
];
return
$attributes
[
'givenName'
][
0
]
.
' '
.
$attributes
[
'sn'
][
0
];
}
if
(
isset
(
$attributes
[
'sn'
]))
if
(
isset
(
$attributes
[
'cn'
]))
{
return
$attributes
[
'sn'
][
0
];
return
$attributes
[
'cn'
][
0
];
}
if
(
isset
(
$attributes
[
'givenName'
]))
if
(
isset
(
$attributes
[
'sn'
]))
{
return
$attributes
[
'givenName'
][
0
];
return
$attributes
[
'sn'
][
0
];
}
if
(
isset
(
$attributes
[
'eduPersonPrincipalName'
]))
{
$localname
=
$this
->
getLocalUser
(
$attributes
[
'eduPersonPrincipalName'
][
0
]);
if
(
isset
(
$localname
))
return
$localname
;
}
return
NULL
;
}
private
function
getLocalUser
(
$userid
)
{
if
(
strpos
(
$userid
,
'@'
)
===
FALSE
)
return
NULL
;
$decomposed
=
explode
(
'@'
,
$userid
);
if
(
count
(
$decomposed
)
===
2
)
{
return
$decomposed
[
0
];
}
return
NULL
;
}
/**
if
(
isset
(
$attributes
[
'givenName'
]))
{
* Apply filter to add or replace attributes.
return
$attributes
[
'givenName'
][
0
];
*
}
* Add or replace existing attributes with the configured values.
*
* @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
[
'eduPersonPrincipalName'
]))
{
$localname
=
$this
->
getLocalUser
(
$attributes
[
'eduPersonPrincipalName'
][
0
]);
$fullname
=
$this
->
getFullName
(
$attributes
);
if
(
isset
(
$localname
))
{
return
$localname
;
if
(
isset
(
$fullname
))
$request
[
'Attributes'
][
'smartname-fullname'
]
=
array
(
$fullname
);
}
}
}
return
null
;
}
private
function
getLocalUser
(
$userid
)
{
if
(
strpos
(
$userid
,
'@'
)
===
false
)
{
return
null
;
}
$decomposed
=
explode
(
'@'
,
$userid
);
if
(
count
(
$decomposed
)
===
2
)
{
return
$decomposed
[
0
];
}
return
null
;
}
/**
* Apply filter to add or replace attributes.
*
* Add or replace existing attributes with the configured values.
*
* @param array &$request The current request
*/
public
function
process
(
&
$request
)
{
assert
(
is_array
(
$request
));
assert
(
array_key_exists
(
'Attributes'
,
$request
));
$attributes
=&
$request
[
'Attributes'
];
$fullname
=
$this
->
getFullName
(
$attributes
);
if
(
isset
(
$fullname
))
{
$request
[
'Attributes'
][
'smartname-fullname'
]
=
array
(
$fullname
);
}
}
}
}
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