1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: dsmrt |
5
|
|
|
* Date: 1/23/18 |
6
|
|
|
* Time: 9:26 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\saml\core\models; |
10
|
|
|
|
11
|
|
|
use craft\base\Model; |
12
|
|
|
use craft\config\GeneralConfig; |
13
|
|
|
use craft\helpers\UrlHelper; |
14
|
|
|
|
15
|
|
|
abstract class AbstractSettings extends Model implements SettingsInterface |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $myType; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $entityId; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* This is the endpoint used to initiate login. Set the general.php config for `loginPath` to this. |
30
|
|
|
* @see GeneralConfig::$loginPath |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
public $loginEndpoint = '/sso/login'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* This is the endpoint used to initiate login. Set the general.php config for `loginPath` to this. |
38
|
|
|
* @see GeneralConfig::$loginPath |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
public $logoutEndpoint = '/sso/logout'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* This is the endpoint used to initiate login. Set the general.php config for `loginPath` to this. |
46
|
|
|
* @see GeneralConfig::$loginPath |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
public $loginRequestEndpoint = '/sso/login/request'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* This is the endpoint used to initiate logout. In this case, `logoutPath` cannot be used. |
54
|
|
|
* Point your logout button to this endpoint. |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
public $logoutRequestEndpoint = '/sso/logout/request'; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritdoc |
62
|
|
|
*/ |
63
|
|
|
public function attributes() |
64
|
|
|
{ |
65
|
|
|
return array_merge( |
66
|
|
|
parent::attributes(), |
67
|
|
|
[ |
68
|
|
|
'entityId', |
69
|
|
|
] |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/******************************************* |
74
|
|
|
* ENTITY ID |
75
|
|
|
*******************************************/ |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param $entityId |
79
|
|
|
* @return $this |
80
|
|
|
*/ |
81
|
|
|
public function setEntityId($entityId) |
82
|
|
|
{ |
83
|
|
|
$this->entityId = $entityId; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
* @throws \craft\errors\SiteNotFoundException |
91
|
|
|
*/ |
92
|
|
|
public function getEntityId() |
93
|
|
|
{ |
94
|
|
|
if (! $this->entityId) { |
95
|
|
|
$this->entityId = UrlHelper::baseUrl(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->entityId; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param $myType |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
|
|
public function setMyType($myType) |
106
|
|
|
{ |
107
|
|
|
$this->myType = $myType; |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getMyType() |
115
|
|
|
{ |
116
|
|
|
return $this->myType; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function getRemoteType() |
123
|
|
|
{ |
124
|
|
|
return $this->getMyType() === self::IDP ? self::SP : self::IDP; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return bool |
129
|
|
|
*/ |
130
|
|
|
public function isIDP() |
131
|
|
|
{ |
132
|
|
|
return $this->getMyType() === self::IDP; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
|
|
public function isSP() |
139
|
|
|
{ |
140
|
|
|
return $this->getMyType() === self::SP; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @inheritdoc |
145
|
|
|
*/ |
146
|
|
|
public function getDefaultLoginEndpoint() |
147
|
|
|
{ |
148
|
|
|
return UrlHelper::siteUrl($this->loginEndpoint); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @inheritdoc |
153
|
|
|
*/ |
154
|
|
|
public function getDefaultLogoutEndpoint() |
155
|
|
|
{ |
156
|
|
|
return UrlHelper::siteUrl($this->logoutEndpoint); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @inheritdoc |
161
|
|
|
*/ |
162
|
|
|
public function getDefaultLogoutRequestEndpoint() |
163
|
|
|
{ |
164
|
|
|
return UrlHelper::siteUrl($this->logoutRequestEndpoint); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @inheritdoc |
169
|
|
|
*/ |
170
|
|
|
public function getDefaultLoginRequestEndpoint() |
171
|
|
|
{ |
172
|
|
|
return UrlHelper::siteUrl($this->loginRequestEndpoint); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|