3 final class PhabricatorAuthSession
extends PhabricatorAuthDAO
4 implements PhabricatorPolicyInterface
{
6 const TYPE_WEB
= 'web';
7 const TYPE_CONDUIT
= 'conduit';
9 const SESSION_DIGEST_KEY
= 'session.digest';
13 protected $sessionKey;
14 protected $sessionStart;
15 protected $sessionExpires;
16 protected $highSecurityUntil;
18 protected $signedLegalpadDocuments;
20 private $identityObject = self
::ATTACHABLE
;
22 public static function newSessionDigest(PhutilOpaqueEnvelope
$session_token) {
23 return PhabricatorHash
::digestWithNamedKey(
24 $session_token->openEnvelope(),
25 self
::SESSION_DIGEST_KEY
);
28 protected function getConfiguration() {
30 self
::CONFIG_TIMESTAMPS
=> false,
31 self
::CONFIG_AUX_PHID
=> true,
32 self
::CONFIG_COLUMN_SCHEMA
=> array(
34 'sessionKey' => 'text64',
35 'sessionStart' => 'epoch',
36 'sessionExpires' => 'epoch',
37 'highSecurityUntil' => 'epoch?',
38 'isPartial' => 'bool',
39 'signedLegalpadDocuments' => 'bool',
41 self
::CONFIG_KEY_SCHEMA
=> array(
42 'sessionKey' => array(
43 'columns' => array('sessionKey'),
46 'key_identity' => array(
47 'columns' => array('userPHID', 'type'),
49 'key_expires' => array(
50 'columns' => array('sessionExpires'),
53 ) + parent
::getConfiguration();
56 public function getApplicationName() {
57 // This table predates the "Auth" application, and really all applications.
61 public function getTableName() {
62 // This is a very old table with a nonstandard name.
63 return PhabricatorUser
::SESSION_TABLE
;
66 public function attachIdentityObject($identity_object) {
67 $this->identityObject
= $identity_object;
71 public function getIdentityObject() {
72 return $this->assertAttached($this->identityObject
);
75 public static function getSessionTypeTTL($session_type, $is_partial) {
76 switch ($session_type) {
79 return phutil_units('30 minutes in seconds');
81 return phutil_units('30 days in seconds');
83 case self
::TYPE_CONDUIT
:
84 return phutil_units('24 hours in seconds');
86 throw new Exception(pht('Unknown session type "%s".', $session_type));
90 public function getPHIDType() {
91 return PhabricatorAuthSessionPHIDType
::TYPECONST
;
94 public function isHighSecuritySession() {
95 $until = $this->getHighSecurityUntil();
101 $now = PhabricatorTime
::getNow();
110 /* -( PhabricatorPolicyInterface )----------------------------------------- */
113 public function getCapabilities() {
115 PhabricatorPolicyCapability
::CAN_VIEW
,
119 public function getPolicy($capability) {
120 return PhabricatorPolicies
::POLICY_NOONE
;
123 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
124 if (!$viewer->getPHID()) {
128 $object = $this->getIdentityObject();
129 if ($object instanceof PhabricatorUser
) {
130 return ($object->getPHID() == $viewer->getPHID());
131 } else if ($object instanceof PhabricatorExternalAccount
) {
132 return ($object->getUserPHID() == $viewer->getPHID());
138 public function describeAutomaticCapability($capability) {
139 return pht('A session is visible only to its owner.');