nette/security

Incompatibility with available nette/http in 3.1.1

jkavalik opened this issue · 12 comments

Argument 1 passed to Nette\Security\User::__construct() must be an instance of Nette\Security\UserStorage or null, instance of Nette\Http\UserStorage given, called in /core/Security/User.php on line 61 and defined in /vendor/nette/security/src/Security/User.php:66

probably nette/http v3.1.0-RC should not be RC anymore, but doing interface rename in a patch release seems a bit too aggressive anyway ;)

ah, I see 3.1.0 is tagged but not really released so it is not a simple patch release

dg commented

What exactly version od nette/http and nette/security do you have installed?

nette/security v3.1.1
nette/http v3.0.5

both are because
nette/nette v3.0.0 requires them with (^3.0)

and fixable by explicitly requiring
"nette/http": "3.1.0-RC"

dg commented

I can't make that bug on the sandbox…

dg commented

Feel free to send a repo or a sample code that doesn't work.

Does sandbox instantiate the security user service by default? We have it as a dependency for our logger.
We have our own implementation too which extends original Nette\Security\User, but the error is on the original constructor which we call (as our code still expects IUserStorage atm)

Hm, so the manually called constructor is at play here - it has strict order of arguments and pust the old IUserStorage instance where the UserStorage is expected
$service = new Core\Security\User(true, $this->getService('security.userStorage'), null, null, $this->getService('orm.model'));
(first parameter is our own, the rest is then sent to Nette\Security\User::__construct() )
whereas the DI itself in sandbox maps arguments by type, so it puts null into UserStorage and pust the 'security.userStorage' into IUserStorage $legacyStorage
$service = new Nette\Security\User(null, $this->getService('01'), null, $this->getService('security.userStorage'));

So the compatibility is ensured for the automatic case but not where we extended the original service with our own.

dg commented

Yes, it instantiates user because it is Presenter dependency.

The problem will be that the constructor of the original User has changed

public function __construct(
UserStorage $storage = null,
IAuthenticator $authenticator = null,
Authorizator $authorizator = null,
IUserStorage $legacyStorage = null
) {

Can you try this in master? 8da2aea

Yes, master fixed it

dg commented

Great

Thank you!