1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AerialShip\SamlSPBundle\Tests\Bridge; |
4
|
|
|
|
5
|
|
|
use AerialShip\LightSaml\Model\Assertion\Attribute; |
6
|
|
|
use AerialShip\LightSaml\Model\Assertion\AuthnStatement; |
7
|
|
|
use AerialShip\LightSaml\Model\Assertion\NameID; |
8
|
|
|
use AerialShip\SamlSPBundle\Bridge\SamlSpInfo; |
9
|
|
|
|
10
|
|
|
class SamlSpInfoHelper |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @param string $nameIDValue |
15
|
|
|
* @param string $nameIDFormat |
16
|
|
|
* @return NameID |
17
|
|
|
*/ |
18
|
20 |
|
public function getNameID( |
19
|
|
|
$nameIDValue = 'nameID', |
20
|
|
|
$nameIDFormat = 'nameIDFormat' |
21
|
|
|
) { |
22
|
20 |
|
$nameID = new NameID(); |
23
|
20 |
|
$nameID->setValue($nameIDValue); |
24
|
20 |
|
$nameID->setFormat($nameIDFormat); |
25
|
|
|
|
26
|
20 |
|
return $nameID; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Attribute[] $attributes |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
19 |
|
public function getAttributes(array $attributes = array('a'=>1, 'b'=>array(2,3))) |
35
|
|
|
{ |
36
|
19 |
|
$arrAttributes = array(); |
37
|
19 |
|
foreach ($attributes as $name => $value) { |
38
|
19 |
|
$a = new Attribute(); |
39
|
19 |
|
$a->setName($name); |
40
|
19 |
|
if (!is_array($value)) { |
41
|
19 |
|
$value = array($value); |
42
|
19 |
|
} |
43
|
19 |
|
$a->setValues($value); |
44
|
19 |
|
$arrAttributes[] = $a; |
45
|
19 |
|
} |
46
|
|
|
|
47
|
19 |
|
return $arrAttributes; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $sessionIndex |
53
|
|
|
* @return AuthnStatement |
54
|
|
|
*/ |
55
|
18 |
|
public function getAuthnStatement($sessionIndex = 'session_index') |
56
|
|
|
{ |
57
|
18 |
|
$authnStatement = new AuthnStatement(); |
58
|
18 |
|
$authnStatement->setSessionIndex($sessionIndex); |
59
|
|
|
|
60
|
18 |
|
return $authnStatement; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $nameIDValue |
66
|
|
|
* @param string $nameIDFormat |
67
|
|
|
* @param array $attributes |
68
|
|
|
* @param string $sessionIndex |
69
|
|
|
* @return SamlSpInfo |
70
|
|
|
*/ |
71
|
16 |
|
public function getSamlSpInfo( |
72
|
|
|
$nameIDValue = 'nameID', |
73
|
|
|
$nameIDFormat = 'nameIDFormat', |
74
|
|
|
array $attributes = array('a'=>1, 'b'=>array(2,3)), |
75
|
|
|
$sessionIndex = 'session_index' |
76
|
|
|
) { |
77
|
16 |
|
$nameID = $this->getNameID($nameIDValue, $nameIDFormat); |
78
|
|
|
|
79
|
16 |
|
$arrAttributes = $this->getAttributes($attributes); |
80
|
|
|
|
81
|
16 |
|
$authnStatement = $this->getAuthnStatement($sessionIndex); |
82
|
|
|
|
83
|
16 |
|
$result = new SamlSpInfo('authServiceID', $nameID, $arrAttributes, $authnStatement); |
84
|
16 |
|
return $result; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|