11package org .openpolicyagent .kafka
22
3+ import com .fasterxml .jackson .databind .json .JsonMapper
4+ import com .fasterxml .jackson .databind .module .SimpleModule
5+
36import java .net .{InetAddress , URI }
47import java .net .http .HttpRequest .BodyPublishers
58import java .net .http .HttpResponse .BodyHandlers
69import java .net .http .{HttpClient , HttpRequest , HttpResponse }
710import org .junit .runner .RunWith
811import org .scalatestplus .junit .JUnitRunner
912import com .typesafe .scalalogging .LazyLogging
10- import com .fasterxml .jackson .databind .ObjectMapper
11- import com .fasterxml .jackson .module .scala .{DefaultScalaModule , ScalaObjectMapper }
12- import kafka .network .RequestChannel
13+ import com .fasterxml .jackson .module .scala .DefaultScalaModule
1314import org .apache .kafka .common .acl .AclOperation
1415import org .apache .kafka .common .network .{ClientInformation , ListenerName }
1516import org .apache .kafka .common .protocol .ApiKeys
@@ -18,10 +19,12 @@ import org.apache.kafka.common.security.auth.{KafkaPrincipal, SecurityProtocol}
1819import org .apache .kafka .common .resource .ResourcePattern
1920import org .apache .kafka .common .resource .ResourceType
2021import org .apache .kafka .common .requests .{RequestContext , RequestHeader }
22+ import org .apache .kafka .network .Session
2123import org .apache .kafka .server .authorizer .{Action , AuthorizationResult }
2224import org .scalatest ._
2325import matchers .should ._
2426import flatspec ._
27+ import org .apache .kafka .common .message .RequestHeaderData
2528
2629import java .lang .management .ManagementFactory
2730import javax .management .ObjectName
@@ -35,7 +38,15 @@ import scala.jdk.CollectionConverters._
3538class OpaAuthorizerSpec extends AnyFlatSpec with Matchers with PrivateMethodTester with LazyLogging {
3639
3740 private val opaUrl = " http://localhost:8181/v1/data/kafka/authz/allow"
38- private val objectMapper = (new ObjectMapper () with ScalaObjectMapper ).registerModule(DefaultScalaModule )
41+ private val requestSerializerModule = new SimpleModule ()
42+ .addSerializer(classOf [ResourcePattern ], new ResourcePatternSerializer )
43+ .addSerializer(classOf [Action ], new ActionSerializer )
44+ .addSerializer(classOf [RequestContext ], new RequestContextSerializer )
45+ .addSerializer(classOf [ClientInformation ], new ClientInformationSerializer )
46+ .addSerializer(classOf [KafkaPrincipal ], new KafkaPrincipalSerializer )
47+ .addSerializer(classOf [RequestHeader ], new RequestHeaderSerializer )
48+ .addSerializer(classOf [RequestHeaderData ], new RequestHeaderDataSerializer )
49+ private val objectMapper = JsonMapper .builder().addModule(requestSerializerModule).addModule(DefaultScalaModule ).build()
3950 private val defaultCacheCapacity = 50000
4051 private lazy val opaResponse = testOpaConnection()
4152
@@ -295,8 +306,8 @@ class OpaAuthorizerSpec extends AnyFlatSpec with Matchers with PrivateMethodTest
295306
296307 def createRequest (username : String , actions : List [Action ]): FullRequest = {
297308 val principal = new KafkaPrincipal (" User" , username)
298- val session = RequestChannel . Session (principal, InetAddress .getLoopbackAddress)
299- val authzReqContext = new AzRequestContext (
309+ val session = new Session (principal, InetAddress .getLoopbackAddress)
310+ val authzReqContext = AzRequestContext (
300311 clientId = " rdkafka" ,
301312 requestType = 1 ,
302313 listenerName = " SASL_PLAINTEXT" ,
0 commit comments