@@ -30,42 +30,42 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | interface ICredentialsManager { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Store a set of credentials |
|
| 35 | - * |
|
| 36 | - * @param string $userId empty string for system-wide credentials |
|
| 37 | - * @param string $identifier |
|
| 38 | - * @param mixed $credentials |
|
| 39 | - * @since 8.2.0 |
|
| 40 | - */ |
|
| 41 | - public function store($userId, $identifier, $credentials); |
|
| 33 | + /** |
|
| 34 | + * Store a set of credentials |
|
| 35 | + * |
|
| 36 | + * @param string $userId empty string for system-wide credentials |
|
| 37 | + * @param string $identifier |
|
| 38 | + * @param mixed $credentials |
|
| 39 | + * @since 8.2.0 |
|
| 40 | + */ |
|
| 41 | + public function store($userId, $identifier, $credentials); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Retrieve a set of credentials |
|
| 45 | - * |
|
| 46 | - * @param string $userId empty string for system-wide credentials |
|
| 47 | - * @param string $identifier |
|
| 48 | - * @return mixed |
|
| 49 | - * @since 8.2.0 |
|
| 50 | - */ |
|
| 51 | - public function retrieve($userId, $identifier); |
|
| 43 | + /** |
|
| 44 | + * Retrieve a set of credentials |
|
| 45 | + * |
|
| 46 | + * @param string $userId empty string for system-wide credentials |
|
| 47 | + * @param string $identifier |
|
| 48 | + * @return mixed |
|
| 49 | + * @since 8.2.0 |
|
| 50 | + */ |
|
| 51 | + public function retrieve($userId, $identifier); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Delete a set of credentials |
|
| 55 | - * |
|
| 56 | - * @param string $userId empty string for system-wide credentials |
|
| 57 | - * @param string $identifier |
|
| 58 | - * @return int rows removed |
|
| 59 | - * @since 8.2.0 |
|
| 60 | - */ |
|
| 61 | - public function delete($userId, $identifier); |
|
| 53 | + /** |
|
| 54 | + * Delete a set of credentials |
|
| 55 | + * |
|
| 56 | + * @param string $userId empty string for system-wide credentials |
|
| 57 | + * @param string $identifier |
|
| 58 | + * @return int rows removed |
|
| 59 | + * @since 8.2.0 |
|
| 60 | + */ |
|
| 61 | + public function delete($userId, $identifier); |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Erase all credentials stored for a user |
|
| 65 | - * |
|
| 66 | - * @param string $userId |
|
| 67 | - * @return int rows removed |
|
| 68 | - * @since 8.2.0 |
|
| 69 | - */ |
|
| 70 | - public function erase($userId); |
|
| 63 | + /** |
|
| 64 | + * Erase all credentials stored for a user |
|
| 65 | + * |
|
| 66 | + * @param string $userId |
|
| 67 | + * @return int rows removed |
|
| 68 | + * @since 8.2.0 |
|
| 69 | + */ |
|
| 70 | + public function erase($userId); |
|
| 71 | 71 | } |
@@ -33,92 +33,92 @@ |
||
| 33 | 33 | * @package OC\Security |
| 34 | 34 | */ |
| 35 | 35 | class CredentialsManager implements ICredentialsManager { |
| 36 | - public const DB_TABLE = 'credentials'; |
|
| 36 | + public const DB_TABLE = 'credentials'; |
|
| 37 | 37 | |
| 38 | - /** @var ICrypto */ |
|
| 39 | - protected $crypto; |
|
| 38 | + /** @var ICrypto */ |
|
| 39 | + protected $crypto; |
|
| 40 | 40 | |
| 41 | - /** @var IDBConnection */ |
|
| 42 | - protected $dbConnection; |
|
| 41 | + /** @var IDBConnection */ |
|
| 42 | + protected $dbConnection; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param ICrypto $crypto |
|
| 46 | - * @param IDBConnection $dbConnection |
|
| 47 | - */ |
|
| 48 | - public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
| 49 | - $this->crypto = $crypto; |
|
| 50 | - $this->dbConnection = $dbConnection; |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * @param ICrypto $crypto |
|
| 46 | + * @param IDBConnection $dbConnection |
|
| 47 | + */ |
|
| 48 | + public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
| 49 | + $this->crypto = $crypto; |
|
| 50 | + $this->dbConnection = $dbConnection; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Store a set of credentials |
|
| 55 | - * |
|
| 56 | - * @param string $userId empty string for system-wide credentials |
|
| 57 | - * @param string $identifier |
|
| 58 | - * @param mixed $credentials |
|
| 59 | - */ |
|
| 60 | - public function store($userId, $identifier, $credentials) { |
|
| 61 | - $value = $this->crypto->encrypt(json_encode($credentials)); |
|
| 53 | + /** |
|
| 54 | + * Store a set of credentials |
|
| 55 | + * |
|
| 56 | + * @param string $userId empty string for system-wide credentials |
|
| 57 | + * @param string $identifier |
|
| 58 | + * @param mixed $credentials |
|
| 59 | + */ |
|
| 60 | + public function store($userId, $identifier, $credentials) { |
|
| 61 | + $value = $this->crypto->encrypt(json_encode($credentials)); |
|
| 62 | 62 | |
| 63 | - $this->dbConnection->setValues(self::DB_TABLE, [ |
|
| 64 | - 'user' => (string)$userId, |
|
| 65 | - 'identifier' => $identifier, |
|
| 66 | - ], [ |
|
| 67 | - 'credentials' => $value, |
|
| 68 | - ]); |
|
| 69 | - } |
|
| 63 | + $this->dbConnection->setValues(self::DB_TABLE, [ |
|
| 64 | + 'user' => (string)$userId, |
|
| 65 | + 'identifier' => $identifier, |
|
| 66 | + ], [ |
|
| 67 | + 'credentials' => $value, |
|
| 68 | + ]); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Retrieve a set of credentials |
|
| 73 | - * |
|
| 74 | - * @param string $userId empty string for system-wide credentials |
|
| 75 | - * @param string $identifier |
|
| 76 | - * @return mixed |
|
| 77 | - */ |
|
| 78 | - public function retrieve($userId, $identifier) { |
|
| 79 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 80 | - $qb->select('credentials') |
|
| 81 | - ->from(self::DB_TABLE) |
|
| 82 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId))) |
|
| 83 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
| 84 | - ; |
|
| 85 | - $result = $qb->execute()->fetch(); |
|
| 71 | + /** |
|
| 72 | + * Retrieve a set of credentials |
|
| 73 | + * |
|
| 74 | + * @param string $userId empty string for system-wide credentials |
|
| 75 | + * @param string $identifier |
|
| 76 | + * @return mixed |
|
| 77 | + */ |
|
| 78 | + public function retrieve($userId, $identifier) { |
|
| 79 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 80 | + $qb->select('credentials') |
|
| 81 | + ->from(self::DB_TABLE) |
|
| 82 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId))) |
|
| 83 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
| 84 | + ; |
|
| 85 | + $result = $qb->execute()->fetch(); |
|
| 86 | 86 | |
| 87 | - if (!$result) { |
|
| 88 | - return null; |
|
| 89 | - } |
|
| 90 | - $value = $result['credentials']; |
|
| 87 | + if (!$result) { |
|
| 88 | + return null; |
|
| 89 | + } |
|
| 90 | + $value = $result['credentials']; |
|
| 91 | 91 | |
| 92 | - return json_decode($this->crypto->decrypt($value), true); |
|
| 93 | - } |
|
| 92 | + return json_decode($this->crypto->decrypt($value), true); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Delete a set of credentials |
|
| 97 | - * |
|
| 98 | - * @param string $userId empty string for system-wide credentials |
|
| 99 | - * @param string $identifier |
|
| 100 | - * @return int rows removed |
|
| 101 | - */ |
|
| 102 | - public function delete($userId, $identifier) { |
|
| 103 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 104 | - $qb->delete(self::DB_TABLE) |
|
| 105 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId))) |
|
| 106 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
| 107 | - ; |
|
| 108 | - return $qb->execute(); |
|
| 109 | - } |
|
| 95 | + /** |
|
| 96 | + * Delete a set of credentials |
|
| 97 | + * |
|
| 98 | + * @param string $userId empty string for system-wide credentials |
|
| 99 | + * @param string $identifier |
|
| 100 | + * @return int rows removed |
|
| 101 | + */ |
|
| 102 | + public function delete($userId, $identifier) { |
|
| 103 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 104 | + $qb->delete(self::DB_TABLE) |
|
| 105 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId))) |
|
| 106 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
| 107 | + ; |
|
| 108 | + return $qb->execute(); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Erase all credentials stored for a user |
|
| 113 | - * |
|
| 114 | - * @param string $userId |
|
| 115 | - * @return int rows removed |
|
| 116 | - */ |
|
| 117 | - public function erase($userId) { |
|
| 118 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 119 | - $qb->delete(self::DB_TABLE) |
|
| 120 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
| 121 | - ; |
|
| 122 | - return $qb->execute(); |
|
| 123 | - } |
|
| 111 | + /** |
|
| 112 | + * Erase all credentials stored for a user |
|
| 113 | + * |
|
| 114 | + * @param string $userId |
|
| 115 | + * @return int rows removed |
|
| 116 | + */ |
|
| 117 | + public function erase($userId) { |
|
| 118 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 119 | + $qb->delete(self::DB_TABLE) |
|
| 120 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
| 121 | + ; |
|
| 122 | + return $qb->execute(); |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $value = $this->crypto->encrypt(json_encode($credentials)); |
| 62 | 62 | |
| 63 | 63 | $this->dbConnection->setValues(self::DB_TABLE, [ |
| 64 | - 'user' => (string)$userId, |
|
| 64 | + 'user' => (string) $userId, |
|
| 65 | 65 | 'identifier' => $identifier, |
| 66 | 66 | ], [ |
| 67 | 67 | 'credentials' => $value, |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $qb = $this->dbConnection->getQueryBuilder(); |
| 80 | 80 | $qb->select('credentials') |
| 81 | 81 | ->from(self::DB_TABLE) |
| 82 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId))) |
|
| 82 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter((string) $userId))) |
|
| 83 | 83 | ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
| 84 | 84 | ; |
| 85 | 85 | $result = $qb->execute()->fetch(); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | public function delete($userId, $identifier) { |
| 103 | 103 | $qb = $this->dbConnection->getQueryBuilder(); |
| 104 | 104 | $qb->delete(self::DB_TABLE) |
| 105 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId))) |
|
| 105 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter((string) $userId))) |
|
| 106 | 106 | ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
| 107 | 107 | ; |
| 108 | 108 | return $qb->execute(); |