Search in sources :

Example 1 with Operation$

use of kafka.security.auth.Operation$ in project ksql by confluentinc.

the class EmbeddedSingleNodeKafkaCluster method addUserAcl.

/**
 * Writes the supplied ACL information to ZK, where it will be picked up by the brokes authorizer.
 *
 * @param username    the who.
 * @param permission  the allow|deny.
 * @param resource    the thing
 * @param ops         the what.
 */
public void addUserAcl(final String username, final AclPermissionType permission, final Resource resource, final Set<AclOperation> ops) {
    final KafkaPrincipal principal = new KafkaPrincipal("User", username);
    final PermissionType scalaPermission = PermissionType$.MODULE$.fromJava(permission);
    final Set<Acl> javaAcls = ops.stream().map(Operation$.MODULE$::fromJava).map(op -> new Acl(principal, scalaPermission, "*", op)).collect(Collectors.toSet());
    final scala.collection.immutable.Set<Acl> scalaAcls = JavaConversions.asScalaSet(javaAcls).toSet();
    kafka.security.auth.ResourceType scalaResType = ResourceType$.MODULE$.fromJava(resource.resourceType());
    final kafka.security.auth.Resource scalaResource = new kafka.security.auth.Resource(scalaResType, resource.name());
    authorizer.addAcls(scalaAcls, scalaResource);
    addedAcls.add(scalaResource);
}
Also used : Arrays(java.util.Arrays) Credentials(io.confluent.ksql.testutils.secure.Credentials) AclPermissionType(org.apache.kafka.common.acl.AclPermissionType) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ServerKeyStore(io.confluent.ksql.testutils.secure.ServerKeyStore) JaasUtils(org.apache.kafka.common.security.JaasUtils) SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Resource(org.apache.kafka.common.resource.Resource) Files(com.google.common.io.Files) Operation$(kafka.security.auth.Operation$) SimpleAclAuthorizer(kafka.security.auth.SimpleAclAuthorizer) SASL_SSL(org.apache.kafka.common.security.auth.SecurityProtocol.SASL_SSL) Map(java.util.Map) PlainLoginModule(org.apache.kafka.common.security.plain.PlainLoginModule) KafkaConfig(kafka.server.KafkaConfig) ZKConfig(kafka.utils.ZKConfig) JavaConversions(scala.collection.JavaConversions) Logger(org.slf4j.Logger) Properties(java.util.Properties) ClientTrustStore(io.confluent.ksql.testutils.secure.ClientTrustStore) ImmutableMap(com.google.common.collect.ImmutableMap) TestUtils(org.apache.kafka.test.TestUtils) SecureKafkaHelper(io.confluent.ksql.testutils.secure.SecureKafkaHelper) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) IOException(java.io.IOException) AclOperation(org.apache.kafka.common.acl.AclOperation) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) PermissionType(kafka.security.auth.PermissionType) PermissionType$(kafka.security.auth.PermissionType$) Acl(kafka.security.auth.Acl) List(java.util.List) ExternalResource(org.junit.rules.ExternalResource) Stream(java.util.stream.Stream) ResourceType$(kafka.security.auth.ResourceType$) KafkaPrincipal(org.apache.kafka.common.security.auth.KafkaPrincipal) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) AclPermissionType(org.apache.kafka.common.acl.AclPermissionType) PermissionType(kafka.security.auth.PermissionType) Resource(org.apache.kafka.common.resource.Resource) ExternalResource(org.junit.rules.ExternalResource) KafkaPrincipal(org.apache.kafka.common.security.auth.KafkaPrincipal) Acl(kafka.security.auth.Acl)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Files (com.google.common.io.Files)1 ClientTrustStore (io.confluent.ksql.testutils.secure.ClientTrustStore)1 Credentials (io.confluent.ksql.testutils.secure.Credentials)1 SecureKafkaHelper (io.confluent.ksql.testutils.secure.SecureKafkaHelper)1 ServerKeyStore (io.confluent.ksql.testutils.secure.ServerKeyStore)1 File (java.io.File)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1