|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: leo108 |
|
5
|
|
|
* Date: 2016/10/23 |
|
6
|
|
|
* Time: 16:01 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Leo108\CAS\Responses; |
|
10
|
|
|
|
|
11
|
|
|
use Leo108\CAS\Contracts\Responses\AuthenticationSuccessResponse; |
|
12
|
|
|
use SimpleXMLElement; |
|
13
|
|
|
|
|
14
|
|
|
class XmlAuthenticationSuccessResponse extends BaseXmlResponse implements AuthenticationSuccessResponse |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* XmlAuthenticationSuccessResponse constructor. |
|
18
|
|
|
*/ |
|
19
|
4 |
|
public function __construct() |
|
20
|
|
|
{ |
|
21
|
4 |
|
parent::__construct(); |
|
22
|
4 |
|
$this->node->addChild('cas:authenticationSuccess'); |
|
23
|
4 |
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
public function setUser($user) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$authNode = $this->getAuthNode(); |
|
28
|
1 |
|
$this->removeByXPath($authNode, 'cas:user'); |
|
29
|
1 |
|
$authNode->addChild('cas:user', $user); |
|
30
|
|
|
|
|
31
|
1 |
|
return $this; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
public function setProxies($proxies) |
|
35
|
|
|
{ |
|
36
|
1 |
|
$authNode = $this->getAuthNode(); |
|
37
|
1 |
|
$this->removeByXPath($authNode, 'cas:proxies'); |
|
38
|
1 |
|
$proxiesNode = $authNode->addChild('cas:proxies'); |
|
39
|
1 |
|
foreach ($proxies as $proxy) { |
|
40
|
1 |
|
$proxiesNode->addChild('cas:proxy', $proxy); |
|
41
|
1 |
|
} |
|
42
|
|
|
|
|
43
|
1 |
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
public function setAttributes($attributes) |
|
47
|
|
|
{ |
|
48
|
1 |
|
$authNode = $this->getAuthNode(); |
|
49
|
1 |
|
$this->removeByXPath($authNode, 'cas:attributes'); |
|
50
|
1 |
|
$attributesNode = $authNode->addChild('cas:attributes'); |
|
51
|
1 |
|
foreach ($attributes as $key => $value) { |
|
52
|
1 |
|
$str = $this->stringify($value); |
|
53
|
1 |
|
if (is_string($str)) { |
|
54
|
1 |
|
$attributesNode->addChild('cas:'.$key, $str); |
|
55
|
1 |
|
} |
|
56
|
1 |
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
public function setProxyGrantingTicket($ticket) |
|
62
|
|
|
{ |
|
63
|
1 |
|
$authNode = $this->getAuthNode(); |
|
64
|
1 |
|
$this->removeByXPath($authNode, 'cas:proxyGrantingTicket'); |
|
65
|
1 |
|
$authNode->addChild('cas:proxyGrantingTicket', $ticket); |
|
66
|
|
|
|
|
67
|
1 |
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return SimpleXMLElement |
|
72
|
|
|
*/ |
|
73
|
4 |
|
protected function getAuthNode() |
|
74
|
|
|
{ |
|
75
|
4 |
|
$authNodes = $this->node->xpath('cas:authenticationSuccess'); |
|
76
|
4 |
|
if (count($authNodes) < 1) { |
|
77
|
|
|
return $this->node->addChild('cas:authenticationSuccess'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
4 |
|
return $authNodes[0]; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|