Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / auth / storage / PhabricatorAuthFactorProvider.php
blob2213535dff6b40d5f70d2d00511254d7beb43b23
1 <?php
3 final class PhabricatorAuthFactorProvider
4 extends PhabricatorAuthDAO
5 implements
6 PhabricatorApplicationTransactionInterface,
7 PhabricatorPolicyInterface,
8 PhabricatorExtendedPolicyInterface,
9 PhabricatorEditEngineMFAInterface {
11 protected $providerFactorKey;
12 protected $name;
13 protected $status;
14 protected $properties = array();
16 private $factor = self::ATTACHABLE;
18 public static function initializeNewProvider(PhabricatorAuthFactor $factor) {
19 return id(new self())
20 ->setProviderFactorKey($factor->getFactorKey())
21 ->attachFactor($factor)
22 ->setStatus(PhabricatorAuthFactorProviderStatus::STATUS_ACTIVE);
25 protected function getConfiguration() {
26 return array(
27 self::CONFIG_SERIALIZATION => array(
28 'properties' => self::SERIALIZATION_JSON,
30 self::CONFIG_AUX_PHID => true,
31 self::CONFIG_COLUMN_SCHEMA => array(
32 'providerFactorKey' => 'text64',
33 'name' => 'text255',
34 'status' => 'text32',
36 ) + parent::getConfiguration();
39 public function getPHIDType() {
40 return PhabricatorAuthAuthFactorProviderPHIDType::TYPECONST;
43 public function getURI() {
44 return '/auth/mfa/'.$this->getID().'/';
47 public function getObjectName() {
48 return pht('MFA Provider %d', $this->getID());
51 public function getAuthFactorProviderProperty($key, $default = null) {
52 return idx($this->properties, $key, $default);
55 public function setAuthFactorProviderProperty($key, $value) {
56 $this->properties[$key] = $value;
57 return $this;
60 public function getEnrollMessage() {
61 return $this->getAuthFactorProviderProperty('enroll-message');
64 public function setEnrollMessage($message) {
65 return $this->setAuthFactorProviderProperty('enroll-message', $message);
68 public function attachFactor(PhabricatorAuthFactor $factor) {
69 $this->factor = $factor;
70 return $this;
73 public function getFactor() {
74 return $this->assertAttached($this->factor);
77 public function getDisplayName() {
78 $name = $this->getName();
79 if (strlen($name)) {
80 return $name;
83 return $this->getFactor()->getFactorName();
86 public function newIconView() {
87 return $this->getFactor()->newIconView();
90 public function getDisplayDescription() {
91 return $this->getFactor()->getFactorDescription();
94 public function processAddFactorForm(
95 AphrontFormView $form,
96 AphrontRequest $request,
97 PhabricatorUser $user) {
99 $factor = $this->getFactor();
101 $config = $factor->processAddFactorForm($this, $form, $request, $user);
102 if ($config) {
103 $config->setFactorProviderPHID($this->getPHID());
106 return $config;
109 public function newSortVector() {
110 $factor = $this->getFactor();
112 return id(new PhutilSortVector())
113 ->addInt($factor->getFactorOrder())
114 ->addInt($this->getID());
117 public function getEnrollDescription(PhabricatorUser $user) {
118 return $this->getFactor()->getEnrollDescription($this, $user);
121 public function getEnrollButtonText(PhabricatorUser $user) {
122 return $this->getFactor()->getEnrollButtonText($this, $user);
125 public function newStatus() {
126 $status_key = $this->getStatus();
127 return PhabricatorAuthFactorProviderStatus::newForStatus($status_key);
130 public function canCreateNewConfiguration(PhabricatorUser $user) {
131 return $this->getFactor()->canCreateNewConfiguration($this, $user);
134 public function getConfigurationCreateDescription(PhabricatorUser $user) {
135 return $this->getFactor()->getConfigurationCreateDescription($this, $user);
138 public function getConfigurationListDetails(
139 PhabricatorAuthFactorConfig $config,
140 PhabricatorUser $viewer) {
141 return $this->getFactor()->getConfigurationListDetails(
142 $config,
143 $this,
144 $viewer);
148 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
151 public function getApplicationTransactionEditor() {
152 return new PhabricatorAuthFactorProviderEditor();
155 public function getApplicationTransactionTemplate() {
156 return new PhabricatorAuthFactorProviderTransaction();
160 /* -( PhabricatorPolicyInterface )----------------------------------------- */
163 public function getCapabilities() {
164 return array(
165 PhabricatorPolicyCapability::CAN_VIEW,
166 PhabricatorPolicyCapability::CAN_EDIT,
170 public function getPolicy($capability) {
171 return PhabricatorPolicies::getMostOpenPolicy();
174 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
175 return false;
179 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
182 public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
183 $extended = array();
185 switch ($capability) {
186 case PhabricatorPolicyCapability::CAN_VIEW:
187 break;
188 case PhabricatorPolicyCapability::CAN_EDIT:
189 $extended[] = array(
190 new PhabricatorAuthApplication(),
191 AuthManageProvidersCapability::CAPABILITY,
193 break;
196 return $extended;
200 /* -( PhabricatorEditEngineMFAInterface )---------------------------------- */
203 public function newEditEngineMFAEngine() {
204 return new PhabricatorAuthFactorProviderMFAEngine();