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
2f144862
Commit
2f144862
authored
10 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Move SimpleSAML_Utilities::getDefaultEndpoint() to SimpleSAML_Utils_Config_Metadata.
parent
093e5e56
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
lib/SimpleSAML/Utils/Config/Metadata.php
+77
-9
77 additions, 9 deletions
lib/SimpleSAML/Utils/Config/Metadata.php
with
77 additions
and
9 deletions
lib/SimpleSAML/Utils/Config/Metadata.php
+
77
−
9
View file @
2f144862
<?php
<?php
/**
/**
* Class with utilities to fetch different configuration objects from metadata configuration arrays.
* Class with utilities to fetch different configuration objects from metadata configuration arrays.
*
*
...
@@ -13,7 +15,12 @@ class SimpleSAML_Utils_Config_Metadata
...
@@ -13,7 +15,12 @@ class SimpleSAML_Utils_Config_Metadata
* @see "Metadata for the OASIS Security Assertion Markup Language (SAML) V2.0", section 2.3.2.2.
* @see "Metadata for the OASIS Security Assertion Markup Language (SAML) V2.0", section 2.3.2.2.
*/
*/
public
static
$VALID_CONTACT_OPTIONS
=
array
(
public
static
$VALID_CONTACT_OPTIONS
=
array
(
'contactType'
,
'emailAddress'
,
'givenName'
,
'surName'
,
'telephoneNumber'
,
'company'
,
'contactType'
,
'emailAddress'
,
'givenName'
,
'surName'
,
'telephoneNumber'
,
'company'
,
);
);
...
@@ -22,7 +29,11 @@ class SimpleSAML_Utils_Config_Metadata
...
@@ -22,7 +29,11 @@ class SimpleSAML_Utils_Config_Metadata
* @see "Metadata for the OASIS Security Assertion Markup Language (SAML) V2.0", section 2.3.2.2.
* @see "Metadata for the OASIS Security Assertion Markup Language (SAML) V2.0", section 2.3.2.2.
*/
*/
public
static
$VALID_CONTACT_TYPES
=
array
(
public
static
$VALID_CONTACT_TYPES
=
array
(
'technical'
,
'support'
,
'administrative'
,
'billing'
,
'other'
,
'technical'
,
'support'
,
'administrative'
,
'billing'
,
'other'
,
);
);
...
@@ -57,6 +68,7 @@ class SimpleSAML_Utils_Config_Metadata
...
@@ -57,6 +68,7 @@ class SimpleSAML_Utils_Config_Metadata
* otherwise it will just return the name as "givenName" in the resulting array.
* otherwise it will just return the name as "givenName" in the resulting array.
*
*
* @param array $contact The contact to parse and sanitize.
* @param array $contact The contact to parse and sanitize.
*
* @return array An array holding valid contact configuration options. If a key 'name' was part of the input array,
* @return array An array holding valid contact configuration options. If a key 'name' was part of the input array,
* it will try to decompose the name into its parts, and place the parts into givenName and surName, if those are
* it will try to decompose the name into its parts, and place the parts into givenName and surName, if those are
* missing.
* missing.
...
@@ -69,12 +81,12 @@ class SimpleSAML_Utils_Config_Metadata
...
@@ -69,12 +81,12 @@ class SimpleSAML_Utils_Config_Metadata
// check the type
// check the type
if
(
!
isset
(
$contact
[
'contactType'
])
||
!
in_array
(
$contact
[
'contactType'
],
self
::
$VALID_CONTACT_TYPES
,
true
))
{
if
(
!
isset
(
$contact
[
'contactType'
])
||
!
in_array
(
$contact
[
'contactType'
],
self
::
$VALID_CONTACT_TYPES
,
true
))
{
$types
=
join
(
', '
,
array_map
(
$types
=
join
(
', '
,
array_map
(
function
(
$t
)
{
function
(
$t
)
{
return
'"'
.
$t
.
'"'
;
return
'"'
.
$t
.
'"'
;
},
},
self
::
$VALID_CONTACT_TYPES
self
::
$VALID_CONTACT_TYPES
));
));
throw
new
InvalidArgumentException
(
'"contactType" is mandatory and must be one of '
.
$types
.
"."
);
throw
new
InvalidArgumentException
(
'"contactType" is mandatory and must be one of '
.
$types
.
"."
);
}
}
// try to fill in givenName and surName from name
// try to fill in givenName and surName from name
...
@@ -100,28 +112,32 @@ class SimpleSAML_Utils_Config_Metadata
...
@@ -100,28 +112,32 @@ class SimpleSAML_Utils_Config_Metadata
// check givenName
// check givenName
if
(
isset
(
$contact
[
'givenName'
])
&&
(
if
(
isset
(
$contact
[
'givenName'
])
&&
(
empty
(
$contact
[
'givenName'
])
||
!
is_string
(
$contact
[
'givenName'
])
empty
(
$contact
[
'givenName'
])
||
!
is_string
(
$contact
[
'givenName'
])
))
{
)
)
{
throw
new
InvalidArgumentException
(
'"givenName" must be a string and cannot be empty.'
);
throw
new
InvalidArgumentException
(
'"givenName" must be a string and cannot be empty.'
);
}
}
// check surName
// check surName
if
(
isset
(
$contact
[
'surName'
])
&&
(
if
(
isset
(
$contact
[
'surName'
])
&&
(
empty
(
$contact
[
'surName'
])
||
!
is_string
(
$contact
[
'surName'
])
empty
(
$contact
[
'surName'
])
||
!
is_string
(
$contact
[
'surName'
])
))
{
)
)
{
throw
new
InvalidArgumentException
(
'"surName" must be a string and cannot be empty.'
);
throw
new
InvalidArgumentException
(
'"surName" must be a string and cannot be empty.'
);
}
}
// check company
// check company
if
(
isset
(
$contact
[
'company'
])
&&
(
if
(
isset
(
$contact
[
'company'
])
&&
(
empty
(
$contact
[
'company'
])
||
!
is_string
(
$contact
[
'company'
])
empty
(
$contact
[
'company'
])
||
!
is_string
(
$contact
[
'company'
])
))
{
)
)
{
throw
new
InvalidArgumentException
(
'"company" must be a string and cannot be empty.'
);
throw
new
InvalidArgumentException
(
'"company" must be a string and cannot be empty.'
);
}
}
// check emailAddress
// check emailAddress
if
(
isset
(
$contact
[
'emailAddress'
]))
{
if
(
isset
(
$contact
[
'emailAddress'
]))
{
if
(
empty
(
$contact
[
'emailAddress'
])
||
if
(
empty
(
$contact
[
'emailAddress'
])
||
!
(
is_string
(
$contact
[
'emailAddress'
])
||
is_array
(
$contact
[
'emailAddress'
])))
{
!
(
is_string
(
$contact
[
'emailAddress'
])
||
is_array
(
$contact
[
'emailAddress'
]))
)
{
throw
new
InvalidArgumentException
(
'"emailAddress" must be a string or an array and cannot be empty.'
);
throw
new
InvalidArgumentException
(
'"emailAddress" must be a string or an array and cannot be empty.'
);
}
}
if
(
is_array
(
$contact
[
'emailAddress'
]))
{
if
(
is_array
(
$contact
[
'emailAddress'
]))
{
...
@@ -136,7 +152,8 @@ class SimpleSAML_Utils_Config_Metadata
...
@@ -136,7 +152,8 @@ class SimpleSAML_Utils_Config_Metadata
// check telephoneNumber
// check telephoneNumber
if
(
isset
(
$contact
[
'telephoneNumber'
]))
{
if
(
isset
(
$contact
[
'telephoneNumber'
]))
{
if
(
empty
(
$contact
[
'telephoneNumber'
])
||
if
(
empty
(
$contact
[
'telephoneNumber'
])
||
!
(
is_string
(
$contact
[
'telephoneNumber'
])
||
is_array
(
$contact
[
'telephoneNumber'
])))
{
!
(
is_string
(
$contact
[
'telephoneNumber'
])
||
is_array
(
$contact
[
'telephoneNumber'
]))
)
{
throw
new
InvalidArgumentException
(
'"telephoneNumber" must be a string or an array and cannot be empty.'
);
throw
new
InvalidArgumentException
(
'"telephoneNumber" must be a string or an array and cannot be empty.'
);
}
}
if
(
is_array
(
$contact
[
'telephoneNumber'
]))
{
if
(
is_array
(
$contact
[
'telephoneNumber'
]))
{
...
@@ -152,4 +169,55 @@ class SimpleSAML_Utils_Config_Metadata
...
@@ -152,4 +169,55 @@ class SimpleSAML_Utils_Config_Metadata
return
array_intersect_key
(
$contact
,
array_flip
(
self
::
$VALID_CONTACT_OPTIONS
));
return
array_intersect_key
(
$contact
,
array_flip
(
self
::
$VALID_CONTACT_OPTIONS
));
}
}
/**
* Find the default endpoint in an endpoint array.
*
* @param array $endpoints An array with endpoints.
* @param array $bindings An array with acceptable bindings. Can be null if any binding is allowed.
*
* @return array|NULL The default endpoint, or null if no acceptable endpoints are used.
*
* @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
*/
public
static
function
getDefaultEndpoint
(
array
$endpoints
,
array
$bindings
=
null
)
{
$firstNotFalse
=
null
;
$firstAllowed
=
null
;
// look through the endpoint list for acceptable endpoints
foreach
(
$endpoints
as
$i
=>
$ep
)
{
if
(
$bindings
!==
null
&&
!
in_array
(
$ep
[
'Binding'
],
$bindings
,
true
))
{
// unsupported binding, skip it
continue
;
}
if
(
array_key_exists
(
'isDefault'
,
$ep
))
{
if
(
$ep
[
'isDefault'
]
===
true
)
{
// this is the first endpoint with isDefault set to true
return
$ep
;
}
// isDefault is set to false, but the endpoint is still usable as a last resort
if
(
$firstAllowed
===
null
)
{
// this is the first endpoint that we can use
$firstAllowed
=
$ep
;
}
}
else
{
if
(
$firstNotFalse
===
null
)
{
// this is the first endpoint without isDefault set
$firstNotFalse
=
$ep
;
}
}
}
if
(
$firstNotFalse
!==
null
)
{
// we have an endpoint without isDefault set to false
return
$firstNotFalse
;
}
/* $firstAllowed either contains the first endpoint we can use, or it contains null if we cannot use any of the
* endpoints. Either way we return its value.
*/
return
$firstAllowed
;
}
}
}
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