Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/revoker/PhabricatorAuthPasswordRevoker.php
- This file was copied from src/applications/auth/revoker/PhabricatorAuthSSHRevoker.php.
<?php | <?php | ||||
final class PhabricatorAuthSSHRevoker | final class PhabricatorAuthPasswordRevoker | ||||
extends PhabricatorAuthRevoker { | extends PhabricatorAuthRevoker { | ||||
const REVOKERKEY = 'ssh'; | const REVOKERKEY = 'password'; | ||||
public function revokeAllCredentials() { | public function revokeAllCredentials() { | ||||
$query = new PhabricatorAuthSSHKeyQuery(); | $query = new PhabricatorAuthPasswordQuery(); | ||||
return $this->revokeWithQuery($query); | return $this->revokeWithQuery($query); | ||||
} | } | ||||
public function revokeCredentialsFrom($object) { | public function revokeCredentialsFrom($object) { | ||||
$query = id(new PhabricatorAuthSSHKeyQuery()) | $query = id(new PhabricatorAuthPasswordQuery()) | ||||
->withObjectPHIDs(array($object->getPHID())); | ->withObjectPHIDs(array($object->getPHID())); | ||||
return $this->revokeWithQuery($query); | return $this->revokeWithQuery($query); | ||||
} | } | ||||
private function revokeWithQuery(PhabricatorAuthSSHKeyQuery $query) { | private function revokeWithQuery(PhabricatorAuthSSHKeyQuery $query) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
// We're only going to revoke keys which have not already been revoked. | $passwords = $query | ||||
$ssh_keys = $query | |||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIsActive(true) | ->withIsRevoked(false) | ||||
->execute(); | ->execute(); | ||||
$content_source = PhabricatorContentSource::newForSource( | $content_source = PhabricatorContentSource::newForSource( | ||||
PhabricatorDaemonContentSource::SOURCECONST); | PhabricatorDaemonContentSource::SOURCECONST); | ||||
$revoke_type = PhabricatorAuthPasswordRevokeTransaction::TRANSACTIONTYPE; | |||||
$auth_phid = id(new PhabricatorAuthApplication())->getPHID(); | $auth_phid = id(new PhabricatorAuthApplication())->getPHID(); | ||||
foreach ($ssh_keys as $ssh_key) { | foreach ($passwords as $password) { | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = $ssh_key->getApplicationTransactionTemplate() | |||||
->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_DEACTIVATE) | |||||
->setNewValue(1); | |||||
$editor = id(new PhabricatorAuthSSHKeyEditor()) | $xactions[] = $password->getApplicationTransactionTemplate() | ||||
->setTransactionType($revoke_type) | |||||
->setNewValue(true); | |||||
$editor = $password->getApplicationTransactionEditor() | |||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setActingAsPHID($auth_phid) | ->setActingAsPHID($auth_phid) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
->setContentSource($content_source) | ->setContentSource($content_source) | ||||
->applyTransactions($ssh_key, $xactions); | ->applyTransactions($password, $xactions); | ||||
} | } | ||||
return count($ssh_keys); | return count($passwords); | ||||
} | } | ||||
} | } |