/** * @param JwtContext $context */ public function handleContext(JwtContext $context) { if ($context->getResponseJwt()) { $keys = $context->optionGet(ContextOptions::KEYS); if ($this->logger) { $this->logger->debug('EncoderHandler.keys', array('keys' => $keys)); } if (is_array($keys)) { $token = $this->encoder->encode($context->getResponseJwt(), array_shift($keys)); if ($this->logger) { $this->logger->debug('EncoderHandler.token', array('token' => $token)); } $context->setResponseToken($token); } } else { if ($this->logger) { $this->logger->debug('EncoderHandler.noResponseJwt'); } } }
/** * @param JwtContext $context * @throws \BWC\Component\JwtApiBundle\Error\JwtException */ public function handleContext(JwtContext $context) { if ($context->getResponseJwt() || $context->optionGet(ContextOptions::HANDLED)) { return; } if ($this->logger) { $this->logger->debug('UnhandledContextHandler', array('context' => $context)); } $message = sprintf("Unhandled request for direction '%s' method '%s' of issuer '%s'", $context->getRequestJwt()->getDirection(), $context->getRequestJwt()->getMethod(), $context->getRequestJwt()->getIssuer()); $requestJwt = $context->getRequestJwt(); if ($requestJwt->getDirection() == Directions::RESPONSE) { throw new JwtException($message); } $responseJwt = MethodJwt::create(Directions::RESPONSE, $context->getMyIssuerId(), $requestJwt->getMethod(), $requestJwt->getInstance(), null, $requestJwt->getJwtId()); $responseJwt->setException($message); $context->setResponseJwt($responseJwt); }