yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

I give "unserialize(): Error at offset 0 of 60 bytes" for create permission with rule #17635

Closed bagtim closed 4 years ago

bagtim commented 5 years ago
 $auth = Yii::$app->authManager;

// add the rule
        $rule = new \app\rbac\AuthorRule;
        $auth->add($rule);

// add "updateOwnPost" permission and bind a rule to it
        $updateOwnPost = $auth->createPermission('updateOwnPost');
        $updateOwnPost->description = 'Update own post';
        $updateOwnPost->ruleName = $rule->name;
        $auth->add($updateOwnPost);

Without setted ruleName, permission is good created. But if set ruleName, i have error "unserialize(): Error at offset 0 of 60 bytes"

Q A
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)
Yii version 2.0.29
PHP version 5.6.31
Operating system win10 64
samdark commented 5 years ago
  1. Was PHP manager used?
  2. What was the name?
bagtim commented 5 years ago

iis 10, php manager from https://www.iis.net/downloads/community/2018/05/php-manager-150-for-iis-10, php install from iis web platform

bagtim commented 5 years ago

I think problem near column type varbinary, because after removed 4 auth tables, i create new tables with change column types from binary to varchar for AuthItem->ruleName and AuthRule->data. And then worked is fine. This problem has from version where columns type is varbinary.

samdark commented 5 years ago

Do you store RBAC rules in MSSQL?

samdark commented 5 years ago

Was table created from migrations or https://github.com/yiisoft/yii2/blob/b39bb71587cb4a4964238bdc6e846535588a3cfc/framework/rbac/migrations/schema-mssql.sql?

bagtim commented 5 years ago

Do you store RBAC rules in MSSQL?

Yes

Tables created from migrations with "yii migrate --migrationPath=@yii/rbac/migrations"

samdark commented 5 years ago

What was used as the rule name?

bagtim commented 5 years ago

What was used as the rule name?

From docs:

class AuthorRule extends Rule
{
    public $name = 'isAuthor';
...

and then from topic post:

$rule = new \app\rbac\AuthorRule;
$auth->add($rule);
...
$updateOwnPost->ruleName = $rule->name;
$auth->add($updateOwnPost);
samdark commented 5 years ago

OK. That's enough info to try reproducing it.

toatall commented 4 years ago

I had an analogical problem. I did following: 1) Change to CONVERT(VARBINARY(MAX), ...) in QueryBuilder::normalizeTableRowData because default length is 30 characters (Link MS SQL Server) 2) For VARBINARY field need add paramert in PDOStatement::bindParam driver_options "PDO::SQLSRV_ENCODING_BINARY" PDOStatement::bindParam(column, &$var, type,length,PDO::SQLSRV_ENCODING_BINARY); DbManager Or not use PDOStatement. Use PDO::exec('insert...')

samdark commented 4 years ago

@toatall since you're into it, would you like to prepare a pull request with a fix?

toatall commented 4 years ago

@samdark OK!

samdark commented 4 years ago

@bagtim would you please check if @toatall solution fixes the issue for you?