Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/storage/PhabricatorAuthFactorProvider.php
12256 views
1
<?php
2
3
final class PhabricatorAuthFactorProvider
4
extends PhabricatorAuthDAO
5
implements
6
PhabricatorApplicationTransactionInterface,
7
PhabricatorPolicyInterface,
8
PhabricatorExtendedPolicyInterface,
9
PhabricatorEditEngineMFAInterface {
10
11
protected $providerFactorKey;
12
protected $name;
13
protected $status;
14
protected $properties = array();
15
16
private $factor = self::ATTACHABLE;
17
18
public static function initializeNewProvider(PhabricatorAuthFactor $factor) {
19
return id(new self())
20
->setProviderFactorKey($factor->getFactorKey())
21
->attachFactor($factor)
22
->setStatus(PhabricatorAuthFactorProviderStatus::STATUS_ACTIVE);
23
}
24
25
protected function getConfiguration() {
26
return array(
27
self::CONFIG_SERIALIZATION => array(
28
'properties' => self::SERIALIZATION_JSON,
29
),
30
self::CONFIG_AUX_PHID => true,
31
self::CONFIG_COLUMN_SCHEMA => array(
32
'providerFactorKey' => 'text64',
33
'name' => 'text255',
34
'status' => 'text32',
35
),
36
) + parent::getConfiguration();
37
}
38
39
public function getPHIDType() {
40
return PhabricatorAuthAuthFactorProviderPHIDType::TYPECONST;
41
}
42
43
public function getURI() {
44
return '/auth/mfa/'.$this->getID().'/';
45
}
46
47
public function getObjectName() {
48
return pht('MFA Provider %d', $this->getID());
49
}
50
51
public function getAuthFactorProviderProperty($key, $default = null) {
52
return idx($this->properties, $key, $default);
53
}
54
55
public function setAuthFactorProviderProperty($key, $value) {
56
$this->properties[$key] = $value;
57
return $this;
58
}
59
60
public function getEnrollMessage() {
61
return $this->getAuthFactorProviderProperty('enroll-message');
62
}
63
64
public function setEnrollMessage($message) {
65
return $this->setAuthFactorProviderProperty('enroll-message', $message);
66
}
67
68
public function attachFactor(PhabricatorAuthFactor $factor) {
69
$this->factor = $factor;
70
return $this;
71
}
72
73
public function getFactor() {
74
return $this->assertAttached($this->factor);
75
}
76
77
public function getDisplayName() {
78
$name = $this->getName();
79
if (strlen($name)) {
80
return $name;
81
}
82
83
return $this->getFactor()->getFactorName();
84
}
85
86
public function newIconView() {
87
return $this->getFactor()->newIconView();
88
}
89
90
public function getDisplayDescription() {
91
return $this->getFactor()->getFactorDescription();
92
}
93
94
public function processAddFactorForm(
95
AphrontFormView $form,
96
AphrontRequest $request,
97
PhabricatorUser $user) {
98
99
$factor = $this->getFactor();
100
101
$config = $factor->processAddFactorForm($this, $form, $request, $user);
102
if ($config) {
103
$config->setFactorProviderPHID($this->getPHID());
104
}
105
106
return $config;
107
}
108
109
public function newSortVector() {
110
$factor = $this->getFactor();
111
112
return id(new PhutilSortVector())
113
->addInt($factor->getFactorOrder())
114
->addInt($this->getID());
115
}
116
117
public function getEnrollDescription(PhabricatorUser $user) {
118
return $this->getFactor()->getEnrollDescription($this, $user);
119
}
120
121
public function getEnrollButtonText(PhabricatorUser $user) {
122
return $this->getFactor()->getEnrollButtonText($this, $user);
123
}
124
125
public function newStatus() {
126
$status_key = $this->getStatus();
127
return PhabricatorAuthFactorProviderStatus::newForStatus($status_key);
128
}
129
130
public function canCreateNewConfiguration(PhabricatorUser $user) {
131
return $this->getFactor()->canCreateNewConfiguration($this, $user);
132
}
133
134
public function getConfigurationCreateDescription(PhabricatorUser $user) {
135
return $this->getFactor()->getConfigurationCreateDescription($this, $user);
136
}
137
138
public function getConfigurationListDetails(
139
PhabricatorAuthFactorConfig $config,
140
PhabricatorUser $viewer) {
141
return $this->getFactor()->getConfigurationListDetails(
142
$config,
143
$this,
144
$viewer);
145
}
146
147
148
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
149
150
151
public function getApplicationTransactionEditor() {
152
return new PhabricatorAuthFactorProviderEditor();
153
}
154
155
public function getApplicationTransactionTemplate() {
156
return new PhabricatorAuthFactorProviderTransaction();
157
}
158
159
160
/* -( PhabricatorPolicyInterface )----------------------------------------- */
161
162
163
public function getCapabilities() {
164
return array(
165
PhabricatorPolicyCapability::CAN_VIEW,
166
PhabricatorPolicyCapability::CAN_EDIT,
167
);
168
}
169
170
public function getPolicy($capability) {
171
return PhabricatorPolicies::getMostOpenPolicy();
172
}
173
174
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
175
return false;
176
}
177
178
179
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
180
181
182
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
183
$extended = array();
184
185
switch ($capability) {
186
case PhabricatorPolicyCapability::CAN_VIEW:
187
break;
188
case PhabricatorPolicyCapability::CAN_EDIT:
189
$extended[] = array(
190
new PhabricatorAuthApplication(),
191
AuthManageProvidersCapability::CAPABILITY,
192
);
193
break;
194
}
195
196
return $extended;
197
}
198
199
200
/* -( PhabricatorEditEngineMFAInterface )---------------------------------- */
201
202
203
public function newEditEngineMFAEngine() {
204
return new PhabricatorAuthFactorProviderMFAEngine();
205
}
206
207
}
208
209