Search in sources :

Example 1 with DefaultPrincipalData

use of org.apache.kafka.common.message.DefaultPrincipalData in project kafka by apache.

the class DefaultKafkaPrincipalBuilder method deserialize.

@Override
public KafkaPrincipal deserialize(byte[] bytes) {
    ByteBuffer buffer = ByteBuffer.wrap(bytes);
    short version = buffer.getShort();
    if (version < DefaultPrincipalData.LOWEST_SUPPORTED_VERSION || version > DefaultPrincipalData.HIGHEST_SUPPORTED_VERSION) {
        throw new SerializationException("Invalid principal data version " + version);
    }
    DefaultPrincipalData data = new DefaultPrincipalData(new ByteBufferAccessor(buffer), version);
    return new KafkaPrincipal(data.type(), data.name(), data.tokenAuthenticated());
}
Also used : SerializationException(org.apache.kafka.common.errors.SerializationException) KafkaPrincipal(org.apache.kafka.common.security.auth.KafkaPrincipal) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) DefaultPrincipalData(org.apache.kafka.common.message.DefaultPrincipalData) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 SerializationException (org.apache.kafka.common.errors.SerializationException)1 DefaultPrincipalData (org.apache.kafka.common.message.DefaultPrincipalData)1 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)1 KafkaPrincipal (org.apache.kafka.common.security.auth.KafkaPrincipal)1