JDare / ClankBundle

A Symfony2 Bundle for use with Ratchet WebSocket Server
MIT License
131 stars 31 forks source link

Security.context issue in RPCs #31

Open Merk87 opened 9 years ago

Merk87 commented 9 years ago

Hi.

I'm working around with the RPCs, and when I try to inject the security context and recover the current user, this is null

I've tried in a bunch of different ways, but I'm always back to the same point... someone was able to do this? Any idea?

Thanks.

NaxYo commented 9 years ago

Hi there! I have solved it by getting the session info, unserializing and getting the user:

private function getCurrentUser(Connection $connection) {
    $securityMain = $connection->Session->get('_security_main');

    if($securityMain) {
        $securityMain = unserialize($securityMain);
        $user = $securityMain->getUser();

        return $user;
    }

    return null;
}

Hope it helps ;)

Merk87 commented 9 years ago

Wow that could do the trick!

Thanks!

theodorDiaconu commented 9 years ago

@NaxYo thank you very much!