3 final class PhabricatorAuthFactorProvider
4 extends PhabricatorAuthDAO
6 PhabricatorApplicationTransactionInterface
,
7 PhabricatorPolicyInterface
,
8 PhabricatorExtendedPolicyInterface
,
9 PhabricatorEditEngineMFAInterface
{
11 protected $providerFactorKey;
14 protected $properties = array();
16 private $factor = self
::ATTACHABLE
;
18 public static function initializeNewProvider(PhabricatorAuthFactor
$factor) {
20 ->setProviderFactorKey($factor->getFactorKey())
21 ->attachFactor($factor)
22 ->setStatus(PhabricatorAuthFactorProviderStatus
::STATUS_ACTIVE
);
25 protected function getConfiguration() {
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',
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;
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;
73 public function getFactor() {
74 return $this->assertAttached($this->factor
);
77 public function getDisplayName() {
78 $name = $this->getName();
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);
103 $config->setFactorProviderPHID($this->getPHID());
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(
148 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
151 public function getApplicationTransactionEditor() {
152 return new PhabricatorAuthFactorProviderEditor();
155 public function getApplicationTransactionTemplate() {
156 return new PhabricatorAuthFactorProviderTransaction();
160 /* -( PhabricatorPolicyInterface )----------------------------------------- */
163 public function getCapabilities() {
165 PhabricatorPolicyCapability
::CAN_VIEW
,
166 PhabricatorPolicyCapability
::CAN_EDIT
,
170 public function getPolicy($capability) {
171 return PhabricatorPolicies
::getMostOpenPolicy();
174 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
179 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
182 public function getExtendedPolicy($capability, PhabricatorUser
$viewer) {
185 switch ($capability) {
186 case PhabricatorPolicyCapability
::CAN_VIEW
:
188 case PhabricatorPolicyCapability
::CAN_EDIT
:
190 new PhabricatorAuthApplication(),
191 AuthManageProvidersCapability
::CAPABILITY
,
200 /* -( PhabricatorEditEngineMFAInterface )---------------------------------- */
203 public function newEditEngineMFAEngine() {
204 return new PhabricatorAuthFactorProviderMFAEngine();