@@ -44,69 +44,69 @@ |
||
| 44 | 44 | abstract class Middleware { |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * This is being run in normal order before the controller is being |
|
| 49 | - * called which allows several modifications and checks |
|
| 50 | - * |
|
| 51 | - * @param Controller $controller the controller that is being called |
|
| 52 | - * @param string $methodName the name of the method that will be called on |
|
| 53 | - * the controller |
|
| 54 | - * @since 6.0.0 |
|
| 55 | - */ |
|
| 56 | - public function beforeController($controller, $methodName){ |
|
| 47 | + /** |
|
| 48 | + * This is being run in normal order before the controller is being |
|
| 49 | + * called which allows several modifications and checks |
|
| 50 | + * |
|
| 51 | + * @param Controller $controller the controller that is being called |
|
| 52 | + * @param string $methodName the name of the method that will be called on |
|
| 53 | + * the controller |
|
| 54 | + * @since 6.0.0 |
|
| 55 | + */ |
|
| 56 | + public function beforeController($controller, $methodName){ |
|
| 57 | 57 | |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * This is being run when either the beforeController method or the |
|
| 63 | - * controller method itself is throwing an exception. The middleware is |
|
| 64 | - * asked in reverse order to handle the exception and to return a response. |
|
| 65 | - * If the response is null, it is assumed that the exception could not be |
|
| 66 | - * handled and the error will be thrown again |
|
| 67 | - * |
|
| 68 | - * @param Controller $controller the controller that is being called |
|
| 69 | - * @param string $methodName the name of the method that will be called on |
|
| 70 | - * the controller |
|
| 71 | - * @param \Exception $exception the thrown exception |
|
| 72 | - * @throws \Exception the passed in exception if it can't handle it |
|
| 73 | - * @return Response a Response object in case that the exception was handled |
|
| 74 | - * @since 6.0.0 |
|
| 75 | - */ |
|
| 76 | - public function afterException($controller, $methodName, \Exception $exception){ |
|
| 77 | - throw $exception; |
|
| 78 | - } |
|
| 61 | + /** |
|
| 62 | + * This is being run when either the beforeController method or the |
|
| 63 | + * controller method itself is throwing an exception. The middleware is |
|
| 64 | + * asked in reverse order to handle the exception and to return a response. |
|
| 65 | + * If the response is null, it is assumed that the exception could not be |
|
| 66 | + * handled and the error will be thrown again |
|
| 67 | + * |
|
| 68 | + * @param Controller $controller the controller that is being called |
|
| 69 | + * @param string $methodName the name of the method that will be called on |
|
| 70 | + * the controller |
|
| 71 | + * @param \Exception $exception the thrown exception |
|
| 72 | + * @throws \Exception the passed in exception if it can't handle it |
|
| 73 | + * @return Response a Response object in case that the exception was handled |
|
| 74 | + * @since 6.0.0 |
|
| 75 | + */ |
|
| 76 | + public function afterException($controller, $methodName, \Exception $exception){ |
|
| 77 | + throw $exception; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * This is being run after a successful controllermethod call and allows |
|
| 83 | - * the manipulation of a Response object. The middleware is run in reverse order |
|
| 84 | - * |
|
| 85 | - * @param Controller $controller the controller that is being called |
|
| 86 | - * @param string $methodName the name of the method that will be called on |
|
| 87 | - * the controller |
|
| 88 | - * @param Response $response the generated response from the controller |
|
| 89 | - * @return Response a Response object |
|
| 90 | - * @since 6.0.0 |
|
| 91 | - */ |
|
| 92 | - public function afterController($controller, $methodName, Response $response){ |
|
| 93 | - return $response; |
|
| 94 | - } |
|
| 81 | + /** |
|
| 82 | + * This is being run after a successful controllermethod call and allows |
|
| 83 | + * the manipulation of a Response object. The middleware is run in reverse order |
|
| 84 | + * |
|
| 85 | + * @param Controller $controller the controller that is being called |
|
| 86 | + * @param string $methodName the name of the method that will be called on |
|
| 87 | + * the controller |
|
| 88 | + * @param Response $response the generated response from the controller |
|
| 89 | + * @return Response a Response object |
|
| 90 | + * @since 6.0.0 |
|
| 91 | + */ |
|
| 92 | + public function afterController($controller, $methodName, Response $response){ |
|
| 93 | + return $response; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * This is being run after the response object has been rendered and |
|
| 99 | - * allows the manipulation of the output. The middleware is run in reverse order |
|
| 100 | - * |
|
| 101 | - * @param Controller $controller the controller that is being called |
|
| 102 | - * @param string $methodName the name of the method that will be called on |
|
| 103 | - * the controller |
|
| 104 | - * @param string $output the generated output from a response |
|
| 105 | - * @return string the output that should be printed |
|
| 106 | - * @since 6.0.0 |
|
| 107 | - */ |
|
| 108 | - public function beforeOutput($controller, $methodName, $output){ |
|
| 109 | - return $output; |
|
| 110 | - } |
|
| 97 | + /** |
|
| 98 | + * This is being run after the response object has been rendered and |
|
| 99 | + * allows the manipulation of the output. The middleware is run in reverse order |
|
| 100 | + * |
|
| 101 | + * @param Controller $controller the controller that is being called |
|
| 102 | + * @param string $methodName the name of the method that will be called on |
|
| 103 | + * the controller |
|
| 104 | + * @param string $output the generated output from a response |
|
| 105 | + * @return string the output that should be printed |
|
| 106 | + * @since 6.0.0 |
|
| 107 | + */ |
|
| 108 | + public function beforeOutput($controller, $methodName, $output){ |
|
| 109 | + return $output; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | } |
@@ -45,116 +45,116 @@ |
||
| 45 | 45 | * https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS |
| 46 | 46 | */ |
| 47 | 47 | class CORSMiddleware extends Middleware { |
| 48 | - /** @var IRequest */ |
|
| 49 | - private $request; |
|
| 50 | - /** @var ControllerMethodReflector */ |
|
| 51 | - private $reflector; |
|
| 52 | - /** @var Session */ |
|
| 53 | - private $session; |
|
| 54 | - /** @var Throttler */ |
|
| 55 | - private $throttler; |
|
| 48 | + /** @var IRequest */ |
|
| 49 | + private $request; |
|
| 50 | + /** @var ControllerMethodReflector */ |
|
| 51 | + private $reflector; |
|
| 52 | + /** @var Session */ |
|
| 53 | + private $session; |
|
| 54 | + /** @var Throttler */ |
|
| 55 | + private $throttler; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param IRequest $request |
|
| 59 | - * @param ControllerMethodReflector $reflector |
|
| 60 | - * @param Session $session |
|
| 61 | - * @param Throttler $throttler |
|
| 62 | - */ |
|
| 63 | - public function __construct(IRequest $request, |
|
| 64 | - ControllerMethodReflector $reflector, |
|
| 65 | - Session $session, |
|
| 66 | - Throttler $throttler) { |
|
| 67 | - $this->request = $request; |
|
| 68 | - $this->reflector = $reflector; |
|
| 69 | - $this->session = $session; |
|
| 70 | - $this->throttler = $throttler; |
|
| 71 | - } |
|
| 57 | + /** |
|
| 58 | + * @param IRequest $request |
|
| 59 | + * @param ControllerMethodReflector $reflector |
|
| 60 | + * @param Session $session |
|
| 61 | + * @param Throttler $throttler |
|
| 62 | + */ |
|
| 63 | + public function __construct(IRequest $request, |
|
| 64 | + ControllerMethodReflector $reflector, |
|
| 65 | + Session $session, |
|
| 66 | + Throttler $throttler) { |
|
| 67 | + $this->request = $request; |
|
| 68 | + $this->reflector = $reflector; |
|
| 69 | + $this->session = $session; |
|
| 70 | + $this->throttler = $throttler; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * This is being run in normal order before the controller is being |
|
| 75 | - * called which allows several modifications and checks |
|
| 76 | - * |
|
| 77 | - * @param Controller $controller the controller that is being called |
|
| 78 | - * @param string $methodName the name of the method that will be called on |
|
| 79 | - * the controller |
|
| 80 | - * @throws SecurityException |
|
| 81 | - * @since 6.0.0 |
|
| 82 | - */ |
|
| 83 | - public function beforeController($controller, $methodName){ |
|
| 84 | - // ensure that @CORS annotated API routes are not used in conjunction |
|
| 85 | - // with session authentication since this enables CSRF attack vectors |
|
| 86 | - if ($this->reflector->hasAnnotation('CORS') && |
|
| 87 | - !$this->reflector->hasAnnotation('PublicPage')) { |
|
| 88 | - $user = $this->request->server['PHP_AUTH_USER']; |
|
| 89 | - $pass = $this->request->server['PHP_AUTH_PW']; |
|
| 73 | + /** |
|
| 74 | + * This is being run in normal order before the controller is being |
|
| 75 | + * called which allows several modifications and checks |
|
| 76 | + * |
|
| 77 | + * @param Controller $controller the controller that is being called |
|
| 78 | + * @param string $methodName the name of the method that will be called on |
|
| 79 | + * the controller |
|
| 80 | + * @throws SecurityException |
|
| 81 | + * @since 6.0.0 |
|
| 82 | + */ |
|
| 83 | + public function beforeController($controller, $methodName){ |
|
| 84 | + // ensure that @CORS annotated API routes are not used in conjunction |
|
| 85 | + // with session authentication since this enables CSRF attack vectors |
|
| 86 | + if ($this->reflector->hasAnnotation('CORS') && |
|
| 87 | + !$this->reflector->hasAnnotation('PublicPage')) { |
|
| 88 | + $user = $this->request->server['PHP_AUTH_USER']; |
|
| 89 | + $pass = $this->request->server['PHP_AUTH_PW']; |
|
| 90 | 90 | |
| 91 | - $this->session->logout(); |
|
| 92 | - try { |
|
| 93 | - if (!$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) { |
|
| 94 | - throw new SecurityException('CORS requires basic auth', Http::STATUS_UNAUTHORIZED); |
|
| 95 | - } |
|
| 96 | - } catch (PasswordLoginForbiddenException $ex) { |
|
| 97 | - throw new SecurityException('Password login forbidden, use token instead', Http::STATUS_UNAUTHORIZED); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 91 | + $this->session->logout(); |
|
| 92 | + try { |
|
| 93 | + if (!$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) { |
|
| 94 | + throw new SecurityException('CORS requires basic auth', Http::STATUS_UNAUTHORIZED); |
|
| 95 | + } |
|
| 96 | + } catch (PasswordLoginForbiddenException $ex) { |
|
| 97 | + throw new SecurityException('Password login forbidden, use token instead', Http::STATUS_UNAUTHORIZED); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * This is being run after a successful controllermethod call and allows |
|
| 104 | - * the manipulation of a Response object. The middleware is run in reverse order |
|
| 105 | - * |
|
| 106 | - * @param Controller $controller the controller that is being called |
|
| 107 | - * @param string $methodName the name of the method that will be called on |
|
| 108 | - * the controller |
|
| 109 | - * @param Response $response the generated response from the controller |
|
| 110 | - * @return Response a Response object |
|
| 111 | - * @throws SecurityException |
|
| 112 | - */ |
|
| 113 | - public function afterController($controller, $methodName, Response $response){ |
|
| 114 | - // only react if its a CORS request and if the request sends origin and |
|
| 102 | + /** |
|
| 103 | + * This is being run after a successful controllermethod call and allows |
|
| 104 | + * the manipulation of a Response object. The middleware is run in reverse order |
|
| 105 | + * |
|
| 106 | + * @param Controller $controller the controller that is being called |
|
| 107 | + * @param string $methodName the name of the method that will be called on |
|
| 108 | + * the controller |
|
| 109 | + * @param Response $response the generated response from the controller |
|
| 110 | + * @return Response a Response object |
|
| 111 | + * @throws SecurityException |
|
| 112 | + */ |
|
| 113 | + public function afterController($controller, $methodName, Response $response){ |
|
| 114 | + // only react if its a CORS request and if the request sends origin and |
|
| 115 | 115 | |
| 116 | - if(isset($this->request->server['HTTP_ORIGIN']) && |
|
| 117 | - $this->reflector->hasAnnotation('CORS')) { |
|
| 116 | + if(isset($this->request->server['HTTP_ORIGIN']) && |
|
| 117 | + $this->reflector->hasAnnotation('CORS')) { |
|
| 118 | 118 | |
| 119 | - // allow credentials headers must not be true or CSRF is possible |
|
| 120 | - // otherwise |
|
| 121 | - foreach($response->getHeaders() as $header => $value) { |
|
| 122 | - if(strtolower($header) === 'access-control-allow-credentials' && |
|
| 123 | - strtolower(trim($value)) === 'true') { |
|
| 124 | - $msg = 'Access-Control-Allow-Credentials must not be '. |
|
| 125 | - 'set to true in order to prevent CSRF'; |
|
| 126 | - throw new SecurityException($msg); |
|
| 127 | - } |
|
| 128 | - } |
|
| 119 | + // allow credentials headers must not be true or CSRF is possible |
|
| 120 | + // otherwise |
|
| 121 | + foreach($response->getHeaders() as $header => $value) { |
|
| 122 | + if(strtolower($header) === 'access-control-allow-credentials' && |
|
| 123 | + strtolower(trim($value)) === 'true') { |
|
| 124 | + $msg = 'Access-Control-Allow-Credentials must not be '. |
|
| 125 | + 'set to true in order to prevent CSRF'; |
|
| 126 | + throw new SecurityException($msg); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - $origin = $this->request->server['HTTP_ORIGIN']; |
|
| 131 | - $response->addHeader('Access-Control-Allow-Origin', $origin); |
|
| 132 | - } |
|
| 133 | - return $response; |
|
| 134 | - } |
|
| 130 | + $origin = $this->request->server['HTTP_ORIGIN']; |
|
| 131 | + $response->addHeader('Access-Control-Allow-Origin', $origin); |
|
| 132 | + } |
|
| 133 | + return $response; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * If an SecurityException is being caught return a JSON error response |
|
| 138 | - * |
|
| 139 | - * @param Controller $controller the controller that is being called |
|
| 140 | - * @param string $methodName the name of the method that will be called on |
|
| 141 | - * the controller |
|
| 142 | - * @param \Exception $exception the thrown exception |
|
| 143 | - * @throws \Exception the passed in exception if it can't handle it |
|
| 144 | - * @return Response a Response object or null in case that the exception could not be handled |
|
| 145 | - */ |
|
| 146 | - public function afterException($controller, $methodName, \Exception $exception){ |
|
| 147 | - if($exception instanceof SecurityException){ |
|
| 148 | - $response = new JSONResponse(['message' => $exception->getMessage()]); |
|
| 149 | - if($exception->getCode() !== 0) { |
|
| 150 | - $response->setStatus($exception->getCode()); |
|
| 151 | - } else { |
|
| 152 | - $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 153 | - } |
|
| 154 | - return $response; |
|
| 155 | - } |
|
| 136 | + /** |
|
| 137 | + * If an SecurityException is being caught return a JSON error response |
|
| 138 | + * |
|
| 139 | + * @param Controller $controller the controller that is being called |
|
| 140 | + * @param string $methodName the name of the method that will be called on |
|
| 141 | + * the controller |
|
| 142 | + * @param \Exception $exception the thrown exception |
|
| 143 | + * @throws \Exception the passed in exception if it can't handle it |
|
| 144 | + * @return Response a Response object or null in case that the exception could not be handled |
|
| 145 | + */ |
|
| 146 | + public function afterException($controller, $methodName, \Exception $exception){ |
|
| 147 | + if($exception instanceof SecurityException){ |
|
| 148 | + $response = new JSONResponse(['message' => $exception->getMessage()]); |
|
| 149 | + if($exception->getCode() !== 0) { |
|
| 150 | + $response->setStatus($exception->getCode()); |
|
| 151 | + } else { |
|
| 152 | + $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); |
|
| 153 | + } |
|
| 154 | + return $response; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - throw $exception; |
|
| 158 | - } |
|
| 157 | + throw $exception; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | 160 | } |
@@ -48,87 +48,87 @@ |
||
| 48 | 48 | * @package OC\AppFramework\Middleware\Security |
| 49 | 49 | */ |
| 50 | 50 | class RateLimitingMiddleware extends Middleware { |
| 51 | - /** @var IRequest $request */ |
|
| 52 | - private $request; |
|
| 53 | - /** @var IUserSession */ |
|
| 54 | - private $userSession; |
|
| 55 | - /** @var ControllerMethodReflector */ |
|
| 56 | - private $reflector; |
|
| 57 | - /** @var Limiter */ |
|
| 58 | - private $limiter; |
|
| 51 | + /** @var IRequest $request */ |
|
| 52 | + private $request; |
|
| 53 | + /** @var IUserSession */ |
|
| 54 | + private $userSession; |
|
| 55 | + /** @var ControllerMethodReflector */ |
|
| 56 | + private $reflector; |
|
| 57 | + /** @var Limiter */ |
|
| 58 | + private $limiter; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param IRequest $request |
|
| 62 | - * @param IUserSession $userSession |
|
| 63 | - * @param ControllerMethodReflector $reflector |
|
| 64 | - * @param Limiter $limiter |
|
| 65 | - */ |
|
| 66 | - public function __construct(IRequest $request, |
|
| 67 | - IUserSession $userSession, |
|
| 68 | - ControllerMethodReflector $reflector, |
|
| 69 | - Limiter $limiter) { |
|
| 70 | - $this->request = $request; |
|
| 71 | - $this->userSession = $userSession; |
|
| 72 | - $this->reflector = $reflector; |
|
| 73 | - $this->limiter = $limiter; |
|
| 74 | - } |
|
| 60 | + /** |
|
| 61 | + * @param IRequest $request |
|
| 62 | + * @param IUserSession $userSession |
|
| 63 | + * @param ControllerMethodReflector $reflector |
|
| 64 | + * @param Limiter $limiter |
|
| 65 | + */ |
|
| 66 | + public function __construct(IRequest $request, |
|
| 67 | + IUserSession $userSession, |
|
| 68 | + ControllerMethodReflector $reflector, |
|
| 69 | + Limiter $limiter) { |
|
| 70 | + $this->request = $request; |
|
| 71 | + $this->userSession = $userSession; |
|
| 72 | + $this->reflector = $reflector; |
|
| 73 | + $this->limiter = $limiter; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * {@inheritDoc} |
|
| 78 | - * @throws RateLimitExceededException |
|
| 79 | - */ |
|
| 80 | - public function beforeController($controller, $methodName) { |
|
| 81 | - parent::beforeController($controller, $methodName); |
|
| 76 | + /** |
|
| 77 | + * {@inheritDoc} |
|
| 78 | + * @throws RateLimitExceededException |
|
| 79 | + */ |
|
| 80 | + public function beforeController($controller, $methodName) { |
|
| 81 | + parent::beforeController($controller, $methodName); |
|
| 82 | 82 | |
| 83 | - $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); |
|
| 84 | - $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
|
| 85 | - $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
|
| 86 | - $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
|
| 87 | - $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
| 88 | - if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
| 89 | - $this->limiter->registerUserRequest( |
|
| 90 | - $rateLimitIdentifier, |
|
| 91 | - $userLimit, |
|
| 92 | - $userPeriod, |
|
| 93 | - $this->userSession->getUser() |
|
| 94 | - ); |
|
| 95 | - } elseif ($anonLimit !== '' && $anonPeriod !== '') { |
|
| 96 | - $this->limiter->registerAnonRequest( |
|
| 97 | - $rateLimitIdentifier, |
|
| 98 | - $anonLimit, |
|
| 99 | - $anonPeriod, |
|
| 100 | - $this->request->getRemoteAddress() |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - } |
|
| 83 | + $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); |
|
| 84 | + $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
|
| 85 | + $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
|
| 86 | + $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
|
| 87 | + $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
| 88 | + if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
| 89 | + $this->limiter->registerUserRequest( |
|
| 90 | + $rateLimitIdentifier, |
|
| 91 | + $userLimit, |
|
| 92 | + $userPeriod, |
|
| 93 | + $this->userSession->getUser() |
|
| 94 | + ); |
|
| 95 | + } elseif ($anonLimit !== '' && $anonPeriod !== '') { |
|
| 96 | + $this->limiter->registerAnonRequest( |
|
| 97 | + $rateLimitIdentifier, |
|
| 98 | + $anonLimit, |
|
| 99 | + $anonPeriod, |
|
| 100 | + $this->request->getRemoteAddress() |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * {@inheritDoc} |
|
| 107 | - */ |
|
| 108 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 109 | - if($exception instanceof RateLimitExceededException) { |
|
| 110 | - if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 111 | - $response = new JSONResponse( |
|
| 112 | - [ |
|
| 113 | - 'message' => $exception->getMessage(), |
|
| 114 | - ], |
|
| 115 | - $exception->getCode() |
|
| 116 | - ); |
|
| 117 | - } else { |
|
| 118 | - $response = new TemplateResponse( |
|
| 119 | - 'core', |
|
| 120 | - '403', |
|
| 121 | - [ |
|
| 122 | - 'file' => $exception->getMessage() |
|
| 123 | - ], |
|
| 124 | - 'guest' |
|
| 125 | - ); |
|
| 126 | - $response->setStatus($exception->getCode()); |
|
| 127 | - } |
|
| 105 | + /** |
|
| 106 | + * {@inheritDoc} |
|
| 107 | + */ |
|
| 108 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 109 | + if($exception instanceof RateLimitExceededException) { |
|
| 110 | + if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 111 | + $response = new JSONResponse( |
|
| 112 | + [ |
|
| 113 | + 'message' => $exception->getMessage(), |
|
| 114 | + ], |
|
| 115 | + $exception->getCode() |
|
| 116 | + ); |
|
| 117 | + } else { |
|
| 118 | + $response = new TemplateResponse( |
|
| 119 | + 'core', |
|
| 120 | + '403', |
|
| 121 | + [ |
|
| 122 | + 'file' => $exception->getMessage() |
|
| 123 | + ], |
|
| 124 | + 'guest' |
|
| 125 | + ); |
|
| 126 | + $response->setStatus($exception->getCode()); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - return $response; |
|
| 130 | - } |
|
| 129 | + return $response; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - throw $exception; |
|
| 133 | - } |
|
| 132 | + throw $exception; |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -63,206 +63,206 @@ |
||
| 63 | 63 | * check fails |
| 64 | 64 | */ |
| 65 | 65 | class SecurityMiddleware extends Middleware { |
| 66 | - /** @var INavigationManager */ |
|
| 67 | - private $navigationManager; |
|
| 68 | - /** @var IRequest */ |
|
| 69 | - private $request; |
|
| 70 | - /** @var ControllerMethodReflector */ |
|
| 71 | - private $reflector; |
|
| 72 | - /** @var string */ |
|
| 73 | - private $appName; |
|
| 74 | - /** @var IURLGenerator */ |
|
| 75 | - private $urlGenerator; |
|
| 76 | - /** @var ILogger */ |
|
| 77 | - private $logger; |
|
| 78 | - /** @var ISession */ |
|
| 79 | - private $session; |
|
| 80 | - /** @var bool */ |
|
| 81 | - private $isLoggedIn; |
|
| 82 | - /** @var bool */ |
|
| 83 | - private $isAdminUser; |
|
| 84 | - /** @var ContentSecurityPolicyManager */ |
|
| 85 | - private $contentSecurityPolicyManager; |
|
| 86 | - /** @var CsrfTokenManager */ |
|
| 87 | - private $csrfTokenManager; |
|
| 88 | - /** @var ContentSecurityPolicyNonceManager */ |
|
| 89 | - private $cspNonceManager; |
|
| 66 | + /** @var INavigationManager */ |
|
| 67 | + private $navigationManager; |
|
| 68 | + /** @var IRequest */ |
|
| 69 | + private $request; |
|
| 70 | + /** @var ControllerMethodReflector */ |
|
| 71 | + private $reflector; |
|
| 72 | + /** @var string */ |
|
| 73 | + private $appName; |
|
| 74 | + /** @var IURLGenerator */ |
|
| 75 | + private $urlGenerator; |
|
| 76 | + /** @var ILogger */ |
|
| 77 | + private $logger; |
|
| 78 | + /** @var ISession */ |
|
| 79 | + private $session; |
|
| 80 | + /** @var bool */ |
|
| 81 | + private $isLoggedIn; |
|
| 82 | + /** @var bool */ |
|
| 83 | + private $isAdminUser; |
|
| 84 | + /** @var ContentSecurityPolicyManager */ |
|
| 85 | + private $contentSecurityPolicyManager; |
|
| 86 | + /** @var CsrfTokenManager */ |
|
| 87 | + private $csrfTokenManager; |
|
| 88 | + /** @var ContentSecurityPolicyNonceManager */ |
|
| 89 | + private $cspNonceManager; |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @param IRequest $request |
|
| 93 | - * @param ControllerMethodReflector $reflector |
|
| 94 | - * @param INavigationManager $navigationManager |
|
| 95 | - * @param IURLGenerator $urlGenerator |
|
| 96 | - * @param ILogger $logger |
|
| 97 | - * @param ISession $session |
|
| 98 | - * @param string $appName |
|
| 99 | - * @param bool $isLoggedIn |
|
| 100 | - * @param bool $isAdminUser |
|
| 101 | - * @param ContentSecurityPolicyManager $contentSecurityPolicyManager |
|
| 102 | - * @param CSRFTokenManager $csrfTokenManager |
|
| 103 | - * @param ContentSecurityPolicyNonceManager $cspNonceManager |
|
| 104 | - */ |
|
| 105 | - public function __construct(IRequest $request, |
|
| 106 | - ControllerMethodReflector $reflector, |
|
| 107 | - INavigationManager $navigationManager, |
|
| 108 | - IURLGenerator $urlGenerator, |
|
| 109 | - ILogger $logger, |
|
| 110 | - ISession $session, |
|
| 111 | - $appName, |
|
| 112 | - $isLoggedIn, |
|
| 113 | - $isAdminUser, |
|
| 114 | - ContentSecurityPolicyManager $contentSecurityPolicyManager, |
|
| 115 | - CsrfTokenManager $csrfTokenManager, |
|
| 116 | - ContentSecurityPolicyNonceManager $cspNonceManager) { |
|
| 117 | - $this->navigationManager = $navigationManager; |
|
| 118 | - $this->request = $request; |
|
| 119 | - $this->reflector = $reflector; |
|
| 120 | - $this->appName = $appName; |
|
| 121 | - $this->urlGenerator = $urlGenerator; |
|
| 122 | - $this->logger = $logger; |
|
| 123 | - $this->session = $session; |
|
| 124 | - $this->isLoggedIn = $isLoggedIn; |
|
| 125 | - $this->isAdminUser = $isAdminUser; |
|
| 126 | - $this->contentSecurityPolicyManager = $contentSecurityPolicyManager; |
|
| 127 | - $this->csrfTokenManager = $csrfTokenManager; |
|
| 128 | - $this->cspNonceManager = $cspNonceManager; |
|
| 129 | - } |
|
| 91 | + /** |
|
| 92 | + * @param IRequest $request |
|
| 93 | + * @param ControllerMethodReflector $reflector |
|
| 94 | + * @param INavigationManager $navigationManager |
|
| 95 | + * @param IURLGenerator $urlGenerator |
|
| 96 | + * @param ILogger $logger |
|
| 97 | + * @param ISession $session |
|
| 98 | + * @param string $appName |
|
| 99 | + * @param bool $isLoggedIn |
|
| 100 | + * @param bool $isAdminUser |
|
| 101 | + * @param ContentSecurityPolicyManager $contentSecurityPolicyManager |
|
| 102 | + * @param CSRFTokenManager $csrfTokenManager |
|
| 103 | + * @param ContentSecurityPolicyNonceManager $cspNonceManager |
|
| 104 | + */ |
|
| 105 | + public function __construct(IRequest $request, |
|
| 106 | + ControllerMethodReflector $reflector, |
|
| 107 | + INavigationManager $navigationManager, |
|
| 108 | + IURLGenerator $urlGenerator, |
|
| 109 | + ILogger $logger, |
|
| 110 | + ISession $session, |
|
| 111 | + $appName, |
|
| 112 | + $isLoggedIn, |
|
| 113 | + $isAdminUser, |
|
| 114 | + ContentSecurityPolicyManager $contentSecurityPolicyManager, |
|
| 115 | + CsrfTokenManager $csrfTokenManager, |
|
| 116 | + ContentSecurityPolicyNonceManager $cspNonceManager) { |
|
| 117 | + $this->navigationManager = $navigationManager; |
|
| 118 | + $this->request = $request; |
|
| 119 | + $this->reflector = $reflector; |
|
| 120 | + $this->appName = $appName; |
|
| 121 | + $this->urlGenerator = $urlGenerator; |
|
| 122 | + $this->logger = $logger; |
|
| 123 | + $this->session = $session; |
|
| 124 | + $this->isLoggedIn = $isLoggedIn; |
|
| 125 | + $this->isAdminUser = $isAdminUser; |
|
| 126 | + $this->contentSecurityPolicyManager = $contentSecurityPolicyManager; |
|
| 127 | + $this->csrfTokenManager = $csrfTokenManager; |
|
| 128 | + $this->cspNonceManager = $cspNonceManager; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * This runs all the security checks before a method call. The |
|
| 133 | - * security checks are determined by inspecting the controller method |
|
| 134 | - * annotations |
|
| 135 | - * @param Controller $controller the controller |
|
| 136 | - * @param string $methodName the name of the method |
|
| 137 | - * @throws SecurityException when a security check fails |
|
| 138 | - */ |
|
| 139 | - public function beforeController($controller, $methodName) { |
|
| 131 | + /** |
|
| 132 | + * This runs all the security checks before a method call. The |
|
| 133 | + * security checks are determined by inspecting the controller method |
|
| 134 | + * annotations |
|
| 135 | + * @param Controller $controller the controller |
|
| 136 | + * @param string $methodName the name of the method |
|
| 137 | + * @throws SecurityException when a security check fails |
|
| 138 | + */ |
|
| 139 | + public function beforeController($controller, $methodName) { |
|
| 140 | 140 | |
| 141 | - // this will set the current navigation entry of the app, use this only |
|
| 142 | - // for normal HTML requests and not for AJAX requests |
|
| 143 | - $this->navigationManager->setActiveEntry($this->appName); |
|
| 141 | + // this will set the current navigation entry of the app, use this only |
|
| 142 | + // for normal HTML requests and not for AJAX requests |
|
| 143 | + $this->navigationManager->setActiveEntry($this->appName); |
|
| 144 | 144 | |
| 145 | - // security checks |
|
| 146 | - $isPublicPage = $this->reflector->hasAnnotation('PublicPage'); |
|
| 147 | - if(!$isPublicPage) { |
|
| 148 | - if(!$this->isLoggedIn) { |
|
| 149 | - throw new NotLoggedInException(); |
|
| 150 | - } |
|
| 145 | + // security checks |
|
| 146 | + $isPublicPage = $this->reflector->hasAnnotation('PublicPage'); |
|
| 147 | + if(!$isPublicPage) { |
|
| 148 | + if(!$this->isLoggedIn) { |
|
| 149 | + throw new NotLoggedInException(); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - if(!$this->reflector->hasAnnotation('NoAdminRequired')) { |
|
| 153 | - if(!$this->isAdminUser) { |
|
| 154 | - throw new NotAdminException(); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - } |
|
| 152 | + if(!$this->reflector->hasAnnotation('NoAdminRequired')) { |
|
| 153 | + if(!$this->isAdminUser) { |
|
| 154 | + throw new NotAdminException(); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) { |
|
| 160 | - $lastConfirm = (int) $this->session->get('last-password-confirm'); |
|
| 161 | - if ($lastConfirm < (time() - (30 * 60 + 15))) { // allow 15 seconds delay |
|
| 162 | - throw new NotConfirmedException(); |
|
| 163 | - } |
|
| 164 | - } |
|
| 159 | + if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) { |
|
| 160 | + $lastConfirm = (int) $this->session->get('last-password-confirm'); |
|
| 161 | + if ($lastConfirm < (time() - (30 * 60 + 15))) { // allow 15 seconds delay |
|
| 162 | + throw new NotConfirmedException(); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - // Check for strict cookie requirement |
|
| 167 | - if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) { |
|
| 168 | - if(!$this->request->passesStrictCookieCheck()) { |
|
| 169 | - throw new StrictCookieMissingException(); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - // CSRF check - also registers the CSRF token since the session may be closed later |
|
| 173 | - Util::callRegister(); |
|
| 174 | - if(!$this->reflector->hasAnnotation('NoCSRFRequired')) { |
|
| 175 | - /* |
|
| 166 | + // Check for strict cookie requirement |
|
| 167 | + if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) { |
|
| 168 | + if(!$this->request->passesStrictCookieCheck()) { |
|
| 169 | + throw new StrictCookieMissingException(); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + // CSRF check - also registers the CSRF token since the session may be closed later |
|
| 173 | + Util::callRegister(); |
|
| 174 | + if(!$this->reflector->hasAnnotation('NoCSRFRequired')) { |
|
| 175 | + /* |
|
| 176 | 176 | * Only allow the CSRF check to fail on OCS Requests. This kind of |
| 177 | 177 | * hacks around that we have no full token auth in place yet and we |
| 178 | 178 | * do want to offer CSRF checks for web requests. |
| 179 | 179 | */ |
| 180 | - if(!$this->request->passesCSRFCheck() && !( |
|
| 181 | - $controller instanceof OCSController && |
|
| 182 | - $this->request->getHeader('OCS-APIREQUEST') === 'true')) { |
|
| 183 | - throw new CrossSiteRequestForgeryException(); |
|
| 184 | - } |
|
| 185 | - } |
|
| 180 | + if(!$this->request->passesCSRFCheck() && !( |
|
| 181 | + $controller instanceof OCSController && |
|
| 182 | + $this->request->getHeader('OCS-APIREQUEST') === 'true')) { |
|
| 183 | + throw new CrossSiteRequestForgeryException(); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * FIXME: Use DI once available |
|
| 189 | - * Checks if app is enabled (also includes a check whether user is allowed to access the resource) |
|
| 190 | - * The getAppPath() check is here since components such as settings also use the AppFramework and |
|
| 191 | - * therefore won't pass this check. |
|
| 192 | - */ |
|
| 193 | - if(\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) { |
|
| 194 | - throw new AppNotEnabledException(); |
|
| 195 | - } |
|
| 187 | + /** |
|
| 188 | + * FIXME: Use DI once available |
|
| 189 | + * Checks if app is enabled (also includes a check whether user is allowed to access the resource) |
|
| 190 | + * The getAppPath() check is here since components such as settings also use the AppFramework and |
|
| 191 | + * therefore won't pass this check. |
|
| 192 | + */ |
|
| 193 | + if(\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) { |
|
| 194 | + throw new AppNotEnabledException(); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Performs the default CSP modifications that may be injected by other |
|
| 201 | - * applications |
|
| 202 | - * |
|
| 203 | - * @param Controller $controller |
|
| 204 | - * @param string $methodName |
|
| 205 | - * @param Response $response |
|
| 206 | - * @return Response |
|
| 207 | - */ |
|
| 208 | - public function afterController($controller, $methodName, Response $response) { |
|
| 209 | - $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy(); |
|
| 199 | + /** |
|
| 200 | + * Performs the default CSP modifications that may be injected by other |
|
| 201 | + * applications |
|
| 202 | + * |
|
| 203 | + * @param Controller $controller |
|
| 204 | + * @param string $methodName |
|
| 205 | + * @param Response $response |
|
| 206 | + * @return Response |
|
| 207 | + */ |
|
| 208 | + public function afterController($controller, $methodName, Response $response) { |
|
| 209 | + $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy(); |
|
| 210 | 210 | |
| 211 | - if (get_class($policy) === EmptyContentSecurityPolicy::class) { |
|
| 212 | - return $response; |
|
| 213 | - } |
|
| 211 | + if (get_class($policy) === EmptyContentSecurityPolicy::class) { |
|
| 212 | + return $response; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - $defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy(); |
|
| 216 | - $defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy); |
|
| 215 | + $defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy(); |
|
| 216 | + $defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy); |
|
| 217 | 217 | |
| 218 | - if($this->cspNonceManager->browserSupportsCspV3()) { |
|
| 219 | - $defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue()); |
|
| 220 | - } |
|
| 218 | + if($this->cspNonceManager->browserSupportsCspV3()) { |
|
| 219 | + $defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue()); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - $response->setContentSecurityPolicy($defaultPolicy); |
|
| 222 | + $response->setContentSecurityPolicy($defaultPolicy); |
|
| 223 | 223 | |
| 224 | - return $response; |
|
| 225 | - } |
|
| 224 | + return $response; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * If an SecurityException is being caught, ajax requests return a JSON error |
|
| 229 | - * response and non ajax requests redirect to the index |
|
| 230 | - * @param Controller $controller the controller that is being called |
|
| 231 | - * @param string $methodName the name of the method that will be called on |
|
| 232 | - * the controller |
|
| 233 | - * @param \Exception $exception the thrown exception |
|
| 234 | - * @throws \Exception the passed in exception if it can't handle it |
|
| 235 | - * @return Response a Response object or null in case that the exception could not be handled |
|
| 236 | - */ |
|
| 237 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 238 | - if($exception instanceof SecurityException) { |
|
| 239 | - if($exception instanceof StrictCookieMissingException) { |
|
| 240 | - return new RedirectResponse(\OC::$WEBROOT); |
|
| 241 | - } |
|
| 242 | - if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 243 | - $response = new JSONResponse( |
|
| 244 | - array('message' => $exception->getMessage()), |
|
| 245 | - $exception->getCode() |
|
| 246 | - ); |
|
| 247 | - } else { |
|
| 248 | - if($exception instanceof NotLoggedInException) { |
|
| 249 | - $params = []; |
|
| 250 | - if (isset($this->request->server['REQUEST_URI'])) { |
|
| 251 | - $params['redirect_url'] = $this->request->server['REQUEST_URI']; |
|
| 252 | - } |
|
| 253 | - $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params); |
|
| 254 | - $response = new RedirectResponse($url); |
|
| 255 | - } else { |
|
| 256 | - $response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest'); |
|
| 257 | - $response->setStatus($exception->getCode()); |
|
| 258 | - } |
|
| 259 | - } |
|
| 227 | + /** |
|
| 228 | + * If an SecurityException is being caught, ajax requests return a JSON error |
|
| 229 | + * response and non ajax requests redirect to the index |
|
| 230 | + * @param Controller $controller the controller that is being called |
|
| 231 | + * @param string $methodName the name of the method that will be called on |
|
| 232 | + * the controller |
|
| 233 | + * @param \Exception $exception the thrown exception |
|
| 234 | + * @throws \Exception the passed in exception if it can't handle it |
|
| 235 | + * @return Response a Response object or null in case that the exception could not be handled |
|
| 236 | + */ |
|
| 237 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 238 | + if($exception instanceof SecurityException) { |
|
| 239 | + if($exception instanceof StrictCookieMissingException) { |
|
| 240 | + return new RedirectResponse(\OC::$WEBROOT); |
|
| 241 | + } |
|
| 242 | + if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 243 | + $response = new JSONResponse( |
|
| 244 | + array('message' => $exception->getMessage()), |
|
| 245 | + $exception->getCode() |
|
| 246 | + ); |
|
| 247 | + } else { |
|
| 248 | + if($exception instanceof NotLoggedInException) { |
|
| 249 | + $params = []; |
|
| 250 | + if (isset($this->request->server['REQUEST_URI'])) { |
|
| 251 | + $params['redirect_url'] = $this->request->server['REQUEST_URI']; |
|
| 252 | + } |
|
| 253 | + $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params); |
|
| 254 | + $response = new RedirectResponse($url); |
|
| 255 | + } else { |
|
| 256 | + $response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest'); |
|
| 257 | + $response->setStatus($exception->getCode()); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - $this->logger->debug($exception->getMessage()); |
|
| 262 | - return $response; |
|
| 263 | - } |
|
| 261 | + $this->logger->debug($exception->getMessage()); |
|
| 262 | + return $response; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - throw $exception; |
|
| 266 | - } |
|
| 265 | + throw $exception; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | } |
@@ -35,49 +35,49 @@ |
||
| 35 | 35 | * @package OC\AppFramework\Middleware\Security |
| 36 | 36 | */ |
| 37 | 37 | class BruteForceMiddleware extends Middleware { |
| 38 | - /** @var ControllerMethodReflector */ |
|
| 39 | - private $reflector; |
|
| 40 | - /** @var Throttler */ |
|
| 41 | - private $throttler; |
|
| 42 | - /** @var IRequest */ |
|
| 43 | - private $request; |
|
| 38 | + /** @var ControllerMethodReflector */ |
|
| 39 | + private $reflector; |
|
| 40 | + /** @var Throttler */ |
|
| 41 | + private $throttler; |
|
| 42 | + /** @var IRequest */ |
|
| 43 | + private $request; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param ControllerMethodReflector $controllerMethodReflector |
|
| 47 | - * @param Throttler $throttler |
|
| 48 | - * @param IRequest $request |
|
| 49 | - */ |
|
| 50 | - public function __construct(ControllerMethodReflector $controllerMethodReflector, |
|
| 51 | - Throttler $throttler, |
|
| 52 | - IRequest $request) { |
|
| 53 | - $this->reflector = $controllerMethodReflector; |
|
| 54 | - $this->throttler = $throttler; |
|
| 55 | - $this->request = $request; |
|
| 56 | - } |
|
| 45 | + /** |
|
| 46 | + * @param ControllerMethodReflector $controllerMethodReflector |
|
| 47 | + * @param Throttler $throttler |
|
| 48 | + * @param IRequest $request |
|
| 49 | + */ |
|
| 50 | + public function __construct(ControllerMethodReflector $controllerMethodReflector, |
|
| 51 | + Throttler $throttler, |
|
| 52 | + IRequest $request) { |
|
| 53 | + $this->reflector = $controllerMethodReflector; |
|
| 54 | + $this->throttler = $throttler; |
|
| 55 | + $this->request = $request; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * {@inheritDoc} |
|
| 60 | - */ |
|
| 61 | - public function beforeController($controller, $methodName) { |
|
| 62 | - parent::beforeController($controller, $methodName); |
|
| 58 | + /** |
|
| 59 | + * {@inheritDoc} |
|
| 60 | + */ |
|
| 61 | + public function beforeController($controller, $methodName) { |
|
| 62 | + parent::beforeController($controller, $methodName); |
|
| 63 | 63 | |
| 64 | - if($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
| 65 | - $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
| 66 | - $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); |
|
| 67 | - } |
|
| 68 | - } |
|
| 64 | + if($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
| 65 | + $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
| 66 | + $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * {@inheritDoc} |
|
| 72 | - */ |
|
| 73 | - public function afterController($controller, $methodName, Response $response) { |
|
| 74 | - if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
| 75 | - $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
| 76 | - $ip = $this->request->getRemoteAddress(); |
|
| 77 | - $this->throttler->sleepDelay($ip, $action); |
|
| 78 | - $this->throttler->registerAttempt($action, $ip, $response->getThrottleMetadata()); |
|
| 79 | - } |
|
| 70 | + /** |
|
| 71 | + * {@inheritDoc} |
|
| 72 | + */ |
|
| 73 | + public function afterController($controller, $methodName, Response $response) { |
|
| 74 | + if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
| 75 | + $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
| 76 | + $ip = $this->request->getRemoteAddress(); |
|
| 77 | + $this->throttler->sleepDelay($ip, $action); |
|
| 78 | + $this->throttler->registerAttempt($action, $ip, $response->getThrottleMetadata()); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - return parent::afterController($controller, $methodName, $response); |
|
| 82 | - } |
|
| 81 | + return parent::afterController($controller, $methodName, $response); |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -35,46 +35,46 @@ |
||
| 35 | 35 | |
| 36 | 36 | class AddServerMiddleware extends Middleware { |
| 37 | 37 | |
| 38 | - /** @var string */ |
|
| 39 | - protected $appName; |
|
| 38 | + /** @var string */ |
|
| 39 | + protected $appName; |
|
| 40 | 40 | |
| 41 | - /** @var IL10N */ |
|
| 42 | - protected $l; |
|
| 41 | + /** @var IL10N */ |
|
| 42 | + protected $l; |
|
| 43 | 43 | |
| 44 | - /** @var ILogger */ |
|
| 45 | - protected $logger; |
|
| 44 | + /** @var ILogger */ |
|
| 45 | + protected $logger; |
|
| 46 | 46 | |
| 47 | - public function __construct($appName, IL10N $l, ILogger $logger) { |
|
| 48 | - $this->appName = $appName; |
|
| 49 | - $this->l = $l; |
|
| 50 | - $this->logger = $logger; |
|
| 51 | - } |
|
| 47 | + public function __construct($appName, IL10N $l, ILogger $logger) { |
|
| 48 | + $this->appName = $appName; |
|
| 49 | + $this->l = $l; |
|
| 50 | + $this->logger = $logger; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Log error message and return a response which can be displayed to the user |
|
| 55 | - * |
|
| 56 | - * @param Controller $controller |
|
| 57 | - * @param string $methodName |
|
| 58 | - * @param \Exception $exception |
|
| 59 | - * @return JSONResponse |
|
| 60 | - * @throws \Exception |
|
| 61 | - */ |
|
| 62 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 63 | - if (($controller instanceof SettingsController) === false) { |
|
| 64 | - throw $exception; |
|
| 65 | - } |
|
| 66 | - $this->logger->error($exception->getMessage(), ['app' => $this->appName]); |
|
| 67 | - if ($exception instanceof HintException) { |
|
| 68 | - $message = $exception->getHint(); |
|
| 69 | - } else { |
|
| 70 | - $message = $exception->getMessage(); |
|
| 71 | - } |
|
| 53 | + /** |
|
| 54 | + * Log error message and return a response which can be displayed to the user |
|
| 55 | + * |
|
| 56 | + * @param Controller $controller |
|
| 57 | + * @param string $methodName |
|
| 58 | + * @param \Exception $exception |
|
| 59 | + * @return JSONResponse |
|
| 60 | + * @throws \Exception |
|
| 61 | + */ |
|
| 62 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 63 | + if (($controller instanceof SettingsController) === false) { |
|
| 64 | + throw $exception; |
|
| 65 | + } |
|
| 66 | + $this->logger->error($exception->getMessage(), ['app' => $this->appName]); |
|
| 67 | + if ($exception instanceof HintException) { |
|
| 68 | + $message = $exception->getHint(); |
|
| 69 | + } else { |
|
| 70 | + $message = $exception->getMessage(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - return new JSONResponse( |
|
| 74 | - ['message' => $message], |
|
| 75 | - Http::STATUS_BAD_REQUEST |
|
| 76 | - ); |
|
| 73 | + return new JSONResponse( |
|
| 74 | + ['message' => $message], |
|
| 75 | + Http::STATUS_BAD_REQUEST |
|
| 76 | + ); |
|
| 77 | 77 | |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | } |
@@ -11,55 +11,55 @@ |
||
| 11 | 11 | |
| 12 | 12 | class ProvisioningApiMiddleware extends Middleware { |
| 13 | 13 | |
| 14 | - /** @var IControllerMethodReflector */ |
|
| 15 | - private $reflector; |
|
| 14 | + /** @var IControllerMethodReflector */ |
|
| 15 | + private $reflector; |
|
| 16 | 16 | |
| 17 | - /** @var bool */ |
|
| 18 | - private $isAdmin; |
|
| 17 | + /** @var bool */ |
|
| 18 | + private $isAdmin; |
|
| 19 | 19 | |
| 20 | - /** @var bool */ |
|
| 21 | - private $isSubAdmin; |
|
| 20 | + /** @var bool */ |
|
| 21 | + private $isSubAdmin; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * ProvisioningApiMiddleware constructor. |
|
| 25 | - * |
|
| 26 | - * @param IControllerMethodReflector $reflector |
|
| 27 | - * @param bool $isAdmin |
|
| 28 | - * @param bool $isSubAdmin |
|
| 29 | - */ |
|
| 30 | - public function __construct( |
|
| 31 | - IControllerMethodReflector $reflector, |
|
| 32 | - $isAdmin, |
|
| 33 | - $isSubAdmin) { |
|
| 34 | - $this->reflector = $reflector; |
|
| 35 | - $this->isAdmin = $isAdmin; |
|
| 36 | - $this->isSubAdmin = $isSubAdmin; |
|
| 37 | - } |
|
| 23 | + /** |
|
| 24 | + * ProvisioningApiMiddleware constructor. |
|
| 25 | + * |
|
| 26 | + * @param IControllerMethodReflector $reflector |
|
| 27 | + * @param bool $isAdmin |
|
| 28 | + * @param bool $isSubAdmin |
|
| 29 | + */ |
|
| 30 | + public function __construct( |
|
| 31 | + IControllerMethodReflector $reflector, |
|
| 32 | + $isAdmin, |
|
| 33 | + $isSubAdmin) { |
|
| 34 | + $this->reflector = $reflector; |
|
| 35 | + $this->isAdmin = $isAdmin; |
|
| 36 | + $this->isSubAdmin = $isSubAdmin; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param Controller $controller |
|
| 41 | - * @param string $methodName |
|
| 42 | - * |
|
| 43 | - * @throws NotSubAdminException |
|
| 44 | - */ |
|
| 45 | - public function beforeController($controller, $methodName) { |
|
| 46 | - if (!$this->isAdmin && !$this->reflector->hasAnnotation('NoSubAdminRequired') && !$this->isSubAdmin) { |
|
| 47 | - throw new NotSubAdminException(); |
|
| 48 | - } |
|
| 49 | - } |
|
| 39 | + /** |
|
| 40 | + * @param Controller $controller |
|
| 41 | + * @param string $methodName |
|
| 42 | + * |
|
| 43 | + * @throws NotSubAdminException |
|
| 44 | + */ |
|
| 45 | + public function beforeController($controller, $methodName) { |
|
| 46 | + if (!$this->isAdmin && !$this->reflector->hasAnnotation('NoSubAdminRequired') && !$this->isSubAdmin) { |
|
| 47 | + throw new NotSubAdminException(); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param Controller $controller |
|
| 53 | - * @param string $methodName |
|
| 54 | - * @param \Exception $exception |
|
| 55 | - * @throws \Exception |
|
| 56 | - * @return Response |
|
| 57 | - */ |
|
| 58 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 59 | - if ($exception instanceof NotSubAdminException) { |
|
| 60 | - throw new OCSException($exception->getMessage(), \OCP\API::RESPOND_UNAUTHORISED); |
|
| 61 | - } |
|
| 51 | + /** |
|
| 52 | + * @param Controller $controller |
|
| 53 | + * @param string $methodName |
|
| 54 | + * @param \Exception $exception |
|
| 55 | + * @throws \Exception |
|
| 56 | + * @return Response |
|
| 57 | + */ |
|
| 58 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 59 | + if ($exception instanceof NotSubAdminException) { |
|
| 60 | + throw new OCSException($exception->getMessage(), \OCP\API::RESPOND_UNAUTHORISED); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - throw $exception; |
|
| 64 | - } |
|
| 63 | + throw $exception; |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -11,43 +11,43 @@ |
||
| 11 | 11 | use OCP\Share\IManager; |
| 12 | 12 | |
| 13 | 13 | class OCSShareAPIMiddleware extends Middleware { |
| 14 | - /** @var IManager */ |
|
| 15 | - private $shareManager; |
|
| 16 | - /** @var IL10N */ |
|
| 17 | - private $l; |
|
| 14 | + /** @var IManager */ |
|
| 15 | + private $shareManager; |
|
| 16 | + /** @var IL10N */ |
|
| 17 | + private $l; |
|
| 18 | 18 | |
| 19 | - public function __construct(IManager $shareManager, |
|
| 20 | - IL10N $l) { |
|
| 21 | - $this->shareManager = $shareManager; |
|
| 22 | - $this->l = $l; |
|
| 23 | - } |
|
| 19 | + public function __construct(IManager $shareManager, |
|
| 20 | + IL10N $l) { |
|
| 21 | + $this->shareManager = $shareManager; |
|
| 22 | + $this->l = $l; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param Controller $controller |
|
| 27 | - * @param string $methodName |
|
| 28 | - * |
|
| 29 | - * @throws OCSNotFoundException |
|
| 30 | - */ |
|
| 31 | - public function beforeController($controller, $methodName) { |
|
| 32 | - if ($controller instanceof ShareAPIController) { |
|
| 33 | - if (!$this->shareManager->shareApiEnabled()) { |
|
| 34 | - throw new OCSNotFoundException($this->l->t('Share API is disabled')); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 25 | + /** |
|
| 26 | + * @param Controller $controller |
|
| 27 | + * @param string $methodName |
|
| 28 | + * |
|
| 29 | + * @throws OCSNotFoundException |
|
| 30 | + */ |
|
| 31 | + public function beforeController($controller, $methodName) { |
|
| 32 | + if ($controller instanceof ShareAPIController) { |
|
| 33 | + if (!$this->shareManager->shareApiEnabled()) { |
|
| 34 | + throw new OCSNotFoundException($this->l->t('Share API is disabled')); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param Controller $controller |
|
| 41 | - * @param string $methodName |
|
| 42 | - * @param Response $response |
|
| 43 | - * @return Response |
|
| 44 | - */ |
|
| 45 | - public function afterController($controller, $methodName, Response $response) { |
|
| 46 | - if ($controller instanceof ShareAPIController) { |
|
| 47 | - /** @var ShareAPIController $controller */ |
|
| 48 | - $controller->cleanup(); |
|
| 49 | - } |
|
| 39 | + /** |
|
| 40 | + * @param Controller $controller |
|
| 41 | + * @param string $methodName |
|
| 42 | + * @param Response $response |
|
| 43 | + * @return Response |
|
| 44 | + */ |
|
| 45 | + public function afterController($controller, $methodName, Response $response) { |
|
| 46 | + if ($controller instanceof ShareAPIController) { |
|
| 47 | + /** @var ShareAPIController $controller */ |
|
| 48 | + $controller->cleanup(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return $response; |
|
| 52 | - } |
|
| 51 | + return $response; |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -47,20 +47,20 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | class SharingCheckMiddleware extends Middleware { |
| 49 | 49 | |
| 50 | - /** @var string */ |
|
| 51 | - protected $appName; |
|
| 52 | - /** @var IConfig */ |
|
| 53 | - protected $config; |
|
| 54 | - /** @var IAppManager */ |
|
| 55 | - protected $appManager; |
|
| 56 | - /** @var IControllerMethodReflector */ |
|
| 57 | - protected $reflector; |
|
| 58 | - /** @var IManager */ |
|
| 59 | - protected $shareManager; |
|
| 60 | - /** @var IRequest */ |
|
| 61 | - protected $request; |
|
| 62 | - |
|
| 63 | - /*** |
|
| 50 | + /** @var string */ |
|
| 51 | + protected $appName; |
|
| 52 | + /** @var IConfig */ |
|
| 53 | + protected $config; |
|
| 54 | + /** @var IAppManager */ |
|
| 55 | + protected $appManager; |
|
| 56 | + /** @var IControllerMethodReflector */ |
|
| 57 | + protected $reflector; |
|
| 58 | + /** @var IManager */ |
|
| 59 | + protected $shareManager; |
|
| 60 | + /** @var IRequest */ |
|
| 61 | + protected $request; |
|
| 62 | + |
|
| 63 | + /*** |
|
| 64 | 64 | * @param string $appName |
| 65 | 65 | * @param IConfig $config |
| 66 | 66 | * @param IAppManager $appManager |
@@ -68,118 +68,118 @@ discard block |
||
| 68 | 68 | * @param IManager $shareManager |
| 69 | 69 | * @param IRequest $request |
| 70 | 70 | */ |
| 71 | - public function __construct($appName, |
|
| 72 | - IConfig $config, |
|
| 73 | - IAppManager $appManager, |
|
| 74 | - IControllerMethodReflector $reflector, |
|
| 75 | - IManager $shareManager, |
|
| 76 | - IRequest $request |
|
| 77 | - ) { |
|
| 78 | - $this->appName = $appName; |
|
| 79 | - $this->config = $config; |
|
| 80 | - $this->appManager = $appManager; |
|
| 81 | - $this->reflector = $reflector; |
|
| 82 | - $this->shareManager = $shareManager; |
|
| 83 | - $this->request = $request; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Check if sharing is enabled before the controllers is executed |
|
| 88 | - * |
|
| 89 | - * @param Controller $controller |
|
| 90 | - * @param string $methodName |
|
| 91 | - * @throws NotFoundException |
|
| 92 | - * @throws S2SException |
|
| 93 | - * @throws ShareNotFound |
|
| 94 | - */ |
|
| 95 | - public function beforeController($controller, $methodName) { |
|
| 96 | - if(!$this->isSharingEnabled()) { |
|
| 97 | - throw new NotFoundException('Sharing is disabled.'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - if ($controller instanceof ExternalSharesController && |
|
| 101 | - !$this->externalSharesChecks()) { |
|
| 102 | - throw new S2SException('Federated sharing not allowed'); |
|
| 103 | - } else if ($controller instanceof ShareController) { |
|
| 104 | - $token = $this->request->getParam('token'); |
|
| 105 | - $share = $this->shareManager->getShareByToken($token); |
|
| 106 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
| 107 | - && !$this->isLinkSharingEnabled()) { |
|
| 108 | - throw new NotFoundException('Link sharing is disabled'); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Return 404 page in case of a not found exception |
|
| 115 | - * |
|
| 116 | - * @param Controller $controller |
|
| 117 | - * @param string $methodName |
|
| 118 | - * @param \Exception $exception |
|
| 119 | - * @return NotFoundResponse |
|
| 120 | - * @throws \Exception |
|
| 121 | - */ |
|
| 122 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 123 | - if(is_a($exception, '\OCP\Files\NotFoundException')) { |
|
| 124 | - return new NotFoundResponse(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if (is_a($exception, '\OCA\Files_Sharing\Exceptions\S2SException')) { |
|
| 128 | - return new JSONResponse($exception->getMessage(), 405); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - throw $exception; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Checks for externalshares controller |
|
| 136 | - * @return bool |
|
| 137 | - */ |
|
| 138 | - private function externalSharesChecks() { |
|
| 139 | - |
|
| 140 | - if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') && |
|
| 141 | - $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') { |
|
| 142 | - return false; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') && |
|
| 146 | - $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') { |
|
| 147 | - return false; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return true; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Check whether sharing is enabled |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - private function isSharingEnabled() { |
|
| 158 | - // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app |
|
| 159 | - // Check whether the sharing application is enabled |
|
| 160 | - if(!$this->appManager->isEnabledForUser($this->appName)) { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return true; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Check if link sharing is allowed |
|
| 169 | - * @return bool |
|
| 170 | - */ |
|
| 171 | - private function isLinkSharingEnabled() { |
|
| 172 | - // Check if the shareAPI is enabled |
|
| 173 | - if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // Check whether public sharing is enabled |
|
| 178 | - if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return true; |
|
| 183 | - } |
|
| 71 | + public function __construct($appName, |
|
| 72 | + IConfig $config, |
|
| 73 | + IAppManager $appManager, |
|
| 74 | + IControllerMethodReflector $reflector, |
|
| 75 | + IManager $shareManager, |
|
| 76 | + IRequest $request |
|
| 77 | + ) { |
|
| 78 | + $this->appName = $appName; |
|
| 79 | + $this->config = $config; |
|
| 80 | + $this->appManager = $appManager; |
|
| 81 | + $this->reflector = $reflector; |
|
| 82 | + $this->shareManager = $shareManager; |
|
| 83 | + $this->request = $request; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Check if sharing is enabled before the controllers is executed |
|
| 88 | + * |
|
| 89 | + * @param Controller $controller |
|
| 90 | + * @param string $methodName |
|
| 91 | + * @throws NotFoundException |
|
| 92 | + * @throws S2SException |
|
| 93 | + * @throws ShareNotFound |
|
| 94 | + */ |
|
| 95 | + public function beforeController($controller, $methodName) { |
|
| 96 | + if(!$this->isSharingEnabled()) { |
|
| 97 | + throw new NotFoundException('Sharing is disabled.'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + if ($controller instanceof ExternalSharesController && |
|
| 101 | + !$this->externalSharesChecks()) { |
|
| 102 | + throw new S2SException('Federated sharing not allowed'); |
|
| 103 | + } else if ($controller instanceof ShareController) { |
|
| 104 | + $token = $this->request->getParam('token'); |
|
| 105 | + $share = $this->shareManager->getShareByToken($token); |
|
| 106 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
| 107 | + && !$this->isLinkSharingEnabled()) { |
|
| 108 | + throw new NotFoundException('Link sharing is disabled'); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Return 404 page in case of a not found exception |
|
| 115 | + * |
|
| 116 | + * @param Controller $controller |
|
| 117 | + * @param string $methodName |
|
| 118 | + * @param \Exception $exception |
|
| 119 | + * @return NotFoundResponse |
|
| 120 | + * @throws \Exception |
|
| 121 | + */ |
|
| 122 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 123 | + if(is_a($exception, '\OCP\Files\NotFoundException')) { |
|
| 124 | + return new NotFoundResponse(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if (is_a($exception, '\OCA\Files_Sharing\Exceptions\S2SException')) { |
|
| 128 | + return new JSONResponse($exception->getMessage(), 405); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + throw $exception; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Checks for externalshares controller |
|
| 136 | + * @return bool |
|
| 137 | + */ |
|
| 138 | + private function externalSharesChecks() { |
|
| 139 | + |
|
| 140 | + if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') && |
|
| 141 | + $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') { |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') && |
|
| 146 | + $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') { |
|
| 147 | + return false; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return true; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Check whether sharing is enabled |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + private function isSharingEnabled() { |
|
| 158 | + // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app |
|
| 159 | + // Check whether the sharing application is enabled |
|
| 160 | + if(!$this->appManager->isEnabledForUser($this->appName)) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return true; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Check if link sharing is allowed |
|
| 169 | + * @return bool |
|
| 170 | + */ |
|
| 171 | + private function isLinkSharingEnabled() { |
|
| 172 | + // Check if the shareAPI is enabled |
|
| 173 | + if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // Check whether public sharing is enabled |
|
| 178 | + if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return true; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | 185 | } |