Path: blob/master/src/applications/auth/storage/PhabricatorAuthFactorProvider.php
12256 views
<?php12final class PhabricatorAuthFactorProvider3extends PhabricatorAuthDAO4implements5PhabricatorApplicationTransactionInterface,6PhabricatorPolicyInterface,7PhabricatorExtendedPolicyInterface,8PhabricatorEditEngineMFAInterface {910protected $providerFactorKey;11protected $name;12protected $status;13protected $properties = array();1415private $factor = self::ATTACHABLE;1617public static function initializeNewProvider(PhabricatorAuthFactor $factor) {18return id(new self())19->setProviderFactorKey($factor->getFactorKey())20->attachFactor($factor)21->setStatus(PhabricatorAuthFactorProviderStatus::STATUS_ACTIVE);22}2324protected function getConfiguration() {25return array(26self::CONFIG_SERIALIZATION => array(27'properties' => self::SERIALIZATION_JSON,28),29self::CONFIG_AUX_PHID => true,30self::CONFIG_COLUMN_SCHEMA => array(31'providerFactorKey' => 'text64',32'name' => 'text255',33'status' => 'text32',34),35) + parent::getConfiguration();36}3738public function getPHIDType() {39return PhabricatorAuthAuthFactorProviderPHIDType::TYPECONST;40}4142public function getURI() {43return '/auth/mfa/'.$this->getID().'/';44}4546public function getObjectName() {47return pht('MFA Provider %d', $this->getID());48}4950public function getAuthFactorProviderProperty($key, $default = null) {51return idx($this->properties, $key, $default);52}5354public function setAuthFactorProviderProperty($key, $value) {55$this->properties[$key] = $value;56return $this;57}5859public function getEnrollMessage() {60return $this->getAuthFactorProviderProperty('enroll-message');61}6263public function setEnrollMessage($message) {64return $this->setAuthFactorProviderProperty('enroll-message', $message);65}6667public function attachFactor(PhabricatorAuthFactor $factor) {68$this->factor = $factor;69return $this;70}7172public function getFactor() {73return $this->assertAttached($this->factor);74}7576public function getDisplayName() {77$name = $this->getName();78if (strlen($name)) {79return $name;80}8182return $this->getFactor()->getFactorName();83}8485public function newIconView() {86return $this->getFactor()->newIconView();87}8889public function getDisplayDescription() {90return $this->getFactor()->getFactorDescription();91}9293public function processAddFactorForm(94AphrontFormView $form,95AphrontRequest $request,96PhabricatorUser $user) {9798$factor = $this->getFactor();99100$config = $factor->processAddFactorForm($this, $form, $request, $user);101if ($config) {102$config->setFactorProviderPHID($this->getPHID());103}104105return $config;106}107108public function newSortVector() {109$factor = $this->getFactor();110111return id(new PhutilSortVector())112->addInt($factor->getFactorOrder())113->addInt($this->getID());114}115116public function getEnrollDescription(PhabricatorUser $user) {117return $this->getFactor()->getEnrollDescription($this, $user);118}119120public function getEnrollButtonText(PhabricatorUser $user) {121return $this->getFactor()->getEnrollButtonText($this, $user);122}123124public function newStatus() {125$status_key = $this->getStatus();126return PhabricatorAuthFactorProviderStatus::newForStatus($status_key);127}128129public function canCreateNewConfiguration(PhabricatorUser $user) {130return $this->getFactor()->canCreateNewConfiguration($this, $user);131}132133public function getConfigurationCreateDescription(PhabricatorUser $user) {134return $this->getFactor()->getConfigurationCreateDescription($this, $user);135}136137public function getConfigurationListDetails(138PhabricatorAuthFactorConfig $config,139PhabricatorUser $viewer) {140return $this->getFactor()->getConfigurationListDetails(141$config,142$this,143$viewer);144}145146147/* -( PhabricatorApplicationTransactionInterface )------------------------- */148149150public function getApplicationTransactionEditor() {151return new PhabricatorAuthFactorProviderEditor();152}153154public function getApplicationTransactionTemplate() {155return new PhabricatorAuthFactorProviderTransaction();156}157158159/* -( PhabricatorPolicyInterface )----------------------------------------- */160161162public function getCapabilities() {163return array(164PhabricatorPolicyCapability::CAN_VIEW,165PhabricatorPolicyCapability::CAN_EDIT,166);167}168169public function getPolicy($capability) {170return PhabricatorPolicies::getMostOpenPolicy();171}172173public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {174return false;175}176177178/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */179180181public function getExtendedPolicy($capability, PhabricatorUser $viewer) {182$extended = array();183184switch ($capability) {185case PhabricatorPolicyCapability::CAN_VIEW:186break;187case PhabricatorPolicyCapability::CAN_EDIT:188$extended[] = array(189new PhabricatorAuthApplication(),190AuthManageProvidersCapability::CAPABILITY,191);192break;193}194195return $extended;196}197198199/* -( PhabricatorEditEngineMFAInterface )---------------------------------- */200201202public function newEditEngineMFAEngine() {203return new PhabricatorAuthFactorProviderMFAEngine();204}205206}207208209