public function check()
    {
    	$action = $this->request->param('action');
        $controller = $this->request->param('controller');
        $prefix = ($this->request->param('prefix') === false) ? '/' : $this->request->param('prefix');
        $plugin = ($this->request->param('plugin') === false) ? '' : $this->request->param('plugin');

        $plugin_prefix = (empty($plugin)) ? $prefix : $plugin . '.' . $prefix;
        if( isset($this->_authorized[$plugin_prefix][$controller]) &&
            in_array($action, $this->_authorized[$plugin_prefix][$controller]) ) return true;

        $user_id = $this->request->session()->read('Auth.User.id');
        $group_id = -1;
        if( isset($this->controllers['group']) ) {
            $User = TableRegistry::get($this->controllers['user']);
            $group_id = $User->get($user_id)->group_id;
        }

        $UserGroupPermission = TableRegistry::get('UserGroupPermission');
        $Permission = TableRegistry::get('Permission');

        $unique_string = $this->getUniqueString($controller, $action, $prefix, $plugin);
        $permission_id = $Permission->find()
            ->select(['id'])
            ->where(['unique_string' => $unique_string])->first();
        if( is_null($permission_id) ) return false;

        $allow = $UserGroupPermission->find()
            ->select(['allow'])
            ->where(
                [
                    'group_or_user'     => 'user',
                    'group_or_user_id'  => $user_id,

                ])
            ->orWhere(
                [
                    'group_or_user'     => 'group',
                    'group_or_user_id'  => $group_id
                ])->andWhere(['permission_id' => $permission_id->id])
            ->order(['allow'=>'DESC'])->first();
        if( is_null($allow) ) return false;

        return $allow->allow;
    }