From fe04bddf77882a8e88701d6c2076f0c8ac132d5e Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 10 Dec 2019 14:33:45 -0500 Subject: [PATCH] - Handles the @Security annotation. Rules are defined at DI level. --- LICENSE | 21 +++++++++++++++++++ composer.json | 26 +++++++++++++++++++++++ src/Annotation/Security.php | 8 +++++++ src/SecurityHandler.php | 42 +++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 LICENSE create mode 100644 composer.json create mode 100644 src/Annotation/Security.php create mode 100644 src/SecurityHandler.php diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cb3012e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019 Dave Mc Nicoll + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..67dbfc2 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "mcnd/notes-security", + "description": "Security annotation at class or method level.", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Dave Mc Nicoll", + "email": "mcndave@gmail.com" + } + ], + "require": { + "mcnd/notes": "master-dev", + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/mcNdave/notes.git" + } + ], + "autoload": { + "psr-4": { + "Notes\\Route\\": "src/" + } + } +} diff --git a/src/Annotation/Security.php b/src/Annotation/Security.php new file mode 100644 index 0000000..595ec57 --- /dev/null +++ b/src/Annotation/Security.php @@ -0,0 +1,8 @@ +response = $response; + } + + public function verify(string $className, string $methodName) : ? ResponseInterface { + # Should generate an equivalent of Ulmus's object reflection here ! + if ( $this->getClassAnnotations($className, $methodName)->locked ) { + return $this->response; + } + + return null; + } + + protected function getClassAnnotations(string $className, string $methodName) : \Notes\Annotation + { + $objectResolver = new ObjectResolver($className, true, true, false, true); + + if ( null !== ( $method = $objectResolver->getAnnotationListFromClassname( Annotation\Security::class ) ) ) { + if ( $method[$methodName] ?? false ) { + return $method[$methodName]; + } + } + + if ( null !== ( $object = $objectResolver->getAnnotationFromClassname( Annotation\Security::class ) ) ) { + return $object; + } + } + +}