@@ -129,7 +129,7 @@ |
||
129 | 129 | $data = $result->fetchAll(); |
130 | 130 | $result->closeCursor(); |
131 | 131 | |
132 | - $entities = array_map(function ($row) { |
|
132 | + $entities = array_map(function($row) { |
|
133 | 133 | return PublicKeyToken::fromRow($row); |
134 | 134 | }, $data); |
135 | 135 |
@@ -33,158 +33,158 @@ |
||
33 | 33 | use OCP\IDBConnection; |
34 | 34 | |
35 | 35 | class PublicKeyTokenMapper extends QBMapper { |
36 | - public function __construct(IDBConnection $db) { |
|
37 | - parent::__construct($db, 'authtoken'); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Invalidate (delete) a given token |
|
42 | - * |
|
43 | - * @param string $token |
|
44 | - */ |
|
45 | - public function invalidate(string $token) { |
|
46 | - /* @var $qb IQueryBuilder */ |
|
47 | - $qb = $this->db->getQueryBuilder(); |
|
48 | - $qb->delete('authtoken') |
|
49 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
50 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
51 | - ->execute(); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param int $olderThan |
|
56 | - * @param int $remember |
|
57 | - */ |
|
58 | - public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) { |
|
59 | - /* @var $qb IQueryBuilder */ |
|
60 | - $qb = $this->db->getQueryBuilder(); |
|
61 | - $qb->delete('authtoken') |
|
62 | - ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
63 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
64 | - ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
65 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
66 | - ->execute(); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Get the user UID for the given token |
|
71 | - * |
|
72 | - * @throws DoesNotExistException |
|
73 | - */ |
|
74 | - public function getToken(string $token): PublicKeyToken { |
|
75 | - /* @var $qb IQueryBuilder */ |
|
76 | - $qb = $this->db->getQueryBuilder(); |
|
77 | - $result = $qb->select('*') |
|
78 | - ->from('authtoken') |
|
79 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
80 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
81 | - ->execute(); |
|
82 | - |
|
83 | - $data = $result->fetch(); |
|
84 | - $result->closeCursor(); |
|
85 | - if ($data === false) { |
|
86 | - throw new DoesNotExistException('token does not exist'); |
|
87 | - } |
|
88 | - return PublicKeyToken::fromRow($data); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Get the token for $id |
|
93 | - * |
|
94 | - * @throws DoesNotExistException |
|
95 | - */ |
|
96 | - public function getTokenById(int $id): PublicKeyToken { |
|
97 | - /* @var $qb IQueryBuilder */ |
|
98 | - $qb = $this->db->getQueryBuilder(); |
|
99 | - $result = $qb->select('*') |
|
100 | - ->from('authtoken') |
|
101 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
102 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
103 | - ->execute(); |
|
104 | - |
|
105 | - $data = $result->fetch(); |
|
106 | - $result->closeCursor(); |
|
107 | - if ($data === false) { |
|
108 | - throw new DoesNotExistException('token does not exist'); |
|
109 | - } |
|
110 | - return PublicKeyToken::fromRow($data); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get all tokens of a user |
|
115 | - * |
|
116 | - * The provider may limit the number of result rows in case of an abuse |
|
117 | - * where a high number of (session) tokens is generated |
|
118 | - * |
|
119 | - * @param string $uid |
|
120 | - * @return PublicKeyToken[] |
|
121 | - */ |
|
122 | - public function getTokenByUser(string $uid): array { |
|
123 | - /* @var $qb IQueryBuilder */ |
|
124 | - $qb = $this->db->getQueryBuilder(); |
|
125 | - $qb->select('*') |
|
126 | - ->from('authtoken') |
|
127 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
128 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
129 | - ->setMaxResults(1000); |
|
130 | - $result = $qb->execute(); |
|
131 | - $data = $result->fetchAll(); |
|
132 | - $result->closeCursor(); |
|
133 | - |
|
134 | - $entities = array_map(function ($row) { |
|
135 | - return PublicKeyToken::fromRow($row); |
|
136 | - }, $data); |
|
137 | - |
|
138 | - return $entities; |
|
139 | - } |
|
140 | - |
|
141 | - public function deleteById(string $uid, int $id) { |
|
142 | - /* @var $qb IQueryBuilder */ |
|
143 | - $qb = $this->db->getQueryBuilder(); |
|
144 | - $qb->delete('authtoken') |
|
145 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
146 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
147 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
148 | - $qb->execute(); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * delete all auth token which belong to a specific client if the client was deleted |
|
153 | - * |
|
154 | - * @param string $name |
|
155 | - */ |
|
156 | - public function deleteByName(string $name) { |
|
157 | - $qb = $this->db->getQueryBuilder(); |
|
158 | - $qb->delete('authtoken') |
|
159 | - ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
160 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
161 | - $qb->execute(); |
|
162 | - } |
|
163 | - |
|
164 | - public function deleteTempToken(PublicKeyToken $except) { |
|
165 | - $qb = $this->db->getQueryBuilder(); |
|
166 | - |
|
167 | - $qb->delete('authtoken') |
|
168 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($except->getUID()))) |
|
169 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) |
|
170 | - ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) |
|
171 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
172 | - |
|
173 | - $qb->execute(); |
|
174 | - } |
|
175 | - |
|
176 | - public function hasExpiredTokens(string $uid): bool { |
|
177 | - $qb = $this->db->getQueryBuilder(); |
|
178 | - $qb->select('*') |
|
179 | - ->from('authtoken') |
|
180 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
181 | - ->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL)) |
|
182 | - ->setMaxResults(1); |
|
183 | - |
|
184 | - $cursor = $qb->execute(); |
|
185 | - $data = $cursor->fetchAll(); |
|
186 | - $cursor->closeCursor(); |
|
187 | - |
|
188 | - return count($data) === 1; |
|
189 | - } |
|
36 | + public function __construct(IDBConnection $db) { |
|
37 | + parent::__construct($db, 'authtoken'); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Invalidate (delete) a given token |
|
42 | + * |
|
43 | + * @param string $token |
|
44 | + */ |
|
45 | + public function invalidate(string $token) { |
|
46 | + /* @var $qb IQueryBuilder */ |
|
47 | + $qb = $this->db->getQueryBuilder(); |
|
48 | + $qb->delete('authtoken') |
|
49 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
50 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
51 | + ->execute(); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param int $olderThan |
|
56 | + * @param int $remember |
|
57 | + */ |
|
58 | + public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) { |
|
59 | + /* @var $qb IQueryBuilder */ |
|
60 | + $qb = $this->db->getQueryBuilder(); |
|
61 | + $qb->delete('authtoken') |
|
62 | + ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
63 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
64 | + ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
65 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
66 | + ->execute(); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Get the user UID for the given token |
|
71 | + * |
|
72 | + * @throws DoesNotExistException |
|
73 | + */ |
|
74 | + public function getToken(string $token): PublicKeyToken { |
|
75 | + /* @var $qb IQueryBuilder */ |
|
76 | + $qb = $this->db->getQueryBuilder(); |
|
77 | + $result = $qb->select('*') |
|
78 | + ->from('authtoken') |
|
79 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
80 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
81 | + ->execute(); |
|
82 | + |
|
83 | + $data = $result->fetch(); |
|
84 | + $result->closeCursor(); |
|
85 | + if ($data === false) { |
|
86 | + throw new DoesNotExistException('token does not exist'); |
|
87 | + } |
|
88 | + return PublicKeyToken::fromRow($data); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Get the token for $id |
|
93 | + * |
|
94 | + * @throws DoesNotExistException |
|
95 | + */ |
|
96 | + public function getTokenById(int $id): PublicKeyToken { |
|
97 | + /* @var $qb IQueryBuilder */ |
|
98 | + $qb = $this->db->getQueryBuilder(); |
|
99 | + $result = $qb->select('*') |
|
100 | + ->from('authtoken') |
|
101 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
102 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
103 | + ->execute(); |
|
104 | + |
|
105 | + $data = $result->fetch(); |
|
106 | + $result->closeCursor(); |
|
107 | + if ($data === false) { |
|
108 | + throw new DoesNotExistException('token does not exist'); |
|
109 | + } |
|
110 | + return PublicKeyToken::fromRow($data); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get all tokens of a user |
|
115 | + * |
|
116 | + * The provider may limit the number of result rows in case of an abuse |
|
117 | + * where a high number of (session) tokens is generated |
|
118 | + * |
|
119 | + * @param string $uid |
|
120 | + * @return PublicKeyToken[] |
|
121 | + */ |
|
122 | + public function getTokenByUser(string $uid): array { |
|
123 | + /* @var $qb IQueryBuilder */ |
|
124 | + $qb = $this->db->getQueryBuilder(); |
|
125 | + $qb->select('*') |
|
126 | + ->from('authtoken') |
|
127 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
128 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
129 | + ->setMaxResults(1000); |
|
130 | + $result = $qb->execute(); |
|
131 | + $data = $result->fetchAll(); |
|
132 | + $result->closeCursor(); |
|
133 | + |
|
134 | + $entities = array_map(function ($row) { |
|
135 | + return PublicKeyToken::fromRow($row); |
|
136 | + }, $data); |
|
137 | + |
|
138 | + return $entities; |
|
139 | + } |
|
140 | + |
|
141 | + public function deleteById(string $uid, int $id) { |
|
142 | + /* @var $qb IQueryBuilder */ |
|
143 | + $qb = $this->db->getQueryBuilder(); |
|
144 | + $qb->delete('authtoken') |
|
145 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
146 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
147 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
148 | + $qb->execute(); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * delete all auth token which belong to a specific client if the client was deleted |
|
153 | + * |
|
154 | + * @param string $name |
|
155 | + */ |
|
156 | + public function deleteByName(string $name) { |
|
157 | + $qb = $this->db->getQueryBuilder(); |
|
158 | + $qb->delete('authtoken') |
|
159 | + ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
160 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
161 | + $qb->execute(); |
|
162 | + } |
|
163 | + |
|
164 | + public function deleteTempToken(PublicKeyToken $except) { |
|
165 | + $qb = $this->db->getQueryBuilder(); |
|
166 | + |
|
167 | + $qb->delete('authtoken') |
|
168 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($except->getUID()))) |
|
169 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) |
|
170 | + ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) |
|
171 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
172 | + |
|
173 | + $qb->execute(); |
|
174 | + } |
|
175 | + |
|
176 | + public function hasExpiredTokens(string $uid): bool { |
|
177 | + $qb = $this->db->getQueryBuilder(); |
|
178 | + $qb->select('*') |
|
179 | + ->from('authtoken') |
|
180 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
181 | + ->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL)) |
|
182 | + ->setMaxResults(1); |
|
183 | + |
|
184 | + $cursor = $qb->execute(); |
|
185 | + $data = $cursor->fetchAll(); |
|
186 | + $cursor->closeCursor(); |
|
187 | + |
|
188 | + return count($data) === 1; |
|
189 | + } |
|
190 | 190 | } |
@@ -36,7 +36,7 @@ |
||
36 | 36 | $l = \OC::$server->getL10N('federation'); |
37 | 37 | $this->parameterList = $missingParameters; |
38 | 38 | $parameterList = implode(',', $missingParameters); |
39 | - $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList; |
|
39 | + $message = 'Parameters missing in order to complete the request. Missing Parameters: '.$parameterList; |
|
40 | 40 | $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]); |
41 | 41 | parent::__construct($message, $hint); |
42 | 42 | } |
@@ -33,45 +33,45 @@ |
||
33 | 33 | * @since 14.0.0 |
34 | 34 | */ |
35 | 35 | class BadRequestException extends HintException { |
36 | - private $parameterList; |
|
36 | + private $parameterList; |
|
37 | 37 | |
38 | - /** |
|
39 | - * BadRequestException constructor. |
|
40 | - * |
|
41 | - * @since 14.0.0 |
|
42 | - * |
|
43 | - * @param array $missingParameters |
|
44 | - */ |
|
45 | - public function __construct(array $missingParameters) { |
|
46 | - $l = \OC::$server->getL10N('federation'); |
|
47 | - $this->parameterList = $missingParameters; |
|
48 | - $parameterList = implode(',', $missingParameters); |
|
49 | - $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList; |
|
50 | - $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]); |
|
51 | - parent::__construct($message, $hint); |
|
52 | - } |
|
38 | + /** |
|
39 | + * BadRequestException constructor. |
|
40 | + * |
|
41 | + * @since 14.0.0 |
|
42 | + * |
|
43 | + * @param array $missingParameters |
|
44 | + */ |
|
45 | + public function __construct(array $missingParameters) { |
|
46 | + $l = \OC::$server->getL10N('federation'); |
|
47 | + $this->parameterList = $missingParameters; |
|
48 | + $parameterList = implode(',', $missingParameters); |
|
49 | + $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList; |
|
50 | + $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]); |
|
51 | + parent::__construct($message, $hint); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * get array with the return message as defined in the OCM API |
|
56 | - * |
|
57 | - * @since 14.0.0 |
|
58 | - * |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public function getReturnMessage() { |
|
62 | - $result = [ |
|
63 | - 'message' => 'RESOURCE_NOT_FOUND', |
|
64 | - 'validationErrors' =>[ |
|
65 | - ] |
|
66 | - ]; |
|
54 | + /** |
|
55 | + * get array with the return message as defined in the OCM API |
|
56 | + * |
|
57 | + * @since 14.0.0 |
|
58 | + * |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public function getReturnMessage() { |
|
62 | + $result = [ |
|
63 | + 'message' => 'RESOURCE_NOT_FOUND', |
|
64 | + 'validationErrors' =>[ |
|
65 | + ] |
|
66 | + ]; |
|
67 | 67 | |
68 | - foreach ($this->parameterList as $missingParameter) { |
|
69 | - $result['validationErrors'] = [ |
|
70 | - 'name' => $missingParameter, |
|
71 | - 'message' => 'NOT_FOUND' |
|
72 | - ]; |
|
73 | - } |
|
68 | + foreach ($this->parameterList as $missingParameter) { |
|
69 | + $result['validationErrors'] = [ |
|
70 | + 'name' => $missingParameter, |
|
71 | + 'message' => 'NOT_FOUND' |
|
72 | + ]; |
|
73 | + } |
|
74 | 74 | |
75 | - return $result; |
|
76 | - } |
|
75 | + return $result; |
|
76 | + } |
|
77 | 77 | } |
@@ -29,52 +29,52 @@ |
||
29 | 29 | * @since 13.0.0 |
30 | 30 | */ |
31 | 31 | abstract class SimpleMigrationStep implements IMigrationStep { |
32 | - /** |
|
33 | - * Human readable name of the migration step |
|
34 | - * |
|
35 | - * @return string |
|
36 | - * @since 14.0.0 |
|
37 | - */ |
|
38 | - public function name(): string { |
|
39 | - return ''; |
|
40 | - } |
|
32 | + /** |
|
33 | + * Human readable name of the migration step |
|
34 | + * |
|
35 | + * @return string |
|
36 | + * @since 14.0.0 |
|
37 | + */ |
|
38 | + public function name(): string { |
|
39 | + return ''; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Human readable description of the migration step |
|
44 | - * |
|
45 | - * @return string |
|
46 | - * @since 14.0.0 |
|
47 | - */ |
|
48 | - public function description(): string { |
|
49 | - return ''; |
|
50 | - } |
|
42 | + /** |
|
43 | + * Human readable description of the migration step |
|
44 | + * |
|
45 | + * @return string |
|
46 | + * @since 14.0.0 |
|
47 | + */ |
|
48 | + public function description(): string { |
|
49 | + return ''; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param IOutput $output |
|
54 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
55 | - * @param array $options |
|
56 | - * @since 13.0.0 |
|
57 | - */ |
|
58 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
59 | - } |
|
52 | + /** |
|
53 | + * @param IOutput $output |
|
54 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
55 | + * @param array $options |
|
56 | + * @since 13.0.0 |
|
57 | + */ |
|
58 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param IOutput $output |
|
63 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
64 | - * @param array $options |
|
65 | - * @return null|ISchemaWrapper |
|
66 | - * @since 13.0.0 |
|
67 | - */ |
|
68 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
69 | - return null; |
|
70 | - } |
|
61 | + /** |
|
62 | + * @param IOutput $output |
|
63 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
64 | + * @param array $options |
|
65 | + * @return null|ISchemaWrapper |
|
66 | + * @since 13.0.0 |
|
67 | + */ |
|
68 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
69 | + return null; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param IOutput $output |
|
74 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
75 | - * @param array $options |
|
76 | - * @since 13.0.0 |
|
77 | - */ |
|
78 | - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
79 | - } |
|
72 | + /** |
|
73 | + * @param IOutput $output |
|
74 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
75 | + * @param array $options |
|
76 | + * @since 13.0.0 |
|
77 | + */ |
|
78 | + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
79 | + } |
|
80 | 80 | } |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | private function getBlobClient() { |
60 | 60 | if (!$this->blobClient) { |
61 | 61 | $protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https'; |
62 | - $connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey; |
|
62 | + $connectionString = "DefaultEndpointsProtocol=".$protocol.";AccountName=".$this->accountName.";AccountKey=".$this->accountKey; |
|
63 | 63 | if ($this->endpoint) { |
64 | - $connectionString .= ';BlobEndpoint=' . $this->endpoint; |
|
64 | + $connectionString .= ';BlobEndpoint='.$this->endpoint; |
|
65 | 65 | } |
66 | 66 | $this->blobClient = BlobRestProxy::createBlobService($connectionString); |
67 | 67 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @return string the container or bucket name where objects are stored |
77 | 77 | */ |
78 | 78 | public function getStorageId() { |
79 | - return 'azure::blob::' . $this->containerName; |
|
79 | + return 'azure::blob::'.$this->containerName; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -26,106 +26,106 @@ |
||
26 | 26 | use OCP\Files\ObjectStore\IObjectStore; |
27 | 27 | |
28 | 28 | class Azure implements IObjectStore { |
29 | - /** @var string */ |
|
30 | - private $containerName; |
|
31 | - /** @var string */ |
|
32 | - private $accountName; |
|
33 | - /** @var string */ |
|
34 | - private $accountKey; |
|
35 | - /** @var BlobRestProxy|null */ |
|
36 | - private $blobClient = null; |
|
37 | - /** @var string|null */ |
|
38 | - private $endpoint = null; |
|
39 | - /** @var bool */ |
|
40 | - private $autoCreate = false; |
|
29 | + /** @var string */ |
|
30 | + private $containerName; |
|
31 | + /** @var string */ |
|
32 | + private $accountName; |
|
33 | + /** @var string */ |
|
34 | + private $accountKey; |
|
35 | + /** @var BlobRestProxy|null */ |
|
36 | + private $blobClient = null; |
|
37 | + /** @var string|null */ |
|
38 | + private $endpoint = null; |
|
39 | + /** @var bool */ |
|
40 | + private $autoCreate = false; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param array $parameters |
|
44 | - */ |
|
45 | - public function __construct($parameters) { |
|
46 | - $this->containerName = $parameters['container']; |
|
47 | - $this->accountName = $parameters['account_name']; |
|
48 | - $this->accountKey = $parameters['account_key']; |
|
49 | - if (isset($parameters['endpoint'])) { |
|
50 | - $this->endpoint = $parameters['endpoint']; |
|
51 | - } |
|
52 | - if (isset($parameters['autocreate'])) { |
|
53 | - $this->autoCreate = $parameters['autocreate']; |
|
54 | - } |
|
55 | - } |
|
42 | + /** |
|
43 | + * @param array $parameters |
|
44 | + */ |
|
45 | + public function __construct($parameters) { |
|
46 | + $this->containerName = $parameters['container']; |
|
47 | + $this->accountName = $parameters['account_name']; |
|
48 | + $this->accountKey = $parameters['account_key']; |
|
49 | + if (isset($parameters['endpoint'])) { |
|
50 | + $this->endpoint = $parameters['endpoint']; |
|
51 | + } |
|
52 | + if (isset($parameters['autocreate'])) { |
|
53 | + $this->autoCreate = $parameters['autocreate']; |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return BlobRestProxy |
|
59 | - */ |
|
60 | - private function getBlobClient() { |
|
61 | - if (!$this->blobClient) { |
|
62 | - $protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https'; |
|
63 | - $connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey; |
|
64 | - if ($this->endpoint) { |
|
65 | - $connectionString .= ';BlobEndpoint=' . $this->endpoint; |
|
66 | - } |
|
67 | - $this->blobClient = BlobRestProxy::createBlobService($connectionString); |
|
57 | + /** |
|
58 | + * @return BlobRestProxy |
|
59 | + */ |
|
60 | + private function getBlobClient() { |
|
61 | + if (!$this->blobClient) { |
|
62 | + $protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https'; |
|
63 | + $connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey; |
|
64 | + if ($this->endpoint) { |
|
65 | + $connectionString .= ';BlobEndpoint=' . $this->endpoint; |
|
66 | + } |
|
67 | + $this->blobClient = BlobRestProxy::createBlobService($connectionString); |
|
68 | 68 | |
69 | - if ($this->autoCreate) { |
|
70 | - try { |
|
71 | - $this->blobClient->createContainer($this->containerName); |
|
72 | - } catch (ServiceException $e) { |
|
73 | - if ($e->getCode() === 409) { |
|
74 | - // already exists |
|
75 | - } else { |
|
76 | - throw $e; |
|
77 | - } |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - return $this->blobClient; |
|
82 | - } |
|
69 | + if ($this->autoCreate) { |
|
70 | + try { |
|
71 | + $this->blobClient->createContainer($this->containerName); |
|
72 | + } catch (ServiceException $e) { |
|
73 | + if ($e->getCode() === 409) { |
|
74 | + // already exists |
|
75 | + } else { |
|
76 | + throw $e; |
|
77 | + } |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + return $this->blobClient; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return string the container or bucket name where objects are stored |
|
86 | - */ |
|
87 | - public function getStorageId() { |
|
88 | - return 'azure::blob::' . $this->containerName; |
|
89 | - } |
|
84 | + /** |
|
85 | + * @return string the container or bucket name where objects are stored |
|
86 | + */ |
|
87 | + public function getStorageId() { |
|
88 | + return 'azure::blob::' . $this->containerName; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $urn the unified resource name used to identify the object |
|
93 | - * @return resource stream with the read data |
|
94 | - * @throws \Exception when something goes wrong, message will be logged |
|
95 | - */ |
|
96 | - public function readObject($urn) { |
|
97 | - $blob = $this->getBlobClient()->getBlob($this->containerName, $urn); |
|
98 | - return $blob->getContentStream(); |
|
99 | - } |
|
91 | + /** |
|
92 | + * @param string $urn the unified resource name used to identify the object |
|
93 | + * @return resource stream with the read data |
|
94 | + * @throws \Exception when something goes wrong, message will be logged |
|
95 | + */ |
|
96 | + public function readObject($urn) { |
|
97 | + $blob = $this->getBlobClient()->getBlob($this->containerName, $urn); |
|
98 | + return $blob->getContentStream(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param string $urn the unified resource name used to identify the object |
|
103 | - * @param resource $stream stream with the data to write |
|
104 | - * @throws \Exception when something goes wrong, message will be logged |
|
105 | - */ |
|
106 | - public function writeObject($urn, $stream) { |
|
107 | - $this->getBlobClient()->createBlockBlob($this->containerName, $urn, $stream); |
|
108 | - } |
|
101 | + /** |
|
102 | + * @param string $urn the unified resource name used to identify the object |
|
103 | + * @param resource $stream stream with the data to write |
|
104 | + * @throws \Exception when something goes wrong, message will be logged |
|
105 | + */ |
|
106 | + public function writeObject($urn, $stream) { |
|
107 | + $this->getBlobClient()->createBlockBlob($this->containerName, $urn, $stream); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @param string $urn the unified resource name used to identify the object |
|
112 | - * @return void |
|
113 | - * @throws \Exception when something goes wrong, message will be logged |
|
114 | - */ |
|
115 | - public function deleteObject($urn) { |
|
116 | - $this->getBlobClient()->deleteBlob($this->containerName, $urn); |
|
117 | - } |
|
110 | + /** |
|
111 | + * @param string $urn the unified resource name used to identify the object |
|
112 | + * @return void |
|
113 | + * @throws \Exception when something goes wrong, message will be logged |
|
114 | + */ |
|
115 | + public function deleteObject($urn) { |
|
116 | + $this->getBlobClient()->deleteBlob($this->containerName, $urn); |
|
117 | + } |
|
118 | 118 | |
119 | - public function objectExists($urn) { |
|
120 | - try { |
|
121 | - $this->getBlobClient()->getBlobMetadata($this->containerName, $urn); |
|
122 | - return true; |
|
123 | - } catch (ServiceException $e) { |
|
124 | - if ($e->getCode() === 404) { |
|
125 | - return false; |
|
126 | - } else { |
|
127 | - throw $e; |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
119 | + public function objectExists($urn) { |
|
120 | + try { |
|
121 | + $this->getBlobClient()->getBlobMetadata($this->containerName, $urn); |
|
122 | + return true; |
|
123 | + } catch (ServiceException $e) { |
|
124 | + if ($e->getCode() === 404) { |
|
125 | + return false; |
|
126 | + } else { |
|
127 | + throw $e; |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | 131 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $ocsStatus = isset($status['ocs']); |
118 | 118 | $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
119 | 119 | |
120 | - if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { |
|
120 | + if ($result['success'] && (!$ocsStatus || $ocsSuccess)) { |
|
121 | 121 | \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
122 | 122 | return true; |
123 | 123 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | return [$ocmResult['token'], $ocmResult['providerId']]; |
161 | 161 | } |
162 | 162 | |
163 | - $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
163 | + $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/'.$id.'/reshare', $fields); |
|
164 | 164 | $status = json_decode($result['result'], true); |
165 | 165 | |
166 | 166 | $httpRequestSuccessful = $result['success']; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
172 | 172 | return [ |
173 | 173 | $status['ocs']['data']['token'], |
174 | - (int)$status['ocs']['data']['remoteId'] |
|
174 | + (int) $status['ocs']['data']['remoteId'] |
|
175 | 175 | ]; |
176 | 176 | } |
177 | 177 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $fields[$key] = $value; |
259 | 259 | } |
260 | 260 | |
261 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action); |
|
261 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/'.$remoteId.'/'.$action, $fields, $action); |
|
262 | 262 | $status = json_decode($result['result'], true); |
263 | 263 | |
264 | 264 | if ($result['success'] && |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | * @return array |
307 | 307 | * @throws \Exception |
308 | 308 | */ |
309 | - protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") { |
|
309 | + protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action = "share") { |
|
310 | 310 | |
311 | 311 | if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
312 | - $remoteDomain = 'https://' . $remoteDomain; |
|
312 | + $remoteDomain = 'https://'.$remoteDomain; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | $result = [ |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
349 | 349 | $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
350 | 350 | try { |
351 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
351 | + $response = $client->post($remoteDomain.$endpoint.$urlSuffix.'?format='.self::RESPONSE_FORMAT, [ |
|
352 | 352 | 'body' => $fields, |
353 | 353 | 'timeout' => 10, |
354 | 354 | 'connect_timeout' => 10, |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | switch ($action) { |
406 | 406 | case 'share': |
407 | 407 | $share = $this->cloudFederationFactory->getCloudFederationShare( |
408 | - $fields['shareWith'] . '@' . $remoteDomain, |
|
408 | + $fields['shareWith'].'@'.$remoteDomain, |
|
409 | 409 | $fields['name'], |
410 | 410 | '', |
411 | 411 | $fields['remoteId'], |
@@ -33,405 +33,405 @@ |
||
33 | 33 | use OCP\OCS\IDiscoveryService; |
34 | 34 | |
35 | 35 | class Notifications { |
36 | - public const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
37 | - |
|
38 | - /** @var AddressHandler */ |
|
39 | - private $addressHandler; |
|
40 | - |
|
41 | - /** @var IClientService */ |
|
42 | - private $httpClientService; |
|
43 | - |
|
44 | - /** @var IDiscoveryService */ |
|
45 | - private $discoveryService; |
|
46 | - |
|
47 | - /** @var IJobList */ |
|
48 | - private $jobList; |
|
49 | - |
|
50 | - /** @var ICloudFederationProviderManager */ |
|
51 | - private $federationProviderManager; |
|
52 | - |
|
53 | - /** @var ICloudFederationFactory */ |
|
54 | - private $cloudFederationFactory; |
|
55 | - |
|
56 | - /** |
|
57 | - * @param AddressHandler $addressHandler |
|
58 | - * @param IClientService $httpClientService |
|
59 | - * @param IDiscoveryService $discoveryService |
|
60 | - * @param IJobList $jobList |
|
61 | - * @param ICloudFederationProviderManager $federationProviderManager |
|
62 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
63 | - */ |
|
64 | - public function __construct( |
|
65 | - AddressHandler $addressHandler, |
|
66 | - IClientService $httpClientService, |
|
67 | - IDiscoveryService $discoveryService, |
|
68 | - IJobList $jobList, |
|
69 | - ICloudFederationProviderManager $federationProviderManager, |
|
70 | - ICloudFederationFactory $cloudFederationFactory |
|
71 | - ) { |
|
72 | - $this->addressHandler = $addressHandler; |
|
73 | - $this->httpClientService = $httpClientService; |
|
74 | - $this->discoveryService = $discoveryService; |
|
75 | - $this->jobList = $jobList; |
|
76 | - $this->federationProviderManager = $federationProviderManager; |
|
77 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * send server-to-server share to remote server |
|
82 | - * |
|
83 | - * @param string $token |
|
84 | - * @param string $shareWith |
|
85 | - * @param string $name |
|
86 | - * @param int $remote_id |
|
87 | - * @param string $owner |
|
88 | - * @param string $ownerFederatedId |
|
89 | - * @param string $sharedBy |
|
90 | - * @param string $sharedByFederatedId |
|
91 | - * @param int $shareType (can be a remote user or group share) |
|
92 | - * @return bool |
|
93 | - * @throws \OC\HintException |
|
94 | - * @throws \OC\ServerNotAvailableException |
|
95 | - */ |
|
96 | - public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId, $shareType) { |
|
97 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
98 | - |
|
99 | - if ($user && $remote) { |
|
100 | - $local = $this->addressHandler->generateRemoteURL(); |
|
101 | - |
|
102 | - $fields = [ |
|
103 | - 'shareWith' => $user, |
|
104 | - 'token' => $token, |
|
105 | - 'name' => $name, |
|
106 | - 'remoteId' => $remote_id, |
|
107 | - 'owner' => $owner, |
|
108 | - 'ownerFederatedId' => $ownerFederatedId, |
|
109 | - 'sharedBy' => $sharedBy, |
|
110 | - 'sharedByFederatedId' => $sharedByFederatedId, |
|
111 | - 'remote' => $local, |
|
112 | - 'shareType' => $shareType |
|
113 | - ]; |
|
114 | - |
|
115 | - $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
116 | - $status = json_decode($result['result'], true); |
|
117 | - |
|
118 | - $ocsStatus = isset($status['ocs']); |
|
119 | - $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
120 | - |
|
121 | - if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { |
|
122 | - \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
123 | - return true; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - return false; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * ask owner to re-share the file with the given user |
|
132 | - * |
|
133 | - * @param string $token |
|
134 | - * @param int $id remote Id |
|
135 | - * @param int $shareId internal share Id |
|
136 | - * @param string $remote remote address of the owner |
|
137 | - * @param string $shareWith |
|
138 | - * @param int $permission |
|
139 | - * @param string $filename |
|
140 | - * @return bool |
|
141 | - * @throws \OC\HintException |
|
142 | - * @throws \OC\ServerNotAvailableException |
|
143 | - */ |
|
144 | - public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission, $filename) { |
|
145 | - $fields = [ |
|
146 | - 'shareWith' => $shareWith, |
|
147 | - 'token' => $token, |
|
148 | - 'permission' => $permission, |
|
149 | - 'remoteId' => $shareId, |
|
150 | - ]; |
|
151 | - |
|
152 | - $ocmFields = $fields; |
|
153 | - $ocmFields['remoteId'] = $id; |
|
154 | - $ocmFields['localId'] = $shareId; |
|
155 | - $ocmFields['name'] = $filename; |
|
156 | - |
|
157 | - $ocmResult = $this->tryOCMEndPoint($remote, $ocmFields, 'reshare'); |
|
158 | - if (is_array($ocmResult) && isset($ocmResult['token']) && isset($ocmResult['providerId'])) { |
|
159 | - return [$ocmResult['token'], $ocmResult['providerId']]; |
|
160 | - } |
|
161 | - |
|
162 | - $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
163 | - $status = json_decode($result['result'], true); |
|
164 | - |
|
165 | - $httpRequestSuccessful = $result['success']; |
|
166 | - $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
167 | - $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
168 | - $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
169 | - |
|
170 | - if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
171 | - return [ |
|
172 | - $status['ocs']['data']['token'], |
|
173 | - (int)$status['ocs']['data']['remoteId'] |
|
174 | - ]; |
|
175 | - } |
|
176 | - |
|
177 | - return false; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * send server-to-server unshare to remote server |
|
182 | - * |
|
183 | - * @param string $remote url |
|
184 | - * @param int $id share id |
|
185 | - * @param string $token |
|
186 | - * @return bool |
|
187 | - */ |
|
188 | - public function sendRemoteUnShare($remote, $id, $token) { |
|
189 | - $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * send server-to-server unshare to remote server |
|
194 | - * |
|
195 | - * @param string $remote url |
|
196 | - * @param int $id share id |
|
197 | - * @param string $token |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function sendRevokeShare($remote, $id, $token) { |
|
201 | - $this->sendUpdateToRemote($remote, $id, $token, 'reshare_undo'); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * send notification to remote server if the permissions was changed |
|
206 | - * |
|
207 | - * @param string $remote |
|
208 | - * @param int $remoteId |
|
209 | - * @param string $token |
|
210 | - * @param int $permissions |
|
211 | - * @return bool |
|
212 | - */ |
|
213 | - public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
214 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * forward accept reShare to remote server |
|
219 | - * |
|
220 | - * @param string $remote |
|
221 | - * @param int $remoteId |
|
222 | - * @param string $token |
|
223 | - */ |
|
224 | - public function sendAcceptShare($remote, $remoteId, $token) { |
|
225 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * forward decline reShare to remote server |
|
230 | - * |
|
231 | - * @param string $remote |
|
232 | - * @param int $remoteId |
|
233 | - * @param string $token |
|
234 | - */ |
|
235 | - public function sendDeclineShare($remote, $remoteId, $token) { |
|
236 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * inform remote server whether server-to-server share was accepted/declined |
|
241 | - * |
|
242 | - * @param string $remote |
|
243 | - * @param string $token |
|
244 | - * @param int $remoteId Share id on the remote host |
|
245 | - * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
246 | - * @param array $data |
|
247 | - * @param int $try |
|
248 | - * @return boolean |
|
249 | - */ |
|
250 | - public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
251 | - $fields = [ |
|
252 | - 'token' => $token, |
|
253 | - 'remoteId' => $remoteId |
|
254 | - ]; |
|
255 | - foreach ($data as $key => $value) { |
|
256 | - $fields[$key] = $value; |
|
257 | - } |
|
258 | - |
|
259 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action); |
|
260 | - $status = json_decode($result['result'], true); |
|
261 | - |
|
262 | - if ($result['success'] && |
|
263 | - ($status['ocs']['meta']['statuscode'] === 100 || |
|
264 | - $status['ocs']['meta']['statuscode'] === 200 |
|
265 | - ) |
|
266 | - ) { |
|
267 | - return true; |
|
268 | - } elseif ($try === 0) { |
|
269 | - // only add new job on first try |
|
270 | - $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
271 | - [ |
|
272 | - 'remote' => $remote, |
|
273 | - 'remoteId' => $remoteId, |
|
274 | - 'token' => $token, |
|
275 | - 'action' => $action, |
|
276 | - 'data' => json_encode($data), |
|
277 | - 'try' => $try, |
|
278 | - 'lastRun' => $this->getTimestamp() |
|
279 | - ] |
|
280 | - ); |
|
281 | - } |
|
282 | - |
|
283 | - return false; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * return current timestamp |
|
289 | - * |
|
290 | - * @return int |
|
291 | - */ |
|
292 | - protected function getTimestamp() { |
|
293 | - return time(); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * try http post with the given protocol, if no protocol is given we pick |
|
298 | - * the secure one (https) |
|
299 | - * |
|
300 | - * @param string $remoteDomain |
|
301 | - * @param string $urlSuffix |
|
302 | - * @param array $fields post parameters |
|
303 | - * @param string $action define the action (possible values: share, reshare, accept, decline, unshare, revoke, permissions) |
|
304 | - * @return array |
|
305 | - * @throws \Exception |
|
306 | - */ |
|
307 | - protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") { |
|
308 | - if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
309 | - $remoteDomain = 'https://' . $remoteDomain; |
|
310 | - } |
|
311 | - |
|
312 | - $result = [ |
|
313 | - 'success' => false, |
|
314 | - 'result' => '', |
|
315 | - ]; |
|
316 | - |
|
317 | - // if possible we use the new OCM API |
|
318 | - $ocmResult = $this->tryOCMEndPoint($remoteDomain, $fields, $action); |
|
319 | - if (is_array($ocmResult)) { |
|
320 | - $result['success'] = true; |
|
321 | - $result['result'] = json_encode([ |
|
322 | - 'ocs' => ['meta' => ['statuscode' => 200]]]); |
|
323 | - return $result; |
|
324 | - } |
|
325 | - |
|
326 | - return $this->tryLegacyEndPoint($remoteDomain, $urlSuffix, $fields); |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * try old federated sharing API if the OCM api doesn't work |
|
331 | - * |
|
332 | - * @param $remoteDomain |
|
333 | - * @param $urlSuffix |
|
334 | - * @param array $fields |
|
335 | - * @return mixed |
|
336 | - * @throws \Exception |
|
337 | - */ |
|
338 | - protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) { |
|
339 | - $result = [ |
|
340 | - 'success' => false, |
|
341 | - 'result' => '', |
|
342 | - ]; |
|
343 | - |
|
344 | - // Fall back to old API |
|
345 | - $client = $this->httpClientService->newClient(); |
|
346 | - $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
347 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
348 | - try { |
|
349 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
350 | - 'body' => $fields, |
|
351 | - 'timeout' => 10, |
|
352 | - 'connect_timeout' => 10, |
|
353 | - ]); |
|
354 | - $result['result'] = $response->getBody(); |
|
355 | - $result['success'] = true; |
|
356 | - } catch (\Exception $e) { |
|
357 | - // if flat re-sharing is not supported by the remote server |
|
358 | - // we re-throw the exception and fall back to the old behaviour. |
|
359 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
360 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
361 | - throw $e; |
|
362 | - } |
|
363 | - } |
|
364 | - |
|
365 | - return $result; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * send action regarding federated sharing to the remote server using the OCM API |
|
370 | - * |
|
371 | - * @param $remoteDomain |
|
372 | - * @param $fields |
|
373 | - * @param $action |
|
374 | - * |
|
375 | - * @return bool |
|
376 | - */ |
|
377 | - protected function tryOCMEndPoint($remoteDomain, $fields, $action) { |
|
378 | - switch ($action) { |
|
379 | - case 'share': |
|
380 | - $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
381 | - $fields['shareWith'] . '@' . $remoteDomain, |
|
382 | - $fields['name'], |
|
383 | - '', |
|
384 | - $fields['remoteId'], |
|
385 | - $fields['ownerFederatedId'], |
|
386 | - $fields['owner'], |
|
387 | - $fields['sharedByFederatedId'], |
|
388 | - $fields['sharedBy'], |
|
389 | - $fields['token'], |
|
390 | - $fields['shareType'], |
|
391 | - 'file' |
|
392 | - ); |
|
393 | - return $this->federationProviderManager->sendShare($share); |
|
394 | - case 'reshare': |
|
395 | - // ask owner to reshare a file |
|
396 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
397 | - $notification->setMessage('REQUEST_RESHARE', |
|
398 | - 'file', |
|
399 | - $fields['remoteId'], |
|
400 | - [ |
|
401 | - 'sharedSecret' => $fields['token'], |
|
402 | - 'shareWith' => $fields['shareWith'], |
|
403 | - 'senderId' => $fields['localId'], |
|
404 | - 'shareType' => $fields['shareType'], |
|
405 | - 'message' => 'Ask owner to reshare the file' |
|
406 | - ] |
|
407 | - ); |
|
408 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
409 | - case 'unshare': |
|
410 | - //owner unshares the file from the recipient again |
|
411 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
412 | - $notification->setMessage('SHARE_UNSHARED', |
|
413 | - 'file', |
|
414 | - $fields['remoteId'], |
|
415 | - [ |
|
416 | - 'sharedSecret' => $fields['token'], |
|
417 | - 'messgage' => 'file is no longer shared with you' |
|
418 | - ] |
|
419 | - ); |
|
420 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
421 | - case 'reshare_undo': |
|
422 | - // if a reshare was unshared we send the information to the initiator/owner |
|
423 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
424 | - $notification->setMessage('RESHARE_UNDO', |
|
425 | - 'file', |
|
426 | - $fields['remoteId'], |
|
427 | - [ |
|
428 | - 'sharedSecret' => $fields['token'], |
|
429 | - 'message' => 'reshare was revoked' |
|
430 | - ] |
|
431 | - ); |
|
432 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
433 | - } |
|
434 | - |
|
435 | - return false; |
|
436 | - } |
|
36 | + public const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
37 | + |
|
38 | + /** @var AddressHandler */ |
|
39 | + private $addressHandler; |
|
40 | + |
|
41 | + /** @var IClientService */ |
|
42 | + private $httpClientService; |
|
43 | + |
|
44 | + /** @var IDiscoveryService */ |
|
45 | + private $discoveryService; |
|
46 | + |
|
47 | + /** @var IJobList */ |
|
48 | + private $jobList; |
|
49 | + |
|
50 | + /** @var ICloudFederationProviderManager */ |
|
51 | + private $federationProviderManager; |
|
52 | + |
|
53 | + /** @var ICloudFederationFactory */ |
|
54 | + private $cloudFederationFactory; |
|
55 | + |
|
56 | + /** |
|
57 | + * @param AddressHandler $addressHandler |
|
58 | + * @param IClientService $httpClientService |
|
59 | + * @param IDiscoveryService $discoveryService |
|
60 | + * @param IJobList $jobList |
|
61 | + * @param ICloudFederationProviderManager $federationProviderManager |
|
62 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
63 | + */ |
|
64 | + public function __construct( |
|
65 | + AddressHandler $addressHandler, |
|
66 | + IClientService $httpClientService, |
|
67 | + IDiscoveryService $discoveryService, |
|
68 | + IJobList $jobList, |
|
69 | + ICloudFederationProviderManager $federationProviderManager, |
|
70 | + ICloudFederationFactory $cloudFederationFactory |
|
71 | + ) { |
|
72 | + $this->addressHandler = $addressHandler; |
|
73 | + $this->httpClientService = $httpClientService; |
|
74 | + $this->discoveryService = $discoveryService; |
|
75 | + $this->jobList = $jobList; |
|
76 | + $this->federationProviderManager = $federationProviderManager; |
|
77 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * send server-to-server share to remote server |
|
82 | + * |
|
83 | + * @param string $token |
|
84 | + * @param string $shareWith |
|
85 | + * @param string $name |
|
86 | + * @param int $remote_id |
|
87 | + * @param string $owner |
|
88 | + * @param string $ownerFederatedId |
|
89 | + * @param string $sharedBy |
|
90 | + * @param string $sharedByFederatedId |
|
91 | + * @param int $shareType (can be a remote user or group share) |
|
92 | + * @return bool |
|
93 | + * @throws \OC\HintException |
|
94 | + * @throws \OC\ServerNotAvailableException |
|
95 | + */ |
|
96 | + public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId, $shareType) { |
|
97 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
98 | + |
|
99 | + if ($user && $remote) { |
|
100 | + $local = $this->addressHandler->generateRemoteURL(); |
|
101 | + |
|
102 | + $fields = [ |
|
103 | + 'shareWith' => $user, |
|
104 | + 'token' => $token, |
|
105 | + 'name' => $name, |
|
106 | + 'remoteId' => $remote_id, |
|
107 | + 'owner' => $owner, |
|
108 | + 'ownerFederatedId' => $ownerFederatedId, |
|
109 | + 'sharedBy' => $sharedBy, |
|
110 | + 'sharedByFederatedId' => $sharedByFederatedId, |
|
111 | + 'remote' => $local, |
|
112 | + 'shareType' => $shareType |
|
113 | + ]; |
|
114 | + |
|
115 | + $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
116 | + $status = json_decode($result['result'], true); |
|
117 | + |
|
118 | + $ocsStatus = isset($status['ocs']); |
|
119 | + $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
120 | + |
|
121 | + if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { |
|
122 | + \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
123 | + return true; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + return false; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * ask owner to re-share the file with the given user |
|
132 | + * |
|
133 | + * @param string $token |
|
134 | + * @param int $id remote Id |
|
135 | + * @param int $shareId internal share Id |
|
136 | + * @param string $remote remote address of the owner |
|
137 | + * @param string $shareWith |
|
138 | + * @param int $permission |
|
139 | + * @param string $filename |
|
140 | + * @return bool |
|
141 | + * @throws \OC\HintException |
|
142 | + * @throws \OC\ServerNotAvailableException |
|
143 | + */ |
|
144 | + public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission, $filename) { |
|
145 | + $fields = [ |
|
146 | + 'shareWith' => $shareWith, |
|
147 | + 'token' => $token, |
|
148 | + 'permission' => $permission, |
|
149 | + 'remoteId' => $shareId, |
|
150 | + ]; |
|
151 | + |
|
152 | + $ocmFields = $fields; |
|
153 | + $ocmFields['remoteId'] = $id; |
|
154 | + $ocmFields['localId'] = $shareId; |
|
155 | + $ocmFields['name'] = $filename; |
|
156 | + |
|
157 | + $ocmResult = $this->tryOCMEndPoint($remote, $ocmFields, 'reshare'); |
|
158 | + if (is_array($ocmResult) && isset($ocmResult['token']) && isset($ocmResult['providerId'])) { |
|
159 | + return [$ocmResult['token'], $ocmResult['providerId']]; |
|
160 | + } |
|
161 | + |
|
162 | + $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
163 | + $status = json_decode($result['result'], true); |
|
164 | + |
|
165 | + $httpRequestSuccessful = $result['success']; |
|
166 | + $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
167 | + $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
168 | + $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
169 | + |
|
170 | + if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
171 | + return [ |
|
172 | + $status['ocs']['data']['token'], |
|
173 | + (int)$status['ocs']['data']['remoteId'] |
|
174 | + ]; |
|
175 | + } |
|
176 | + |
|
177 | + return false; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * send server-to-server unshare to remote server |
|
182 | + * |
|
183 | + * @param string $remote url |
|
184 | + * @param int $id share id |
|
185 | + * @param string $token |
|
186 | + * @return bool |
|
187 | + */ |
|
188 | + public function sendRemoteUnShare($remote, $id, $token) { |
|
189 | + $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * send server-to-server unshare to remote server |
|
194 | + * |
|
195 | + * @param string $remote url |
|
196 | + * @param int $id share id |
|
197 | + * @param string $token |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function sendRevokeShare($remote, $id, $token) { |
|
201 | + $this->sendUpdateToRemote($remote, $id, $token, 'reshare_undo'); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * send notification to remote server if the permissions was changed |
|
206 | + * |
|
207 | + * @param string $remote |
|
208 | + * @param int $remoteId |
|
209 | + * @param string $token |
|
210 | + * @param int $permissions |
|
211 | + * @return bool |
|
212 | + */ |
|
213 | + public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
214 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * forward accept reShare to remote server |
|
219 | + * |
|
220 | + * @param string $remote |
|
221 | + * @param int $remoteId |
|
222 | + * @param string $token |
|
223 | + */ |
|
224 | + public function sendAcceptShare($remote, $remoteId, $token) { |
|
225 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * forward decline reShare to remote server |
|
230 | + * |
|
231 | + * @param string $remote |
|
232 | + * @param int $remoteId |
|
233 | + * @param string $token |
|
234 | + */ |
|
235 | + public function sendDeclineShare($remote, $remoteId, $token) { |
|
236 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * inform remote server whether server-to-server share was accepted/declined |
|
241 | + * |
|
242 | + * @param string $remote |
|
243 | + * @param string $token |
|
244 | + * @param int $remoteId Share id on the remote host |
|
245 | + * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
246 | + * @param array $data |
|
247 | + * @param int $try |
|
248 | + * @return boolean |
|
249 | + */ |
|
250 | + public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
251 | + $fields = [ |
|
252 | + 'token' => $token, |
|
253 | + 'remoteId' => $remoteId |
|
254 | + ]; |
|
255 | + foreach ($data as $key => $value) { |
|
256 | + $fields[$key] = $value; |
|
257 | + } |
|
258 | + |
|
259 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action); |
|
260 | + $status = json_decode($result['result'], true); |
|
261 | + |
|
262 | + if ($result['success'] && |
|
263 | + ($status['ocs']['meta']['statuscode'] === 100 || |
|
264 | + $status['ocs']['meta']['statuscode'] === 200 |
|
265 | + ) |
|
266 | + ) { |
|
267 | + return true; |
|
268 | + } elseif ($try === 0) { |
|
269 | + // only add new job on first try |
|
270 | + $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
271 | + [ |
|
272 | + 'remote' => $remote, |
|
273 | + 'remoteId' => $remoteId, |
|
274 | + 'token' => $token, |
|
275 | + 'action' => $action, |
|
276 | + 'data' => json_encode($data), |
|
277 | + 'try' => $try, |
|
278 | + 'lastRun' => $this->getTimestamp() |
|
279 | + ] |
|
280 | + ); |
|
281 | + } |
|
282 | + |
|
283 | + return false; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * return current timestamp |
|
289 | + * |
|
290 | + * @return int |
|
291 | + */ |
|
292 | + protected function getTimestamp() { |
|
293 | + return time(); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * try http post with the given protocol, if no protocol is given we pick |
|
298 | + * the secure one (https) |
|
299 | + * |
|
300 | + * @param string $remoteDomain |
|
301 | + * @param string $urlSuffix |
|
302 | + * @param array $fields post parameters |
|
303 | + * @param string $action define the action (possible values: share, reshare, accept, decline, unshare, revoke, permissions) |
|
304 | + * @return array |
|
305 | + * @throws \Exception |
|
306 | + */ |
|
307 | + protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") { |
|
308 | + if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
309 | + $remoteDomain = 'https://' . $remoteDomain; |
|
310 | + } |
|
311 | + |
|
312 | + $result = [ |
|
313 | + 'success' => false, |
|
314 | + 'result' => '', |
|
315 | + ]; |
|
316 | + |
|
317 | + // if possible we use the new OCM API |
|
318 | + $ocmResult = $this->tryOCMEndPoint($remoteDomain, $fields, $action); |
|
319 | + if (is_array($ocmResult)) { |
|
320 | + $result['success'] = true; |
|
321 | + $result['result'] = json_encode([ |
|
322 | + 'ocs' => ['meta' => ['statuscode' => 200]]]); |
|
323 | + return $result; |
|
324 | + } |
|
325 | + |
|
326 | + return $this->tryLegacyEndPoint($remoteDomain, $urlSuffix, $fields); |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * try old federated sharing API if the OCM api doesn't work |
|
331 | + * |
|
332 | + * @param $remoteDomain |
|
333 | + * @param $urlSuffix |
|
334 | + * @param array $fields |
|
335 | + * @return mixed |
|
336 | + * @throws \Exception |
|
337 | + */ |
|
338 | + protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) { |
|
339 | + $result = [ |
|
340 | + 'success' => false, |
|
341 | + 'result' => '', |
|
342 | + ]; |
|
343 | + |
|
344 | + // Fall back to old API |
|
345 | + $client = $this->httpClientService->newClient(); |
|
346 | + $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
347 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
348 | + try { |
|
349 | + $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
350 | + 'body' => $fields, |
|
351 | + 'timeout' => 10, |
|
352 | + 'connect_timeout' => 10, |
|
353 | + ]); |
|
354 | + $result['result'] = $response->getBody(); |
|
355 | + $result['success'] = true; |
|
356 | + } catch (\Exception $e) { |
|
357 | + // if flat re-sharing is not supported by the remote server |
|
358 | + // we re-throw the exception and fall back to the old behaviour. |
|
359 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
360 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
361 | + throw $e; |
|
362 | + } |
|
363 | + } |
|
364 | + |
|
365 | + return $result; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * send action regarding federated sharing to the remote server using the OCM API |
|
370 | + * |
|
371 | + * @param $remoteDomain |
|
372 | + * @param $fields |
|
373 | + * @param $action |
|
374 | + * |
|
375 | + * @return bool |
|
376 | + */ |
|
377 | + protected function tryOCMEndPoint($remoteDomain, $fields, $action) { |
|
378 | + switch ($action) { |
|
379 | + case 'share': |
|
380 | + $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
381 | + $fields['shareWith'] . '@' . $remoteDomain, |
|
382 | + $fields['name'], |
|
383 | + '', |
|
384 | + $fields['remoteId'], |
|
385 | + $fields['ownerFederatedId'], |
|
386 | + $fields['owner'], |
|
387 | + $fields['sharedByFederatedId'], |
|
388 | + $fields['sharedBy'], |
|
389 | + $fields['token'], |
|
390 | + $fields['shareType'], |
|
391 | + 'file' |
|
392 | + ); |
|
393 | + return $this->federationProviderManager->sendShare($share); |
|
394 | + case 'reshare': |
|
395 | + // ask owner to reshare a file |
|
396 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
397 | + $notification->setMessage('REQUEST_RESHARE', |
|
398 | + 'file', |
|
399 | + $fields['remoteId'], |
|
400 | + [ |
|
401 | + 'sharedSecret' => $fields['token'], |
|
402 | + 'shareWith' => $fields['shareWith'], |
|
403 | + 'senderId' => $fields['localId'], |
|
404 | + 'shareType' => $fields['shareType'], |
|
405 | + 'message' => 'Ask owner to reshare the file' |
|
406 | + ] |
|
407 | + ); |
|
408 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
409 | + case 'unshare': |
|
410 | + //owner unshares the file from the recipient again |
|
411 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
412 | + $notification->setMessage('SHARE_UNSHARED', |
|
413 | + 'file', |
|
414 | + $fields['remoteId'], |
|
415 | + [ |
|
416 | + 'sharedSecret' => $fields['token'], |
|
417 | + 'messgage' => 'file is no longer shared with you' |
|
418 | + ] |
|
419 | + ); |
|
420 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
421 | + case 'reshare_undo': |
|
422 | + // if a reshare was unshared we send the information to the initiator/owner |
|
423 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
424 | + $notification->setMessage('RESHARE_UNDO', |
|
425 | + 'file', |
|
426 | + $fields['remoteId'], |
|
427 | + [ |
|
428 | + 'sharedSecret' => $fields['token'], |
|
429 | + 'message' => 'reshare was revoked' |
|
430 | + ] |
|
431 | + ); |
|
432 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
433 | + } |
|
434 | + |
|
435 | + return false; |
|
436 | + } |
|
437 | 437 | } |
@@ -38,75 +38,75 @@ |
||
38 | 38 | use OCP\Settings\ISettings; |
39 | 39 | |
40 | 40 | class Admin implements ISettings { |
41 | - /** @var IConfig */ |
|
42 | - private $config; |
|
43 | - /** @var IL10N */ |
|
44 | - private $l; |
|
45 | - /** @var ThemingDefaults */ |
|
46 | - private $themingDefaults; |
|
47 | - /** @var IURLGenerator */ |
|
48 | - private $urlGenerator; |
|
49 | - /** @var ImageManager */ |
|
50 | - private $imageManager; |
|
41 | + /** @var IConfig */ |
|
42 | + private $config; |
|
43 | + /** @var IL10N */ |
|
44 | + private $l; |
|
45 | + /** @var ThemingDefaults */ |
|
46 | + private $themingDefaults; |
|
47 | + /** @var IURLGenerator */ |
|
48 | + private $urlGenerator; |
|
49 | + /** @var ImageManager */ |
|
50 | + private $imageManager; |
|
51 | 51 | |
52 | - public function __construct(IConfig $config, |
|
53 | - IL10N $l, |
|
54 | - ThemingDefaults $themingDefaults, |
|
55 | - IURLGenerator $urlGenerator, |
|
56 | - ImageManager $imageManager) { |
|
57 | - $this->config = $config; |
|
58 | - $this->l = $l; |
|
59 | - $this->themingDefaults = $themingDefaults; |
|
60 | - $this->urlGenerator = $urlGenerator; |
|
61 | - $this->imageManager = $imageManager; |
|
62 | - } |
|
52 | + public function __construct(IConfig $config, |
|
53 | + IL10N $l, |
|
54 | + ThemingDefaults $themingDefaults, |
|
55 | + IURLGenerator $urlGenerator, |
|
56 | + ImageManager $imageManager) { |
|
57 | + $this->config = $config; |
|
58 | + $this->l = $l; |
|
59 | + $this->themingDefaults = $themingDefaults; |
|
60 | + $this->urlGenerator = $urlGenerator; |
|
61 | + $this->imageManager = $imageManager; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return TemplateResponse |
|
66 | - */ |
|
67 | - public function getForm(): TemplateResponse { |
|
68 | - $themable = true; |
|
69 | - $errorMessage = ''; |
|
70 | - $theme = $this->config->getSystemValue('theme', ''); |
|
71 | - if ($theme !== '') { |
|
72 | - $themable = false; |
|
73 | - $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.'); |
|
74 | - } |
|
64 | + /** |
|
65 | + * @return TemplateResponse |
|
66 | + */ |
|
67 | + public function getForm(): TemplateResponse { |
|
68 | + $themable = true; |
|
69 | + $errorMessage = ''; |
|
70 | + $theme = $this->config->getSystemValue('theme', ''); |
|
71 | + if ($theme !== '') { |
|
72 | + $themable = false; |
|
73 | + $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.'); |
|
74 | + } |
|
75 | 75 | |
76 | - $parameters = [ |
|
77 | - 'themable' => $themable, |
|
78 | - 'errorMessage' => $errorMessage, |
|
79 | - 'name' => $this->themingDefaults->getEntity(), |
|
80 | - 'url' => $this->themingDefaults->getBaseUrl(), |
|
81 | - 'slogan' => $this->themingDefaults->getSlogan(), |
|
82 | - 'color' => $this->themingDefaults->getColorPrimary(), |
|
83 | - 'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'), |
|
84 | - 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(), |
|
85 | - 'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'), |
|
86 | - 'images' => $this->imageManager->getCustomImages(), |
|
87 | - 'imprintUrl' => $this->themingDefaults->getImprintUrl(), |
|
88 | - 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), |
|
89 | - ]; |
|
76 | + $parameters = [ |
|
77 | + 'themable' => $themable, |
|
78 | + 'errorMessage' => $errorMessage, |
|
79 | + 'name' => $this->themingDefaults->getEntity(), |
|
80 | + 'url' => $this->themingDefaults->getBaseUrl(), |
|
81 | + 'slogan' => $this->themingDefaults->getSlogan(), |
|
82 | + 'color' => $this->themingDefaults->getColorPrimary(), |
|
83 | + 'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'), |
|
84 | + 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(), |
|
85 | + 'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'), |
|
86 | + 'images' => $this->imageManager->getCustomImages(), |
|
87 | + 'imprintUrl' => $this->themingDefaults->getImprintUrl(), |
|
88 | + 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), |
|
89 | + ]; |
|
90 | 90 | |
91 | - return new TemplateResponse('theming', 'settings-admin', $parameters, ''); |
|
92 | - } |
|
91 | + return new TemplateResponse('theming', 'settings-admin', $parameters, ''); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return string the section ID, e.g. 'sharing' |
|
96 | - */ |
|
97 | - public function getSection(): string { |
|
98 | - return 'theming'; |
|
99 | - } |
|
94 | + /** |
|
95 | + * @return string the section ID, e.g. 'sharing' |
|
96 | + */ |
|
97 | + public function getSection(): string { |
|
98 | + return 'theming'; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return int whether the form should be rather on the top or bottom of |
|
103 | - * the admin section. The forms are arranged in ascending order of the |
|
104 | - * priority values. It is required to return a value between 0 and 100. |
|
105 | - * |
|
106 | - * E.g.: 70 |
|
107 | - */ |
|
108 | - public function getPriority(): int { |
|
109 | - return 5; |
|
110 | - } |
|
101 | + /** |
|
102 | + * @return int whether the form should be rather on the top or bottom of |
|
103 | + * the admin section. The forms are arranged in ascending order of the |
|
104 | + * priority values. It is required to return a value between 0 and 100. |
|
105 | + * |
|
106 | + * E.g.: 70 |
|
107 | + */ |
|
108 | + public function getPriority(): int { |
|
109 | + return 5; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | } |
@@ -33,17 +33,17 @@ |
||
33 | 33 | * @since 14.0.0 |
34 | 34 | */ |
35 | 35 | interface ILogFactory { |
36 | - /** |
|
37 | - * @param string $type - one of: file, errorlog, syslog, systemd |
|
38 | - * @return IWriter |
|
39 | - * @since 14.0.0 |
|
40 | - */ |
|
41 | - public function get(string $type): IWriter; |
|
36 | + /** |
|
37 | + * @param string $type - one of: file, errorlog, syslog, systemd |
|
38 | + * @return IWriter |
|
39 | + * @since 14.0.0 |
|
40 | + */ |
|
41 | + public function get(string $type): IWriter; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $path |
|
45 | - * @return ILogger |
|
46 | - * @since 14.0.0 |
|
47 | - */ |
|
48 | - public function getCustomLogger(string $path): ILogger; |
|
43 | + /** |
|
44 | + * @param string $path |
|
45 | + * @return ILogger |
|
46 | + * @since 14.0.0 |
|
47 | + */ |
|
48 | + public function getCustomLogger(string $path): ILogger; |
|
49 | 49 | } |
@@ -35,31 +35,31 @@ |
||
35 | 35 | */ |
36 | 36 | class RSAPrivateKey extends AuthMechanism { |
37 | 37 | |
38 | - /** @var IConfig */ |
|
39 | - private $config; |
|
38 | + /** @var IConfig */ |
|
39 | + private $config; |
|
40 | 40 | |
41 | - public function __construct(IL10N $l, IConfig $config) { |
|
42 | - $this->config = $config; |
|
41 | + public function __construct(IL10N $l, IConfig $config) { |
|
42 | + $this->config = $config; |
|
43 | 43 | |
44 | - $this |
|
45 | - ->setIdentifier('publickey::rsa_private') |
|
46 | - ->setScheme(self::SCHEME_PUBLICKEY) |
|
47 | - ->setText($l->t('RSA private key')) |
|
48 | - ->addParameters([ |
|
49 | - new DefinitionParameter('user', $l->t('Username')), |
|
50 | - (new DefinitionParameter('password', $l->t('Password'))) |
|
51 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL) |
|
52 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
53 | - new DefinitionParameter('private_key', $l->t('Private key')), |
|
54 | - ]); |
|
55 | - } |
|
44 | + $this |
|
45 | + ->setIdentifier('publickey::rsa_private') |
|
46 | + ->setScheme(self::SCHEME_PUBLICKEY) |
|
47 | + ->setText($l->t('RSA private key')) |
|
48 | + ->addParameters([ |
|
49 | + new DefinitionParameter('user', $l->t('Username')), |
|
50 | + (new DefinitionParameter('password', $l->t('Password'))) |
|
51 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL) |
|
52 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
53 | + new DefinitionParameter('private_key', $l->t('Private key')), |
|
54 | + ]); |
|
55 | + } |
|
56 | 56 | |
57 | - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
58 | - $auth = new RSACrypt(); |
|
59 | - $auth->setPassword($this->config->getSystemValue('secret', '')); |
|
60 | - if (!$auth->loadKey($storage->getBackendOption('private_key'))) { |
|
61 | - throw new \RuntimeException('unable to load private key'); |
|
62 | - } |
|
63 | - $storage->setBackendOption('public_key_auth', $auth); |
|
64 | - } |
|
57 | + public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
58 | + $auth = new RSACrypt(); |
|
59 | + $auth->setPassword($this->config->getSystemValue('secret', '')); |
|
60 | + if (!$auth->loadKey($storage->getBackendOption('private_key'))) { |
|
61 | + throw new \RuntimeException('unable to load private key'); |
|
62 | + } |
|
63 | + $storage->setBackendOption('public_key_auth', $auth); |
|
64 | + } |
|
65 | 65 | } |
@@ -30,24 +30,24 @@ |
||
30 | 30 | */ |
31 | 31 | interface ICloudFederationNotification { |
32 | 32 | |
33 | - /** |
|
34 | - * add a message to the notification |
|
35 | - * |
|
36 | - * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
37 | - * @param string $resourceType (e.g. file, calendar, contact,...) |
|
38 | - * @param $providerId id of the share |
|
39 | - * @param array $notification , payload of the notification |
|
40 | - * |
|
41 | - * @since 14.0.0 |
|
42 | - */ |
|
43 | - public function setMessage($notificationType, $resourceType, $providerId, array $notification); |
|
33 | + /** |
|
34 | + * add a message to the notification |
|
35 | + * |
|
36 | + * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
37 | + * @param string $resourceType (e.g. file, calendar, contact,...) |
|
38 | + * @param $providerId id of the share |
|
39 | + * @param array $notification , payload of the notification |
|
40 | + * |
|
41 | + * @since 14.0.0 |
|
42 | + */ |
|
43 | + public function setMessage($notificationType, $resourceType, $providerId, array $notification); |
|
44 | 44 | |
45 | - /** |
|
46 | - * get message, ready to send out |
|
47 | - * |
|
48 | - * @return array |
|
49 | - * |
|
50 | - * @since 14.0.0 |
|
51 | - */ |
|
52 | - public function getMessage(); |
|
45 | + /** |
|
46 | + * get message, ready to send out |
|
47 | + * |
|
48 | + * @return array |
|
49 | + * |
|
50 | + * @since 14.0.0 |
|
51 | + */ |
|
52 | + public function getMessage(); |
|
53 | 53 | } |