# |
Jul 24th 2021, 22:48 |
kevin.pfeifer |
well the Application.php is pretty important since it is used in literally the first php file loaded :) (webroot/index.php) |
# |
Jul 24th 2021, 22:48 |
jojomartius |
hehe ya now its not writing it into the logfile :) |
# |
Jul 24th 2021, 22:47 |
jojomartius |
i do remember that i somehow missed the point when the "Application.php" was introduced and i had some trouble to get it working, so maybe i did something stupid back in this days |
# |
Jul 24th 2021, 22:46 |
jojomartius |
well.. guess that could be the problem |
# |
Jul 24th 2021, 22:46 |
jojomartius |
but theres a lot of interesting stuff inside the "new" app |
# |
Jul 24th 2021, 22:45 |
kevin.pfeifer |
which is not the problem here because I got that too |
# |
Jul 24th 2021, 22:44 |
kevin.pfeifer |
I also just noticed, that there is an issue open for duplicate errorHandler instances created in the template https://github.com/cakephp/app/issues/842 |
# |
Jul 24th 2021, 22:43 |
kevin.pfeifer |
yea, keeping the project up2date with the cakephp/app template can be a bit challenging sometimes :) |
# |
Jul 24th 2021, 22:43 |
jojomartius |
i think thats a good point to start debugging :) |
# |
Jul 24th 2021, 22:43 |
jojomartius |
guess this comes from updating and upgrading from older cake versions over and over again ;) |
# |
Jul 24th 2021, 22:42 |
jojomartius |
yes, just compared config/boostrap.php with https://github.com/cakephp/app/blob/master/config/bootstrap.php, looks pretty different. but also replacing it with the standard one doesnt help |
# |
Jul 24th 2021, 22:37 |
kevin.pfeifer |
well then either look for `Configure::write` or check your `config/bootstrap.php` if some other config files are loaded which could overwrite your main config |
# |
Jul 24th 2021, 22:35 |
jojomartius |
you'r right. well i havn't foudn whats overwriting the config but when i dump getconfig in `vendor/cakephp/cakephp/src/Error/ErrorLogger.php` line 77, it says its an empty array |
# |
Jul 24th 2021, 22:32 |
jojomartius |
mh... yes there must be something overwriting my config... usually computers don't lie ;-) |
# |
Jul 24th 2021, 22:31 |
kevin.pfeifer |
you sure no other config overwrites your config set in app.php? |
# |
Jul 24th 2021, 22:30 |
kevin.pfeifer |
basically the decision/logic for that is present in `vendor/cakephp/cakephp/src/Error/ErrorLogger.php` line 77 If you got xdebug maybe step into there |
# |
Jul 24th 2021, 22:28 |
jojomartius |
`021-07-25 00:28:03 Error: [Cake\Http\Exception\MissingControllerException] Controller class Asdf could not be found. in /app/app/acb/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php on line 226` Exception Attributes: array ( 'class' => 'Asdf', 'plugin' => NULL, 'prefix' => NULL, '_ext' => NULL, ) Request URL: /asdf Client IP: 172.19.0.1 |
# |
Jul 24th 2021, 22:28 |
jojomartius |
``` 'Error' => [ 'errorLevel' => E_ALL and ~E_USER_DEPRECATED and ~E_USER_NOTICE, 'exceptionRenderer' => 'Cake\Error\ExceptionRenderer', 'skipLog' => ['Cake\Http\Exception\MissingControllerException'], 'log' => true, 'trace' => true, ],``` |
# |
Jul 24th 2021, 22:28 |
jojomartius |
intresting |
# |
Jul 24th 2021, 22:27 |
kevin.pfeifer |
no error when adding ```'skipLog' => ['Cake\Http\Exception\MissingControllerException'],``` and calling an unkown URL |
# |
Jul 24th 2021, 22:27 |
kevin.pfeifer |
mhmm, it works for me :thinking_face: |
# |
Jul 24th 2021, 22:17 |
jojomartius |
Hey, i'm using Cakephp 4.2 and want to skip some error's from being logged (to much in production). I added in app.php Error.skipLog => ['Cake\Http\Exception\MissingControllerException'] but i still get messages when i try to visit random urls like /lkajsdf2 in logs/error.log. Did i get it wrong? |
# |
Jul 24th 2021, 19:14 |
kevin.pfeifer |
as always, just ask ;) |
# |
Jul 24th 2021, 18:21 |
kevin.pfeifer |
https://github.com/cakephp/app/blob/master/src/Controller/PagesController.php#L46 |
# |
Jul 24th 2021, 18:10 |
kevin.pfeifer |
just like in the main app example https://github.com/cakephp/app/blob/master/config/routes.php#L53 You can set the default homepage via ```$builder->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);``` Which will show the `/templates/pages/home` template for your root domain like http://mydomain.local |
# |
Jul 24th 2021, 17:56 |
kevin.pfeifer |
basically ```$this->set('navs', $navs);``` and ```$this->set(compact('navs'));``` are the same |
# |
Jul 24th 2021, 17:50 |
kevin.pfeifer |
and see https://book.cakephp.org/3/en/controllers.html#setting-view-variables how `$this->set()` works with either 2 parameters or one associative array |
# |
Jul 24th 2021, 17:47 |
kevin.pfeifer |
but basically its up to you if you want to build the query completely in the controller or clean up the controller and put these query statements in the model |
# |
Jul 24th 2021, 17:47 |
kevin.pfeifer |
but if you want to use your custom finder method you should use ``` $navs = $this->Pages->find('publish')``` instead of ``` $navs = $this->Pages->find('all')``` |
# |
Jul 24th 2021, 17:46 |
kevin.pfeifer |
see https://www.php.net/manual/de/function.compact.php what compact does. It just is a neat way to transform variables inside the controller into key=>value pairs which then can be set to the view via `$this->set(compact('vars'));` |
# |
Jul 24th 2021, 17:14 |
kevin.pfeifer |
there should be no calling of custom finder methods via the template directly. If you have already defined that function in your PagesTable.php then you should go to your PagesController.php, call that finder in e.g. the `index()` function via ```$data = $this->Pages->find('publish')->toArray();``` and set that data to be accessible in your view/template via ```$this->set(compact('data'));``` So always go Model => |
# |
Jul 24th 2021, 17:14 |
slackebot2 |
Controller => View |
# |
Jul 24th 2021, 09:45 |
kevin.pfeifer |
there is only one post-install hook after `composer install` which sets `chmod -R 777 logs tmp` https://github.com/cakephp/app/blob/54b699c2b0b212cef645f8c764c6b7494c9bba32/src/Console/Installer.php#L136 |
# |
Jul 24th 2021, 09:35 |
kevin.pfeifer |
what permissions problems do you have? |
# |
Jul 24th 2021, 09:10 |
noel |
I tried this:-https://book.cakephp.org/3/en/installation.html#permissions ... but it doesn't work on Mac |
# |
Jul 24th 2021, 09:09 |
noel |
Is there a bin/cake command to reset folder permissions for cake? |
# |
Jul 24th 2021, 08:25 |
rohith |
Never mind, I think I am supposed to do that using TypeFactory::map() function :) |
# |
Jul 24th 2021, 08:20 |
rohith |
Hi, is there any way to disable date and time converting to FrozenDate Object when executing queries ? |
# |
Jul 23rd 2021, 13:27 |
kevin.pfeifer |
but thats how the authentication and authorization plugin is built now |
# |
Jul 23rd 2021, 13:27 |
kevin.pfeifer |
not that easy for sure |
# |
Jul 23rd 2021, 13:27 |
paolo.bragagni |
thanks Kevin |
# |
Jul 23rd 2021, 13:27 |
paolo.bragagni |
but probaby from now on I can go with my legs |
# |
Jul 23rd 2021, 13:27 |
kevin.pfeifer |
then you need to adjust that in the given config |
# |
Jul 23rd 2021, 13:26 |
paolo.bragagni |
and not to https://cakephp.local/myapp/users/login |
# |
Jul 23rd 2021, 13:26 |
paolo.bragagni |
https://cakephp.local/users/login |
# |
Jul 23rd 2021, 13:26 |
paolo.bragagni |
it redirects to |
# |
Jul 23rd 2021, 13:26 |
kevin.pfeifer |
and the ```$request->getFlash()->error('You are not authorized to access that location');``` needs to be added anywhere in the handle function before the reutnr |
# |
Jul 23rd 2021, 13:24 |
kevin.pfeifer |
and adjust the namespace to `namespace App\Middleware\UnauthorizedHandler;` |
# |
Jul 23rd 2021, 13:24 |
kevin.pfeifer |
if you copied the whole RedirectHandler then you will have to add at least ```use Authorization\Middleware\UnauthorizedHandler\HandlerInterface;``` at the top since the interface can’t be autoloaded |
# |
Jul 23rd 2021, 13:22 |
paolo.bragagni |
steps ahead |
# |
Jul 23rd 2021, 13:20 |
kevin.pfeifer |
ok and ```use Authorization\Exception\ForbiddenException; ``` at the top |
# |
Jul 23rd 2021, 13:20 |
paolo.bragagni |
$middlewareQueue->add(new AuthorizationMiddleware($this, [ 'requireAuthorizationCheck' => false, 'unauthorizedHandler' => [ 'className' => 'Regtosc', 'url' => '/users/login', 'queryParam' => 'redirectUrl', 'exceptions' => [ ForbiddenException::class, MissingIdentityException::class, OtherException::class, ], ], ])); |
# |
Jul 23rd 2021, 13:19 |
kevin.pfeifer |
do you have the `ForbiddenException::class` in your exceptions array |
# |
Jul 23rd 2021, 13:18 |
kevin.pfeifer |
check your middleware |
# |
Jul 23rd 2021, 13:18 |
paolo.bragagni |
*Identity is not authorized to perform `add` on `App\Model\Entity\Libro`.* |
# |
Jul 23rd 2021, 13:18 |
paolo.bragagni |
but it doesnt redirect |
# |
Jul 23rd 2021, 13:17 |
kevin.pfeifer |
ok sure |
# |
Jul 23rd 2021, 13:17 |
paolo.bragagni |
no. now I've copied all redirect handler to my handler |
# |
Jul 23rd 2021, 13:17 |
kevin.pfeifer |
``` // Add authorization **after** authentication ->add(new AuthorizationMiddleware($this, [ 'unauthorizedHandler' => [ 'className' => 'CustomRedirect', 'url' => '/users/login', 'queryParam' => 'redirectUrl', 'exceptions' => [ MissingIdentityException::class, ForbiddenException::class ], ], ]))``` |
# |
Jul 23rd 2021, 13:15 |
kevin.pfeifer |
so its not working for you? |
# |
Jul 23rd 2021, 13:14 |
kevin.pfeifer |
basically what is done here https://github.com/cakephp/authorization/blob/master/src/Middleware/UnauthorizedHandler/RedirectHandler.php#L61 |
# |
Jul 23rd 2021, 13:14 |
paolo.bragagni |
a little bit too much for me :S |
# |
Jul 23rd 2021, 13:13 |
kevin.pfeifer |
and you have to tell the handler which exceptions it should “listen” to |
# |
Jul 23rd 2021, 13:13 |
kevin.pfeifer |
the handler only redirects certain exceptions |
# |
Jul 23rd 2021, 13:10 |
kevin.pfeifer |
and `use Authorization\Exception\ForbiddenException;` at the top |
# |
Jul 23rd 2021, 13:10 |
kevin.pfeifer |
you need to add `ForbiddenException::class` to the `exception` array |
# |
Jul 23rd 2021, 13:09 |
kevin.pfeifer |
as said, thats a different exception |
# |
Jul 23rd 2021, 13:08 |
paolo.bragagni |
*Identity is not authorized to perform `add` on `App\Model\Entity\Libro`* |
# |
Jul 23rd 2021, 13:05 |
kevin.pfeifer |
depending on the thrown execption could be that you need to adjust the expections array in the config |
# |
Jul 23rd 2021, 13:05 |
kevin.pfeifer |
works for me now :thinking_face: |
# |
Jul 23rd 2021, 13:04 |
paolo.bragagni |
mmm |
# |
Jul 23rd 2021, 13:04 |
kevin.pfeifer |
try to just return false to test it |
# |
Jul 23rd 2021, 13:04 |
kevin.pfeifer |
thats a problem inside your policy |
# |
Jul 23rd 2021, 13:00 |
paolo.bragagni |
*Pre-authorization check must return `Authorization\Policy\ResultInterface`, `bool` or `null`.* |
# |
Jul 23rd 2021, 12:56 |
kevin.pfeifer |
well i basically copied my values from the use statement but i forgot that you need to add the \ if youre not using the class via the use |
# |
Jul 23rd 2021, 12:54 |
paolo.bragagni |
before Authorization |
# |
Jul 23rd 2021, 12:52 |
kevin.pfeifer |
could be that i forgot the \ at the front of App ,:) |
# |
Jul 23rd 2021, 12:51 |
paolo.bragagni |
*Interface 'App\Middleware\UnauthorizedHandler\Authorization\Middleware\UnauthorizedHandler\HandlerInterface' not found* |
# |
Jul 23rd 2021, 12:49 |
kevin.pfeifer |
basically i forgot the extend of the already present RedirectHandler |
# |
Jul 23rd 2021, 12:49 |
kevin.pfeifer |
check again, should be more clear now |
# |
Jul 23rd 2021, 12:44 |
paolo.bragagni |
fighting with namespaces |
# |
Jul 23rd 2021, 12:39 |
kevin.pfeifer |
i mixed 2 things together, let me fix that |
# |
Jul 23rd 2021, 12:39 |
kevin.pfeifer |
ah sorry, i forgot something |
# |
Jul 23rd 2021, 12:37 |
paolo.bragagni |
wait |
# |
Jul 23rd 2021, 12:37 |
paolo.bragagni |
I'm stupid |
# |
Jul 23rd 2021, 12:37 |
paolo.bragagni |
:S |
# |
Jul 23rd 2021, 12:37 |
paolo.bragagni |
*Handler `Regtosc` does not exist.* |
# |
Jul 23rd 2021, 12:32 |
paolo.bragagni |
thank you Kevin. trying to reproduce |
# |
Jul 23rd 2021, 12:32 |
kevin.pfeifer |
you can check out https://github.com/LordSimal/authorization/blob/master/docs/en/middleware.rst#how-to-create-a-custom-unauthorizedhandler till we wait till my PR is being reviewed |
# |
Jul 23rd 2021, 12:31 |
kevin.pfeifer |
well since you will be implementing a custom handler you can do that logic in there too |
# |
Jul 23rd 2021, 12:11 |
paolo.bragagni |
also redirection to previuos page needs an handler? |
# |
Jul 23rd 2021, 12:10 |
paolo.bragagni |
hhihi thanks (I think that its a common request, so probably should be included someway in default code) |
# |
Jul 23rd 2021, 12:08 |
kevin.pfeifer |
I am just in the process of updating the doc since its a bit more “advanced” I would say |
# |
Jul 23rd 2021, 12:06 |
paolo.bragagni |
first of all I dont know how to create my own handler |
# |
Jul 23rd 2021, 12:05 |
paolo.bragagni |
not so easy |
# |
Jul 23rd 2021, 11:46 |
paolo.bragagni |
:) |
# |
Jul 23rd 2021, 11:46 |
paolo.bragagni |
arghhhh |
# |
Jul 23rd 2021, 10:54 |
kevin.pfeifer |
so basically the example uses the RedirectHandler (`Authorization.Redirect` in your array above) which is this class in the plugin https://github.com/cakephp/authorization/blob/master/src/Middleware/UnauthorizedHandler/RedirectHandler.php |
# |
Jul 23rd 2021, 10:53 |
kevin.pfeifer |
what you do in that handle() function is basically up to you |
# |
Jul 23rd 2021, 10:52 |
kevin.pfeifer |
and with that you can also (as the doc describes) create your own Handler https://github.com/cakephp/authorization/blob/15aa0e01746c797ed3ce5ce745a7a3f08ccc0c6e/docs/en/middleware.rst#handling-unauthorized-requests |