/** * Create an exception that indicates that the credentials specified in the * connection options do not grant access to the requested AMQP virtual host. * * @param ConnectionOptions $options The options used when establishing the connection. * @param Exception|null $previous The exception that caused this exception, if any. */ public static function authorizationFailed(ConnectionOptions $options, Exception $previous = null) : SingleConnectionException { return new self($options, \sprintf('Unable to access vhost "%s" as "%s" on AMQP broker [%s:%d], check permissions.', $options->vhost(), $options->username(), $options->host(), $options->port()), $previous); }
/** * Perform the "open" phase of the handshake. * * @recoil-coroutine * * @param DuplexChannel $frames A channel over which frames are sent * and received. * @param ConnectionOptions $options The options used when establishing * the connection. */ private function open(DuplexChannel $frames, ConnectionOptions $options) : Generator { (yield $frames->write(ConnectionOpenFrame::create($options->vhost()))); try { $frame = (yield $frames->read()); } catch (ChannelClosedException $e) { throw SingleConnectionException::authorizationFailed($options, $e); } if ($frame instanceof ConnectionCloseFrame) { if ($frame->replyCode === Constants::NOT_ALLOWED && $frame->classId === ConnectionOpenFrame::METHOD_ID >> 16 && $frame->methodId === (ConnectionOpenFrame::METHOD_ID & 0xff)) { throw SingleConnectionException::authorizationFailed($options); } throw SingleConnectionException::closedUnexpectedly($options); } elseif (!$frame instanceof ConnectionOpenOkFrame) { throw ProtocolException::unexpectedFrame($frame, 'expected ' . ConnectionOpenOkFrame::class); } }