@@ -31,70 +31,70 @@ |
||
31 | 31 | use OCP\Security\ISecureRandom; |
32 | 32 | |
33 | 33 | class SettingsController extends Controller { |
34 | - /** @var IURLGenerator */ |
|
35 | - private $urlGenerator; |
|
36 | - /** @var ClientMapper */ |
|
37 | - private $clientMapper; |
|
38 | - /** @var ISecureRandom */ |
|
39 | - private $secureRandom; |
|
40 | - /** @var AccessTokenMapper */ |
|
41 | - private $accessTokenMapper; |
|
34 | + /** @var IURLGenerator */ |
|
35 | + private $urlGenerator; |
|
36 | + /** @var ClientMapper */ |
|
37 | + private $clientMapper; |
|
38 | + /** @var ISecureRandom */ |
|
39 | + private $secureRandom; |
|
40 | + /** @var AccessTokenMapper */ |
|
41 | + private $accessTokenMapper; |
|
42 | 42 | |
43 | - const validChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
43 | + const validChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $appName |
|
47 | - * @param IRequest $request |
|
48 | - * @param IURLGenerator $urlGenerator |
|
49 | - * @param ClientMapper $clientMapper |
|
50 | - * @param ISecureRandom $secureRandom |
|
51 | - * @param AccessTokenMapper $accessTokenMapper |
|
52 | - */ |
|
53 | - public function __construct($appName, |
|
54 | - IRequest $request, |
|
55 | - IURLGenerator $urlGenerator, |
|
56 | - ClientMapper $clientMapper, |
|
57 | - ISecureRandom $secureRandom, |
|
58 | - AccessTokenMapper $accessTokenMapper |
|
59 | - ) { |
|
60 | - parent::__construct($appName, $request); |
|
61 | - $this->urlGenerator = $urlGenerator; |
|
62 | - $this->secureRandom = $secureRandom; |
|
63 | - $this->clientMapper = $clientMapper; |
|
64 | - $this->accessTokenMapper = $accessTokenMapper; |
|
65 | - } |
|
45 | + /** |
|
46 | + * @param string $appName |
|
47 | + * @param IRequest $request |
|
48 | + * @param IURLGenerator $urlGenerator |
|
49 | + * @param ClientMapper $clientMapper |
|
50 | + * @param ISecureRandom $secureRandom |
|
51 | + * @param AccessTokenMapper $accessTokenMapper |
|
52 | + */ |
|
53 | + public function __construct($appName, |
|
54 | + IRequest $request, |
|
55 | + IURLGenerator $urlGenerator, |
|
56 | + ClientMapper $clientMapper, |
|
57 | + ISecureRandom $secureRandom, |
|
58 | + AccessTokenMapper $accessTokenMapper |
|
59 | + ) { |
|
60 | + parent::__construct($appName, $request); |
|
61 | + $this->urlGenerator = $urlGenerator; |
|
62 | + $this->secureRandom = $secureRandom; |
|
63 | + $this->clientMapper = $clientMapper; |
|
64 | + $this->accessTokenMapper = $accessTokenMapper; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param string $name |
|
69 | - * @param string $redirectUri |
|
70 | - * @return RedirectResponse |
|
71 | - */ |
|
72 | - public function addClient($name, |
|
73 | - $redirectUri) { |
|
74 | - $client = new Client(); |
|
75 | - $client->setName($name); |
|
76 | - $client->setRedirectUri($redirectUri); |
|
77 | - $client->setSecret($this->secureRandom->generate(64, self::validChars)); |
|
78 | - $client->setClientIdentifier($this->secureRandom->generate(64, self::validChars)); |
|
79 | - $this->clientMapper->insert($client); |
|
80 | - return new RedirectResponse($this->urlGenerator->getAbsoluteURL('/index.php/settings/admin/security')); |
|
81 | - } |
|
67 | + /** |
|
68 | + * @param string $name |
|
69 | + * @param string $redirectUri |
|
70 | + * @return RedirectResponse |
|
71 | + */ |
|
72 | + public function addClient($name, |
|
73 | + $redirectUri) { |
|
74 | + $client = new Client(); |
|
75 | + $client->setName($name); |
|
76 | + $client->setRedirectUri($redirectUri); |
|
77 | + $client->setSecret($this->secureRandom->generate(64, self::validChars)); |
|
78 | + $client->setClientIdentifier($this->secureRandom->generate(64, self::validChars)); |
|
79 | + $this->clientMapper->insert($client); |
|
80 | + return new RedirectResponse($this->urlGenerator->getAbsoluteURL('/index.php/settings/admin/security')); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param int $id |
|
85 | - * @return RedirectResponse |
|
86 | - */ |
|
87 | - public function deleteClient($id) { |
|
88 | - $accessTokens = $this->accessTokenMapper->getByClientId($id); |
|
89 | - foreach ($accessTokens as $token) { |
|
90 | - $id = $token->getTokenId(); |
|
91 | - // TODO batch delete from oc_authtoken |
|
83 | + /** |
|
84 | + * @param int $id |
|
85 | + * @return RedirectResponse |
|
86 | + */ |
|
87 | + public function deleteClient($id) { |
|
88 | + $accessTokens = $this->accessTokenMapper->getByClientId($id); |
|
89 | + foreach ($accessTokens as $token) { |
|
90 | + $id = $token->getTokenId(); |
|
91 | + // TODO batch delete from oc_authtoken |
|
92 | 92 | |
93 | - } |
|
94 | - $this->accessTokenMapper->deleteByClientId($id); |
|
95 | - $client = new Client(); |
|
96 | - $client->setId($id); |
|
97 | - $this->clientMapper->delete($client); |
|
98 | - return new RedirectResponse($this->urlGenerator->getAbsoluteURL('/index.php/settings/admin/security')); |
|
99 | - } |
|
93 | + } |
|
94 | + $this->accessTokenMapper->deleteByClientId($id); |
|
95 | + $client = new Client(); |
|
96 | + $client->setId($id); |
|
97 | + $this->clientMapper->delete($client); |
|
98 | + return new RedirectResponse($this->urlGenerator->getAbsoluteURL('/index.php/settings/admin/security')); |
|
99 | + } |
|
100 | 100 | } |
@@ -27,70 +27,70 @@ |
||
27 | 27 | |
28 | 28 | class AccessTokenMapper extends Mapper { |
29 | 29 | |
30 | - /** |
|
31 | - * @param IDBConnection $db |
|
32 | - */ |
|
33 | - public function __construct(IDBConnection $db) { |
|
34 | - parent::__construct($db, 'oauth2_access_tokens'); |
|
35 | - } |
|
30 | + /** |
|
31 | + * @param IDBConnection $db |
|
32 | + */ |
|
33 | + public function __construct(IDBConnection $db) { |
|
34 | + parent::__construct($db, 'oauth2_access_tokens'); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $code |
|
39 | - * @return AccessToken |
|
40 | - */ |
|
41 | - public function getByCode($code) { |
|
42 | - $qb = $this->db->getQueryBuilder(); |
|
43 | - $qb |
|
44 | - ->select('*') |
|
45 | - ->from($this->tableName) |
|
46 | - ->where($qb->expr()->eq('hashed_code', $qb->createNamedParameter(hash('sha512', $code)))); |
|
47 | - $result = $qb->execute(); |
|
48 | - $row = $result->fetch(); |
|
49 | - $result->closeCursor(); |
|
50 | - return AccessToken::fromRow($row); |
|
51 | - } |
|
37 | + /** |
|
38 | + * @param string $code |
|
39 | + * @return AccessToken |
|
40 | + */ |
|
41 | + public function getByCode($code) { |
|
42 | + $qb = $this->db->getQueryBuilder(); |
|
43 | + $qb |
|
44 | + ->select('*') |
|
45 | + ->from($this->tableName) |
|
46 | + ->where($qb->expr()->eq('hashed_code', $qb->createNamedParameter(hash('sha512', $code)))); |
|
47 | + $result = $qb->execute(); |
|
48 | + $row = $result->fetch(); |
|
49 | + $result->closeCursor(); |
|
50 | + return AccessToken::fromRow($row); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * get accessTokens by Client ID |
|
55 | - * |
|
56 | - * @param int $id |
|
57 | - * @return AccessToken[] |
|
58 | - */ |
|
59 | - public function getByClientId($id) { |
|
60 | - $qb = $this->db->getQueryBuilder(); |
|
61 | - $qb |
|
62 | - ->select('*') |
|
63 | - ->from($this->tableName) |
|
64 | - ->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
65 | - $result = $qb->execute(); |
|
66 | - $rows = $result->fetchAll(); |
|
67 | - $result->closeCursor(); |
|
53 | + /** |
|
54 | + * get accessTokens by Client ID |
|
55 | + * |
|
56 | + * @param int $id |
|
57 | + * @return AccessToken[] |
|
58 | + */ |
|
59 | + public function getByClientId($id) { |
|
60 | + $qb = $this->db->getQueryBuilder(); |
|
61 | + $qb |
|
62 | + ->select('*') |
|
63 | + ->from($this->tableName) |
|
64 | + ->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
65 | + $result = $qb->execute(); |
|
66 | + $rows = $result->fetchAll(); |
|
67 | + $result->closeCursor(); |
|
68 | 68 | |
69 | - if (!is_array($rows)) { |
|
70 | - $rows = []; |
|
71 | - } |
|
69 | + if (!is_array($rows)) { |
|
70 | + $rows = []; |
|
71 | + } |
|
72 | 72 | |
73 | - $accessTokens = []; |
|
73 | + $accessTokens = []; |
|
74 | 74 | |
75 | - foreach ($rows as $row) { |
|
76 | - $accessTokens[] = AccessToken::fromRow($row); |
|
77 | - } |
|
75 | + foreach ($rows as $row) { |
|
76 | + $accessTokens[] = AccessToken::fromRow($row); |
|
77 | + } |
|
78 | 78 | |
79 | - return $accessTokens; |
|
80 | - } |
|
79 | + return $accessTokens; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * delete all access token from a given client |
|
84 | - * |
|
85 | - * @param int $id |
|
86 | - */ |
|
87 | - public function deleteByClientID($id) { |
|
88 | - $qb = $this->db->getQueryBuilder(); |
|
89 | - $qb |
|
90 | - ->delete() |
|
91 | - ->from($this->tableName) |
|
92 | - ->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
93 | - $result = $qb->execute(); |
|
94 | - $result->closeCursor(); |
|
95 | - } |
|
82 | + /** |
|
83 | + * delete all access token from a given client |
|
84 | + * |
|
85 | + * @param int $id |
|
86 | + */ |
|
87 | + public function deleteByClientID($id) { |
|
88 | + $qb = $this->db->getQueryBuilder(); |
|
89 | + $qb |
|
90 | + ->delete() |
|
91 | + ->from($this->tableName) |
|
92 | + ->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
93 | + $result = $qb->execute(); |
|
94 | + $result->closeCursor(); |
|
95 | + } |
|
96 | 96 | } |