本文整理汇总了Java中org.apache.kafka.common.network.Mode类的典型用法代码示例。如果您正苦于以下问题:Java Mode类的具体用法?Java Mode怎么用?Java Mode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Mode类属于org.apache.kafka.common.network包,在下文中一共展示了Mode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: configure
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
public void configure(TransportLayer transportLayer, PrincipalBuilder principalBuilder, Map<String, ?> configs) throws KafkaException {
try {
this.transportLayer = transportLayer;
this.configs = configs;
// 初始化saslstate字段为SEND_HANDSHAKE_REQUEST
setSaslState(handshakeRequestEnable ? SaslState.SEND_HANDSHAKE_REQUEST : SaslState.INITIAL);
// determine client principal from subject for Kerberos to use as authorization id for the SaslClient.
// For other mechanisms, the authenticated principal (username for PLAIN and SCRAM) is used as
// authorization id. Hence the principal is not specified for creating the SaslClient.
if (mechanism.equals(SaslConfigs.GSSAPI_MECHANISM))
this.clientPrincipalName = firstPrincipal(subject);
else
this.clientPrincipalName = null;
// 用于收集认证信息I的SaslClientCallbackHandler
callbackHandler = new SaslClientCallbackHandler();
callbackHandler.configure(configs, Mode.CLIENT, subject, mechanism);
// 创建saslclient对象
saslClient = createSaslClient();
} catch (Exception e) {
throw new KafkaException("Failed to configure SaslClientAuthenticator", e);
}
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:SaslClientAuthenticator.java
示例2: createSaslServer
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
private void createSaslServer(String mechanism) throws IOException {
this.saslMechanism = mechanism;
if (!ScramMechanism.isScram(mechanism))
callbackHandler = new SaslServerCallbackHandler(jaasContext, kerberosNamer);
else
callbackHandler = new ScramServerCallbackHandler(credentialCache.cache(mechanism, ScramCredential.class));
callbackHandler.configure(configs, Mode.SERVER, subject, saslMechanism);
if (mechanism.equals(SaslConfigs.GSSAPI_MECHANISM)) {
saslServer = createSaslKerberosServer(callbackHandler, configs, subject);
} else {
try {
saslServer = Subject.doAs(subject, new PrivilegedExceptionAction<SaslServer>() {
public SaslServer run() throws SaslException {
// 调用createSaslServer
return Sasl.createSaslServer(saslMechanism, "kafka", host, configs, callbackHandler);
}
});
} catch (PrivilegedActionException e) {
throw new SaslException("Kafka Server failed to create a SaslServer to interact with a client during session authentication", e.getCause());
}
}
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:23,代码来源:SaslServerAuthenticator.java
示例3: createSslEngine
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
public SSLEngine createSslEngine(String peerHost, int peerPort) {
SSLEngine sslEngine = sslContext.createSSLEngine(peerHost, peerPort);
if (cipherSuites != null) sslEngine.setEnabledCipherSuites(cipherSuites);
if (enabledProtocols != null) sslEngine.setEnabledProtocols(enabledProtocols);
// SSLParameters#setEndpointIdentificationAlgorithm enables endpoint validation
// only in client mode. Hence, validation is enabled only for clients.
if (mode == Mode.SERVER) {
sslEngine.setUseClientMode(false);
if (needClientAuth)
sslEngine.setNeedClientAuth(needClientAuth);
else
sslEngine.setWantClientAuth(wantClientAuth);
} else {
sslEngine.setUseClientMode(true);
SSLParameters sslParams = sslEngine.getSSLParameters();
sslParams.setEndpointIdentificationAlgorithm(endpointIdentification);
sslEngine.setSSLParameters(sslParams);
}
return sslEngine;
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:22,代码来源:SslFactory.java
示例4: createSslConfig
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
private static Map<String, Object> createSslConfig(Mode mode, File keyStoreFile, Password password, Password keyPassword,
File trustStoreFile, Password trustStorePassword) {
Map<String, Object> sslConfigs = new HashMap<>();
sslConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.2"); // protocol to create SSLContext
if (mode == Mode.SERVER || (mode == Mode.CLIENT && keyStoreFile != null)) {
sslConfigs.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, keyStoreFile.getPath());
sslConfigs.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, "JKS");
sslConfigs.put(SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, TrustManagerFactory.getDefaultAlgorithm());
sslConfigs.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, password);
sslConfigs.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyPassword);
}
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, trustStoreFile.getPath());
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, trustStorePassword);
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, "JKS");
sslConfigs.put(SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, TrustManagerFactory.getDefaultAlgorithm());
List<String> enabledProtocols = new ArrayList<>();
enabledProtocols.add("TLSv1.2");
sslConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, enabledProtocols);
return sslConfigs;
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:25,代码来源:TestSslUtils.java
示例5: createSslConfig
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
private static Map<String, Object> createSslConfig(Mode mode, File keyStoreFile, Password password, Password keyPassword,
File trustStoreFile, Password trustStorePassword) {
Map<String, Object> sslConfigs = new HashMap<>();
sslConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.2"); // protocol to create SSLContext
if (mode == Mode.SERVER || (mode == Mode.CLIENT && keyStoreFile != null)) {
sslConfigs.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, keyStoreFile.getPath());
sslConfigs.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, "JKS");
sslConfigs.put(SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, TrustManagerFactory.getDefaultAlgorithm());
sslConfigs.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, password);
sslConfigs.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyPassword);
}
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, trustStoreFile.getPath());
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, trustStorePassword);
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, "JKS");
sslConfigs.put(SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, TrustManagerFactory.getDefaultAlgorithm());
List<String> enabledProtocols = new ArrayList<>();
enabledProtocols.add("TLSv1.2");
sslConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, enabledProtocols);
return sslConfigs;
}
开发者ID:becketqin,项目名称:likafka-clients,代码行数:25,代码来源:TestSslUtils.java
示例6: configure
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
public void configure(TransportLayer transportLayer, PrincipalBuilder principalBuilder, Map<String, ?> configs) throws KafkaException {
try {
this.transportLayer = transportLayer;
this.configs = configs;
setSaslState(handshakeRequestEnable ? SaslState.SEND_HANDSHAKE_REQUEST : SaslState.INITIAL);
// determine client principal from subject.
if (!subject.getPrincipals().isEmpty()) {
Principal clientPrincipal = subject.getPrincipals().iterator().next();
this.clientPrincipalName = clientPrincipal.getName();
} else {
clientPrincipalName = null;
}
callbackHandler = new SaslClientCallbackHandler();
callbackHandler.configure(configs, Mode.CLIENT, subject, mechanism);
saslClient = createSaslClient();
} catch (Exception e) {
throw new KafkaException("Failed to configure SaslClientAuthenticator", e);
}
}
开发者ID:txazo,项目名称:kafka,代码行数:23,代码来源:SaslClientAuthenticator.java
示例7: createSaslServer
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
private void createSaslServer(String mechanism) throws IOException {
this.saslMechanism = mechanism;
callbackHandler = new SaslServerCallbackHandler(Configuration.getConfiguration(), kerberosNamer);
callbackHandler.configure(configs, Mode.SERVER, subject, saslMechanism);
if (mechanism.equals(SaslConfigs.GSSAPI_MECHANISM)) {
if (subject.getPrincipals().isEmpty())
throw new IllegalArgumentException("subject must have at least one principal");
saslServer = createSaslKerberosServer(callbackHandler, configs);
} else {
try {
saslServer = Subject.doAs(subject, new PrivilegedExceptionAction<SaslServer>() {
public SaslServer run() throws SaslException {
return Sasl.createSaslServer(saslMechanism, "kafka", host, configs, callbackHandler);
}
});
} catch (PrivilegedActionException e) {
throw new SaslException("Kafka Server failed to create a SaslServer to interact with a client during session authentication", e.getCause());
}
}
}
开发者ID:txazo,项目名称:kafka,代码行数:21,代码来源:SaslServerAuthenticator.java
示例8: createSslEngine
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
public SSLEngine createSslEngine(String peerHost, int peerPort) {
SSLEngine sslEngine = sslContext.createSSLEngine(peerHost, peerPort);
if (cipherSuites != null) sslEngine.setEnabledCipherSuites(cipherSuites);
if (enabledProtocols != null) sslEngine.setEnabledProtocols(enabledProtocols);
if (mode == Mode.SERVER) {
sslEngine.setUseClientMode(false);
if (needClientAuth)
sslEngine.setNeedClientAuth(needClientAuth);
else
sslEngine.setWantClientAuth(wantClientAuth);
} else {
sslEngine.setUseClientMode(true);
SSLParameters sslParams = sslEngine.getSSLParameters();
sslParams.setEndpointIdentificationAlgorithm(endpointIdentification);
sslEngine.setSSLParameters(sslParams);
}
return sslEngine;
}
开发者ID:txazo,项目名称:kafka,代码行数:20,代码来源:SslFactory.java
示例9: createSslConfig
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
private static Map<String, Object> createSslConfig(Mode mode, File keyStoreFile, Password password, Password keyPassword,
File trustStoreFile, Password trustStorePassword) {
Map<String, Object> sslConfigs = new HashMap<>();
sslConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.2"); // protocol to create SSLContext
if (mode == Mode.SERVER || (mode == Mode.CLIENT && keyStoreFile != null)) {
sslConfigs.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, keyStoreFile.getPath());
sslConfigs.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, "JKS");
sslConfigs.put(SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, TrustManagerFactory.getDefaultAlgorithm());
sslConfigs.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, password);
sslConfigs.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyPassword);
}
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, trustStoreFile.getPath());
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, trustStorePassword);
sslConfigs.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, "JKS");
sslConfigs.put(SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, TrustManagerFactory.getDefaultAlgorithm());
List<String> enabledProtocols = new ArrayList<>();
enabledProtocols.add("TLSv1.2");
sslConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, enabledProtocols);
return sslConfigs;
}
开发者ID:txazo,项目名称:kafka,代码行数:25,代码来源:TestSslUtils.java
示例10: testSslFactoryConfiguration
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
@Test
public void testSslFactoryConfiguration() throws Exception {
File trustStoreFile = File.createTempFile("truststore", ".jks");
Map<String, Object> serverSslConfig = TestSslUtils.createSslConfig(false, true, Mode.SERVER, trustStoreFile, "server");
SslFactory sslFactory = new SslFactory(Mode.SERVER);
sslFactory.configure(serverSslConfig);
//host and port are hints
SSLEngine engine = sslFactory.createSslEngine("localhost", 0);
assertNotNull(engine);
String[] expectedProtocols = {"TLSv1.2"};
assertArrayEquals(expectedProtocols, engine.getEnabledProtocols());
assertEquals(false, engine.getUseClientMode());
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:SslFactoryTest.java
示例11: testSslFactoryWithoutPasswordConfiguration
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
@Test
public void testSslFactoryWithoutPasswordConfiguration() throws Exception {
File trustStoreFile = File.createTempFile("truststore", ".jks");
Map<String, Object> serverSslConfig = TestSslUtils.createSslConfig(false, true, Mode.SERVER, trustStoreFile, "server");
// unset the password
serverSslConfig.remove(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG);
SslFactory sslFactory = new SslFactory(Mode.SERVER);
try {
sslFactory.configure(serverSslConfig);
} catch (Exception e) {
fail("An exception was thrown when configuring the truststore without a password: " + e);
}
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:SslFactoryTest.java
示例12: testClientMode
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
@Test
public void testClientMode() throws Exception {
File trustStoreFile = File.createTempFile("truststore", ".jks");
Map<String, Object> clientSslConfig = TestSslUtils.createSslConfig(false, true, Mode.CLIENT, trustStoreFile, "client");
SslFactory sslFactory = new SslFactory(Mode.CLIENT);
sslFactory.configure(clientSslConfig);
//host and port are hints
SSLEngine engine = sslFactory.createSslEngine("localhost", 0);
assertTrue(engine.getUseClientMode());
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:11,代码来源:SslFactoryTest.java
示例13: createChannelBuilder
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
/**
* @param configs client/server configs
* @return configured ChannelBuilder based on the configs.
*/
public static ChannelBuilder createChannelBuilder(Map<String, ?> configs) {
SecurityProtocol securityProtocol = SecurityProtocol.forName((String) configs.get(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG));
if (!SecurityProtocol.nonTestingValues().contains(securityProtocol))
throw new ConfigException("Invalid SecurityProtocol " + securityProtocol);
String clientSaslMechanism = (String) configs.get(SaslConfigs.SASL_MECHANISM);
return ChannelBuilders.create(securityProtocol, Mode.CLIENT, LoginType.CLIENT, configs, clientSaslMechanism, true);
}
开发者ID:txazo,项目名称:kafka,代码行数:12,代码来源:ClientUtils.java
示例14: buildConfig
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
public Map<Object, Object> buildConfig() {
applyDefaults();
validate();
Map<Object, Object> props = new HashMap<>();
StringJoiner csvJoiner = new StringJoiner(",");
if (plaintextPort >= 0) {
csvJoiner.add(SecurityProtocol.PLAINTEXT.name + "://localhost:" + plaintextPort);
}
if (sslPort >= 0) {
csvJoiner.add(SecurityProtocol.SSL.name + "://localhost:" + sslPort);
}
props.put("broker.id", Integer.toString(nodeId));
props.put("listeners", csvJoiner.toString());
props.put("log.dir", logDirectory.getAbsolutePath());
props.put("zookeeper.connect", zkConnect);
props.put("replica.socket.timeout.ms", Long.toString(socketTimeout));
props.put("controller.socket.timeout.ms", Long.toString(socketTimeout));
props.put("controlled.shutdown.enable", Boolean.toString(enableControlledShutdown));
props.put("delete.topic.enable", Boolean.toString(enableDeleteTopic));
props.put("controlled.shutdown.retry.backoff.ms", Long.toString(controlledShutdownRetryBackoff));
props.put("log.cleaner.dedupe.buffer.size", Long.toString(logCleanerDedupBufferSize));
props.put("log.cleaner.enable", Boolean.toString(enableLogCleaner));
if (rack != null) {
props.put("broker.rack", rack);
}
if (trustStore != null || sslPort > 0) {
try {
props.putAll(TestSslUtils.createSslConfig(false, true, Mode.SERVER, trustStore, "server" + nodeId));
//switch interbroker to ssl
props.put("security.inter.broker.protocol", "SSL");
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
return props;
}
开发者ID:linkedin,项目名称:li-apache-kafka-clients,代码行数:40,代码来源:EmbeddedBrokerBuilder.java
示例15: setSecurityConfigs
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
protected void setSecurityConfigs(Properties clientProps, String certAlias) {
SecurityProtocol protocol = securityProtocol();
if (protocol == SecurityProtocol.SSL) {
File trustStoreFile = trustStoreFile();
if (trustStoreFile == null) {
throw new AssertionError("ssl set but no trust store provided");
}
clientProps.setProperty(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, protocol.name);
try {
clientProps.putAll(TestSslUtils.createSslConfig(true, true, Mode.CLIENT, trustStoreFile, certAlias));
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
开发者ID:linkedin,项目名称:li-apache-kafka-clients,代码行数:16,代码来源:AbstractKafkaClientsIntegrationTestHarness.java
示例16: configure
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
@Override
public void configure(Map<String, ?> configs, Mode mode, Subject subject, String saslMechanism) {
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:4,代码来源:SaslServerCallbackHandler.java
示例17: configure
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
@Override
public void configure(Map<String, ?> configs, Mode mode, Subject subject, String mechanism) {
this.isKerberos = mechanism.equals(SaslConfigs.GSSAPI_MECHANISM);
this.subject = subject;
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:6,代码来源:SaslClientCallbackHandler.java
示例18: SslFactory
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
public SslFactory(Mode mode) {
this(mode, null);
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:4,代码来源:SslFactory.java
示例19: createSelector
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
private void createSelector(SecurityProtocol securityProtocol, Map<String, Object> clientConfigs) {
String saslMechanism = (String) saslClientConfigs.get(SaslConfigs.SASL_MECHANISM);
this.channelBuilder = ChannelBuilders.create(securityProtocol, Mode.CLIENT, LoginType.CLIENT, clientConfigs, saslMechanism, true);
this.selector = NetworkTestUtils.createSelector(channelBuilder);
}
开发者ID:txazo,项目名称:kafka,代码行数:6,代码来源:SaslAuthenticatorTest.java
示例20: configure
import org.apache.kafka.common.network.Mode; //导入依赖的package包/类
/**
* Configures this callback handler.
*
* @param configs Configuration
* @param mode The mode that indicates if this is a client or server connection
* @param subject Subject from login context
* @param saslMechanism Negotiated SASL mechanism
*/
void configure(Map<String, ?> configs, Mode mode, Subject subject, String saslMechanism);
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:AuthCallbackHandler.java
注:本文中的org.apache.kafka.common.network.Mode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论