当前位置: 首页>>代码示例>>Java>>正文


Java JaasUtils类代码示例

本文整理汇总了Java中org.apache.kafka.common.security.JaasUtils的典型用法代码示例。如果您正苦于以下问题:Java JaasUtils类的具体用法?Java JaasUtils怎么用?Java JaasUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JaasUtils类属于org.apache.kafka.common.security包,在下文中一共展示了JaasUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUpClass

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
  int zkConnectionTimeout = 6000;
  int zkSessionTimeout = 6000;

  zookeeper = new EmbeddedZookeeper();
  zkConnect = String.format("127.0.0.1:%d", zookeeper.port());
  zkUtils = ZkUtils.apply(
      zkConnect, zkSessionTimeout, zkConnectionTimeout,
      JaasUtils.isZkSecurityEnabled());

  port = NetworkUtils.getRandomPort();
  kafkaServer = TestUtil09.createKafkaServer(port, zkConnect);
  for (int i = 0; i < topics.length; i++) {
    topics[i] = UUID.randomUUID().toString();
    AdminUtils.createTopic(zkUtils, topics[i], 1, 1, new Properties());

    TestUtils.waitUntilMetadataIsPropagated(
        scala.collection.JavaConversions.asScalaBuffer(Arrays.asList(kafkaServer)),
        topics[i], 0, 5000);
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:23,代码来源:KafkaProducer09IT.java

示例2: createJaasConfiguration

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
private void createJaasConfiguration( String userName, String password) throws Throwable{
	//Create the jaas configuration
	String packageName = MessageHubConfig.class.getPackage().getName().replace('.', File.separatorChar);
	try(InputStream is = MessageHubConfig.class.getClassLoader().getResourceAsStream( packageName + "/jaas.conf")){
		BufferedReader br = new BufferedReader(new InputStreamReader( is ) );
		StringBuilder sb = new StringBuilder();
		String line = null;
		while ( (line = br.readLine()) != null ){
			sb.append( line.replace( "$USERNAME", userName).replace( "$PASSWORD", password ));
		}

		File confDir= new File( System.getProperty("java.io.tmpdir") + File.separator + fixPath( userName ) );
		confDir.mkdirs();
		File confFile = new File( confDir, "jaas.conf");
		FileWriter fw = new FileWriter( confFile );
		fw.write( sb.toString() );
		fw.close();

		//Set the jaas login config property
		System.out.println("Registering JaasConfiguration: " + confFile.getAbsolutePath());
		System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, confFile.getAbsolutePath() );
	}catch (Throwable t){
		t.printStackTrace();
		throw t;
	}        
}
 
开发者ID:ibm-watson-data-lab,项目名称:advo-beta-producer,代码行数:27,代码来源:MessageHubConfig.java

示例3: lookupBootstrap

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
/**
 * Generates the Kafka bootstrap connection string from the metadata stored in Zookeeper.
 * Allows for backwards compatibility of the zookeeperConnect configuration.
 */
private String lookupBootstrap(String zookeeperConnect, SecurityProtocol securityProtocol) {
  ZkUtils zkUtils = ZkUtils.apply(zookeeperConnect, ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT,
      JaasUtils.isZkSecurityEnabled());
  try {
    List<BrokerEndPoint> endPoints =
        asJavaListConverter(zkUtils.getAllBrokerEndPointsForChannel(securityProtocol)).asJava();
    List<String> connections = new ArrayList<>();
    for (BrokerEndPoint endPoint : endPoints) {
      connections.add(endPoint.connectionString());
    }
    return StringUtils.join(connections, ',');
  } finally {
    zkUtils.close();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:KafkaSource.java

示例4: getServiceName

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
private static String getServiceName(Map<String, ?> configs, JaasContext jaasContext) {
    String jaasServiceName = jaasContext.configEntryOption(JaasUtils.SERVICE_NAME, null);
    String configServiceName = (String) configs.get(SaslConfigs.SASL_KERBEROS_SERVICE_NAME);
    if (jaasServiceName != null && configServiceName != null && !jaasServiceName.equals(configServiceName)) {
        String message = String.format("Conflicting serviceName values found in JAAS and Kafka configs " +
            "value in JAAS file %s, value in Kafka config %s", jaasServiceName, configServiceName);
        throw new IllegalArgumentException(message);
    }

    if (jaasServiceName != null)
        return jaasServiceName;
    if (configServiceName != null)
        return configServiceName;

    throw new IllegalArgumentException("No serviceName defined in either JAAS or Kafka config");
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:17,代码来源:KerberosLogin.java

示例5: login

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
@Override
public LoginContext login() throws LoginException {
    String jaasConfigFile = System.getProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM);
    if (jaasConfigFile == null) {
        log.debug("System property '" + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' is not set, using default JAAS configuration.");
    }
    AppConfigurationEntry[] configEntries = Configuration.getConfiguration().getAppConfigurationEntry(loginContextName);
    if (configEntries == null) {
        String errorMessage = "Could not find a '" + loginContextName + "' entry in the JAAS configuration. System property '" +
            JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' is " + (jaasConfigFile == null ? "not set" : jaasConfigFile);
        throw new IllegalArgumentException(errorMessage);
    }

    loginContext = new LoginContext(loginContextName, new LoginCallbackHandler());
    loginContext.login();
    log.info("Successfully logged in.");
    return loginContext;
}
 
开发者ID:txazo,项目名称:kafka,代码行数:19,代码来源:AbstractLogin.java

示例6: getServiceName

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
private String getServiceName(Map<String, ?> configs, String loginContext) {
    String jaasServiceName;
    try {
        jaasServiceName = JaasUtils.jaasConfig(loginContext, JaasUtils.SERVICE_NAME);
    } catch (IOException e) {
        throw new KafkaException("Jaas configuration not found", e);
    }
    String configServiceName = (String) configs.get(SaslConfigs.SASL_KERBEROS_SERVICE_NAME);
    if (jaasServiceName != null && configServiceName != null && !jaasServiceName.equals(configServiceName)) {
        String message = "Conflicting serviceName values found in JAAS and Kafka configs " +
            "value in JAAS file " + jaasServiceName + ", value in Kafka config " + configServiceName;
        throw new IllegalArgumentException(message);
    }

    if (jaasServiceName != null)
        return jaasServiceName;
    if (configServiceName != null)
        return configServiceName;

    throw new IllegalArgumentException("No serviceName defined in either JAAS or Kafka config");
}
 
开发者ID:txazo,项目名称:kafka,代码行数:22,代码来源:KerberosLogin.java

示例7: createMonitoringTopicIfNotExists

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
/**
 * Create the topic that the monitor uses to monitor the cluster.  This method attempts to create a topic so that all
 * the brokers in the cluster will have partitionToBrokerRatio partitions.  If the topic exists, but has different parameters
 * then this does nothing to update the parameters.
 *
 * TODO: Do we care about rack aware mode?  I would think no because we want to spread the topic over all brokers.
 * @param zkUrl zookeeper connection url
 * @param topic topic name
 * @param replicationFactor the replication factor for the topic
 * @param partitionToBrokerRatio This is multiplied by the number brokers to compute the number of partitions in the topic.
 * @param topicConfig additional parameters for the topic for example min.insync.replicas
 * @return the number of partitions created
 */
public static int createMonitoringTopicIfNotExists(String zkUrl, String topic, int replicationFactor,
    double partitionToBrokerRatio, Properties topicConfig) {
  ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled());
  try {
    if (AdminUtils.topicExists(zkUtils, topic)) {
      return getPartitionNumForTopic(zkUrl, topic);
    }
    int brokerCount = zkUtils.getAllBrokersInCluster().size();
    int partitionCount = (int) Math.ceil(brokerCount * partitionToBrokerRatio);

    try {
      AdminUtils.createTopic(zkUtils, topic, partitionCount, replicationFactor, topicConfig, RackAwareMode.Enforced$.MODULE$);
    } catch (TopicExistsException e) {
      //There is a race condition with the consumer.
      LOG.debug("Monitoring topic " + topic + " already exists in cluster " + zkUrl, e);
      return getPartitionNumForTopic(zkUrl, topic);
    }
    LOG.info("Created monitoring topic " + topic + " in cluster " + zkUrl + " with " + partitionCount + " partitions, min ISR of "
      + topicConfig.get(KafkaConfig.MinInSyncReplicasProp()) + " and replication factor of " + replicationFactor + ".");

    return partitionCount;
  } finally {
    zkUtils.close();
  }
}
 
开发者ID:linkedin,项目名称:kafka-monitor,代码行数:39,代码来源:Utils.java

示例8: initKafka

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
@BeforeClass
public static void initKafka() throws Exception {
  synchronized (TestKafkaSuit.class) {
    if (initCount.get() == 0) {
      ZookeeperTestUtil.setZookeeperSaslTestConfigProps();
      System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, ClassLoader.getSystemResource(LOGIN_CONF_RESOURCE_PATHNAME).getFile());
      embeddedKafkaCluster = new EmbeddedKafkaCluster();
      Properties topicProps = new Properties();
      zkClient = new ZkClient(embeddedKafkaCluster.getZkServer().getConnectionString(), SESSION_TIMEOUT, CONN_TIMEOUT, ZKStringSerializer$.MODULE$);
      ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(embeddedKafkaCluster.getZkServer().getConnectionString()), false);
      AdminUtils.createTopic(zkUtils, QueryConstants.JSON_TOPIC, 1, 1, topicProps, RackAwareMode.Disabled$.MODULE$);

      org.apache.kafka.common.requests.MetadataResponse.TopicMetadata fetchTopicMetadataFromZk = AdminUtils
          .fetchTopicMetadataFromZk(QueryConstants.JSON_TOPIC, zkUtils);
      logger.info("Topic Metadata: " + fetchTopicMetadataFromZk);

      KafkaMessageGenerator generator = new KafkaMessageGenerator(embeddedKafkaCluster.getKafkaBrokerList(),
          StringSerializer.class);
      generator.populateJsonMsgIntoKafka(QueryConstants.JSON_TOPIC, NUM_JSON_MSG);
    }
    initCount.incrementAndGet();
    runningSuite = true;
  }
  logger.info("Initialized Embedded Zookeeper and Kafka");
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:26,代码来源:TestKafkaSuit.java

示例9: alterTopic

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
/**
 * <p>Title: alterTopic</p>
 * <p>Description: 修改队列操作</p>
 *
 * @param zookeeperStr zookeeper地址
 * @param topic        队列名称
 * @param config       配置参数
 */
public static void alterTopic(String zookeeperStr, String topic,
                              String... config) {

    StringBuffer updateOptions = new StringBuffer();

    updateOptions.append("--alter").append(space)
            .append("--topic").append(space).append(topic);

    for (int i = 0; i < config.length; i++) {

        if (config[i].indexOf("=") > 0)

            updateOptions.append(space).append("--config").append(space)
                    .append(config[i]);
        else
            updateOptions.append(space).append("--delete-config")
                    .append(space).append(config[i]);
    }

    TopicCommand.alterTopic(ZkUtils.apply(zookeeperStr,
            sessionTimeout, connectionTimeout,
            JaasUtils.isZkSecurityEnabled()), new TopicCommandOptions(
            updateOptions.toString().split(space)));
}
 
开发者ID:DarkPhoenixs,项目名称:message-queue-client-framework,代码行数:33,代码来源:KafkaCommand.java

示例10: before

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
@Override
protected void before() throws Throwable {
    logDirectory = tempDir(perTest("kafka-log"));
    Properties properties = brokerDefinition.getProperties();
    properties.setProperty(KafkaConfig.LogDirProp(), logDirectory.getCanonicalPath());
    kafkaServer = new KafkaServer(new KafkaConfig(properties),
            SystemTime$.MODULE$, Some$.MODULE$.apply("kafkaServer"));
    kafkaServer.startup();

    List<TopicDefinition> topicDefinitions = brokerDefinition.getTopicDefinitions();
    if (!topicDefinitions.isEmpty()) {
        ZkUtils zkUtils = ZkUtils.apply(brokerDefinition.getZookeeperConnect(), 30000, 30000,
                JaasUtils.isZkSecurityEnabled());
        for (TopicDefinition topicDefinition : topicDefinitions) {
            String name = topicDefinition.getName();
            log.info("Creating topic {}", name);
            AdminUtils.createTopic(zkUtils,
                    name,
                    topicDefinition.getPartitions(),
                    topicDefinition.getReplicationFactor(),
                    topicDefinition.getProperties());
        }
    }
}
 
开发者ID:jkorab,项目名称:ameliant-tools,代码行数:25,代码来源:EmbeddedKafkaBroker.java

示例11: login

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
private synchronized LoginContext login(final String loginContextName) throws LoginException {
    String jaasConfigFile = System.getProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM);
    if (jaasConfigFile == null) {
        throw new IllegalArgumentException("You must pass " + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + " in secure mode.");
    }
    AppConfigurationEntry[] configEntries = Configuration.getConfiguration().getAppConfigurationEntry(loginContextName);
    if (configEntries == null) {
        String errorMessage = "Could not find a '" + loginContextName + "' entry in `" + jaasConfigFile + "`.";
        throw new IllegalArgumentException(errorMessage);
    }

    LoginContext loginContext = new LoginContext(loginContextName, callbackHandler);
    loginContext.login();
    log.info("Successfully logged in.");
    return loginContext;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:17,代码来源:Login.java

示例12: getServiceName

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
private String getServiceName(Map<String, ?> configs, String loginContext) {
  String jaasServiceName = null;
  try {
    jaasServiceName = JaasUtils.jaasConfig(loginContext, JaasUtils.SERVICE_NAME);
  } catch (IOException e) {
    //throw new KafkaException("Jaas configuration not found", e);
    log.warn("Jaas configuration not found", e);
  }
  String configServiceName = (String) configs.get(SaslConfigs.SASL_KERBEROS_SERVICE_NAME);
  if (jaasServiceName != null && configServiceName != null && !jaasServiceName.equals(configServiceName)) {
    String message = "Conflicting serviceName values found in JAAS and Kafka configs " +
        "value in JAAS file " + jaasServiceName + ", value in Kafka config " + configServiceName;
    throw new IllegalArgumentException(message);
  }

  if (jaasServiceName != null)
    return jaasServiceName;
  if (configServiceName != null)
    return configServiceName;

  throw new IllegalArgumentException("No serviceName defined in either JAAS or Kafka config");
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:23,代码来源:KerberosLogin.java

示例13: LocalKafkaServer

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
public LocalKafkaServer() throws IOException {

		while (new File(logDir).exists()) {
			FileUtils.deleteDirectory(new File(logDir));
		}

		Properties props = new Properties();
		props.put("broker.id", nodeId);
		props.put("port", port);
		props.put("log.dir", logDir);
		props.put("zookeeper.connect", zkConnect);
		props.put("host.name", "127.0.0.1");
		KafkaConfig conf = new KafkaConfig(props);

                zkUtils = ZkUtils.apply(props.getProperty("zookeeper.connect"),
                          30000,
                          30000,
                          JaasUtils.isZkSecurityEnabled());


		server = new KafkaServerStartable(conf);
		server.startup();
	}
 
开发者ID:blackberry,项目名称:Krackle,代码行数:24,代码来源:LocalKafkaServer.java

示例14: createTopic

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
public static void createTopic(String topicName, int numPartitions, int zkPort) {
    // setup
    String[] arguments = new String[9];
    arguments[0] = "--create";
    arguments[1] = "--zookeeper";
    arguments[2] = "127.0.0.1:" + zkPort;
    arguments[3] = "--replication-factor";
    arguments[4] = "1";
    arguments[5] = "--partitions";
    arguments[6] = "" + Integer.valueOf(numPartitions);
    arguments[7] = "--topic";
    arguments[8] = topicName;
    TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments);

    ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    TopicCommand.createTopic(zkUtils, opts);
}
 
开发者ID:DDTH,项目名称:ddth-kafka,代码行数:19,代码来源:QndEmbeddedServer.java

示例15: createTopic

import org.apache.kafka.common.security.JaasUtils; //导入依赖的package包/类
private static void createTopic(String topicName, int numPartitions, int zkPort) {
    // setup
    String[] arguments = new String[9];
    arguments[0] = "--create";
    arguments[1] = "--zookeeper";
    arguments[2] = "127.0.0.1:" + zkPort;
    arguments[3] = "--replication-factor";
    arguments[4] = "1";
    arguments[5] = "--partitions";
    arguments[6] = "" + Integer.valueOf(numPartitions);
    arguments[7] = "--topic";
    arguments[8] = topicName;
    TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments);

    ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    TopicCommand.createTopic(zkUtils, opts);
}
 
开发者ID:DDTH,项目名称:ddth-kafka,代码行数:19,代码来源:BaseKafkaTest.java


注:本文中的org.apache.kafka.common.security.JaasUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。