java sasl例子_Java SaslConfigs類代碼示例

本文整理匯總了Java中org.apache.kafka.common.config.SaslConfigs類的典型用法代碼示例。如果您正苦於以下問題:Java SaslConfigs類的具體用法?Java SaslConfigs怎麽用?Java SaslConfigs使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。

SaslConfigs類屬於org.apache.kafka.common.config包,在下文中一共展示了SaslConfigs類的37個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: configure

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

public void configure(TransportLayer transportLayer, PrincipalBuilder principalBuilder, Map 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,

示例2: createSaslServer

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的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() {

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,

示例3: acquireLoginManager

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Returns an instance of `LoginManager` and increases its reference count.

*

* `release()` should be invoked when the `LoginManager` is no longer needed. This method will try to reuse an

* existing `LoginManager` for the provided context type and `SaslConfigs.SASL_JAAS_CONFIG` in `configs`,

* if available.

*

* This is a bit ugly and it would be nicer if we could pass the `LoginManager` to `ChannelBuilders.create` and

* shut it down when the broker or clients are closed. It's straightforward to do the former, but it's more

* complicated to do the latter without making the consumer API more complex.

*/

public static LoginManager acquireLoginManager(JaasContext jaasContext, boolean hasKerberos,

Map configs) throws IOException, LoginException {

synchronized (LoginManager.class) {

// SASL_JAAS_CONFIG is only supported by clients

LoginManager loginManager;

Password jaasConfigValue = (Password) configs.get(SaslConfigs.SASL_JAAS_CONFIG);

if (jaasContext.type() == JaasContext.Type.CLIENT && jaasConfigValue != null) {

loginManager = DYNAMIC_INSTANCES.get(jaasConfigValue);

if (loginManager == null) {

loginManager = new LoginManager(jaasContext, hasKerberos, configs, jaasConfigValue);

DYNAMIC_INSTANCES.put(jaasConfigValue, loginManager);

}

} else {

loginManager = STATIC_INSTANCES.get(jaasContext.name());

if (loginManager == null) {

loginManager = new LoginManager(jaasContext, hasKerberos, configs, jaasConfigValue);

STATIC_INSTANCES.put(jaasContext.name(), loginManager);

}

}

return loginManager.acquire();

}

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:34,

示例4: load

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

static JaasContext load(JaasContext.Type contextType, String listenerContextName,

String globalContextName, Map configs) {

Password jaasConfigArgs = (Password) configs.get(SaslConfigs.SASL_JAAS_CONFIG);

if (jaasConfigArgs != null) {

if (contextType == JaasContext.Type.SERVER)

throw new IllegalArgumentException("JAAS config property not supported for server");

else {

JaasConfig jaasConfig = new JaasConfig(globalContextName, jaasConfigArgs.value());

AppConfigurationEntry[] clientModules = jaasConfig.getAppConfigurationEntry(globalContextName);

int numModules = clientModules == null ? 0 : clientModules.length;

if (numModules != 1)

throw new IllegalArgumentException("JAAS config property contains " + numModules + " login modules, should be 1 module");

return new JaasContext(globalContextName, contextType, jaasConfig);

}

} else

return defaultContext(contextType, listenerContextName, globalContextName);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:18,

示例5: getServiceName

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private static String getServiceName(Map 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,

示例6: testMultipleServerMechanisms

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Tests that servers supporting multiple SASL mechanisms work with clients using

* any of the enabled mechanisms.

*/

@Test

public void testMultipleServerMechanisms() throws Exception {

SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;

configureMechanisms("DIGEST-MD5", Arrays.asList("DIGEST-MD5", "PLAIN", "SCRAM-SHA-256"));

server = createEchoServer(securityProtocol);

updateScramCredentialCache(TestJaasConfig.USERNAME, TestJaasConfig.PASSWORD);

String node1 = "1";

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "PLAIN");

createAndCheckClientConnection(securityProtocol, node1);

String node2 = "2";

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "DIGEST-MD5");

createSelector(securityProtocol, saslClientConfigs);

InetSocketAddress addr = new InetSocketAddress("127.0.0.1", server.port());

selector.connect(node2, addr, BUFFER_SIZE, BUFFER_SIZE);

NetworkTestUtils.checkClientConnection(selector, node2, 100, 10);

String node3 = "3";

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "SCRAM-SHA-256");

createSelector(securityProtocol, saslClientConfigs);

selector.connect(node3, new InetSocketAddress("127.0.0.1", server.port()), BUFFER_SIZE, BUFFER_SIZE);

NetworkTestUtils.checkClientConnection(selector, node3, 100, 10);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:29,

示例7: testUserCredentialsUnavailableForScramMechanism

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Tests that SASL/SCRAM clients fail authentication if credentials are not available for

* the specific SCRAM mechanism.

*/

@Test

public void testUserCredentialsUnavailableForScramMechanism() throws Exception {

SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;

configureMechanisms("SCRAM-SHA-256", new ArrayList<>(ScramMechanism.mechanismNames()));

server = createEchoServer(securityProtocol);

updateScramCredentialCache(TestJaasConfig.USERNAME, TestJaasConfig.PASSWORD);

server.credentialCache().cache(ScramMechanism.SCRAM_SHA_256.mechanismName(), ScramCredential.class).remove(TestJaasConfig.USERNAME);

String node = "1";

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "SCRAM-SHA-256");

createAndCheckClientConnectionFailure(securityProtocol, node);

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "SCRAM-SHA-512");

createAndCheckClientConnection(securityProtocol, "2");

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:20,

示例8: configurationEntry

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private AppConfigurationEntry configurationEntry(JaasContext.Type contextType, String jaasConfigProp) {

Map configs = new HashMap<>();

if (jaasConfigProp != null)

configs.put(SaslConfigs.SASL_JAAS_CONFIG, new Password(jaasConfigProp));

JaasContext context = JaasContext.load(contextType, null, contextType.name(), configs);

List entries = context.configurationEntries();

assertEquals(1, entries.size());

return entries.get(0);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:10,

示例9: createSaslServer

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的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() {

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,

示例10: getServiceName

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private String getServiceName(Map 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,

示例11: testMultipleServerMechanisms

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Tests that servers supporting multiple SASL mechanisms work with clients using

* any of the enabled mechanisms.

*/

@Test

public void testMultipleServerMechanisms() throws Exception {

SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;

configureMechanisms("DIGEST-MD5", Arrays.asList("DIGEST-MD5", "PLAIN"));

server = NetworkTestUtils.createEchoServer(securityProtocol, saslServerConfigs);

String node1 = "1";

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "PLAIN");

createAndCheckClientConnection(securityProtocol, node1);

String node2 = "2";

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "DIGEST-MD5");

createSelector(securityProtocol, saslClientConfigs);

InetSocketAddress addr = new InetSocketAddress("127.0.0.1", server.port());

selector.connect(node2, addr, BUFFER_SIZE, BUFFER_SIZE);

NetworkTestUtils.checkClientConnection(selector, node2, 100, 10);

}

開發者ID:txazo,項目名稱:kafka,代碼行數:22,

示例12: getServiceName

​點讚 3

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private String getServiceName(Map 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,

示例13: testConfigFromStreamsConfig

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

@Test

public void testConfigFromStreamsConfig() {

for (final String expectedMechanism : asList("PLAIN", "SCRAM-SHA-512")) {

final Properties props = new Properties();

props.setProperty(StreamsConfig.APPLICATION_ID_CONFIG, "some_app_id");

props.setProperty(SaslConfigs.SASL_MECHANISM, expectedMechanism);

props.setProperty(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9000");

final StreamsConfig streamsConfig = new StreamsConfig(props);

final AbstractConfig config = StreamsKafkaClient.Config.fromStreamsConfig(streamsConfig);

assertEquals(expectedMechanism, config.values().get(SaslConfigs.SASL_MECHANISM));

assertEquals(expectedMechanism, config.getString(SaslConfigs.SASL_MECHANISM));

}

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:14,

示例14: createChannelBuilder

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* @param config client configs

* @return configured ChannelBuilder based on the configs.

*/

public static ChannelBuilder createChannelBuilder(AbstractConfig config) {

// 根據security.protocol配置項的值,得到對應的securityprotocal對象

SecurityProtocol securityProtocol = SecurityProtocol.forName(config.getString(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG));

if (!SecurityProtocol.nonTestingValues().contains(securityProtocol))

throw new ConfigException("Invalid SecurityProtocol " + securityProtocol);

// 獲取sasl.mechanism配置項的值

String clientSaslMechanism = config.getString(SaslConfigs.SASL_MECHANISM);

// 創建對應的ChannelBuilder對象

return ChannelBuilders.clientChannelBuilder(securityProtocol, JaasContext.Type.CLIENT, config, null,

clientSaslMechanism, true);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:18,

示例15: configure

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

public void configure(TransportLayer transportLayer, PrincipalBuilder principalBuilder, Map configs) {

this.transportLayer = transportLayer;

this.configs = configs;

List enabledMechanisms = (List) this.configs.get(SaslConfigs.SASL_ENABLED_MECHANISMS);

if (enabledMechanisms == null || enabledMechanisms.isEmpty())

throw new IllegalArgumentException("No SASL mechanisms are enabled");

this.enabledMechanisms = new HashSet<>(enabledMechanisms);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:9,

示例16: defaultContext

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private static JaasContext defaultContext(JaasContext.Type contextType, String listenerContextName,

String globalContextName) {

String jaasConfigFile = System.getProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM);

if (jaasConfigFile == null) {

if (contextType == Type.CLIENT) {

LOG.debug("System property '" + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' and Kafka SASL property '" +

SaslConfigs.SASL_JAAS_CONFIG + "' are not set, using default JAAS configuration.");

} else {

LOG.debug("System property '" + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' is not set, using default JAAS " +

"configuration.");

}

}

Configuration jaasConfig = Configuration.getConfiguration();

AppConfigurationEntry[] configEntries = null;

String contextName = globalContextName;

if (listenerContextName != null) {

configEntries = jaasConfig.getAppConfigurationEntry(listenerContextName);

if (configEntries != null)

contextName = listenerContextName;

}

if (configEntries == null)

configEntries = jaasConfig.getAppConfigurationEntry(globalContextName);

if (configEntries == null) {

String listenerNameText = listenerContextName == null ? "" : " or '" + listenerContextName + "'";

String errorMessage = "Could not find a '" + globalContextName + "'" + listenerNameText + " entry in the JAAS " +

"configuration. System property '" + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' is " +

(jaasConfigFile == null ? "not set" : jaasConfigFile);

throw new IllegalArgumentException(errorMessage);

}

return new JaasContext(contextName, contextType, jaasConfig);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:38,

示例17: configure

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

public void configure(Map configs, JaasContext jaasContext) {

super.configure(configs, jaasContext);

this.ticketRenewWindowFactor = (Double) configs.get(SaslConfigs.SASL_KERBEROS_TICKET_RENEW_WINDOW_FACTOR);

this.ticketRenewJitter = (Double) configs.get(SaslConfigs.SASL_KERBEROS_TICKET_RENEW_JITTER);

this.minTimeBeforeRelogin = (Long) configs.get(SaslConfigs.SASL_KERBEROS_MIN_TIME_BEFORE_RELOGIN);

this.kinitCmd = (String) configs.get(SaslConfigs.SASL_KERBEROS_KINIT_CMD);

this.serviceName = getServiceName(configs, jaasContext);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:9,

示例18: configure

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

public void configure(Map configs) throws KafkaException {

try {

this.configs = configs;

boolean hasKerberos;

if (mode == Mode.SERVER) {

List enabledMechanisms = (List) this.configs.get(SaslConfigs.SASL_ENABLED_MECHANISMS);

hasKerberos = enabledMechanisms == null || enabledMechanisms.contains(SaslConfigs.GSSAPI_MECHANISM);

} else {

hasKerberos = clientSaslMechanism.equals(SaslConfigs.GSSAPI_MECHANISM);

}

if (hasKerberos) {

String defaultRealm;

try {

defaultRealm = defaultKerberosRealm();

} catch (Exception ke) {

defaultRealm = "";

}

@SuppressWarnings("unchecked")

List principalToLocalRules = (List) configs.get(SaslConfigs.SASL_KERBEROS_PRINCIPAL_TO_LOCAL_RULES);

if (principalToLocalRules != null)

kerberosShortNamer = KerberosShortNamer.fromUnparsedRules(defaultRealm, principalToLocalRules);

}

this.loginManager = LoginManager.acquireLoginManager(jaasContext, hasKerberos, configs);

if (this.securityProtocol == SecurityProtocol.SASL_SSL) {

// Disable SSL client authentication as we are using SASL authentication

this.sslFactory = new SslFactory(mode, "none");

this.sslFactory.configure(configs);

}

} catch (Exception e) {

throw new KafkaException(e);

}

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:35,

示例19: testValidSaslScramMechanisms

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Tests all supported SCRAM client and server channels. Also tests that all

* supported SCRAM mechanisms can be supported simultaneously on a server.

*/

@Test

public void testValidSaslScramMechanisms() throws Exception {

SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;

configureMechanisms("SCRAM-SHA-256", new ArrayList<>(ScramMechanism.mechanismNames()));

server = createEchoServer(securityProtocol);

updateScramCredentialCache(TestJaasConfig.USERNAME, TestJaasConfig.PASSWORD);

for (String mechanism : ScramMechanism.mechanismNames()) {

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, mechanism);

createAndCheckClientConnection(securityProtocol, "node-" + mechanism);

}

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:17,

示例20: testInvalidMechanism

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Tests that clients using invalid SASL mechanisms fail authentication.

*/

@Test

public void testInvalidMechanism() throws Exception {

String node = "0";

SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;

configureMechanisms("PLAIN", Arrays.asList("PLAIN"));

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "INVALID");

server = createEchoServer(securityProtocol);

createAndCheckClientConnectionFailure(securityProtocol, node);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:14,

示例21: testJaasConfigurationForListener

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

@Test

public void testJaasConfigurationForListener() throws Exception {

SecurityProtocol securityProtocol = SecurityProtocol.SASL_PLAINTEXT;

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "PLAIN");

saslServerConfigs.put(SaslConfigs.SASL_ENABLED_MECHANISMS, Arrays.asList("PLAIN"));

TestJaasConfig staticJaasConfig = new TestJaasConfig();

Map globalServerOptions = new HashMap<>();

globalServerOptions.put("user_global1", "gsecret1");

globalServerOptions.put("user_global2", "gsecret2");

staticJaasConfig.createOrUpdateEntry(TestJaasConfig.LOGIN_CONTEXT_SERVER, PlainLoginModule.class.getName(),

globalServerOptions);

Map clientListenerServerOptions = new HashMap<>();

clientListenerServerOptions.put("user_client1", "csecret1");

clientListenerServerOptions.put("user_client2", "csecret2");

String clientJaasEntryName = "client." + TestJaasConfig.LOGIN_CONTEXT_SERVER;

staticJaasConfig.createOrUpdateEntry(clientJaasEntryName, PlainLoginModule.class.getName(), clientListenerServerOptions);

Configuration.setConfiguration(staticJaasConfig);

// Listener-specific credentials

server = createEchoServer(new ListenerName("client"), securityProtocol);

saslClientConfigs.put(SaslConfigs.SASL_JAAS_CONFIG,

TestJaasConfig.jaasConfigProperty("PLAIN", "client1", "csecret1"));

createAndCheckClientConnection(securityProtocol, "1");

saslClientConfigs.put(SaslConfigs.SASL_JAAS_CONFIG,

TestJaasConfig.jaasConfigProperty("PLAIN", "global1", "gsecret1"));

createAndCheckClientConnectionFailure(securityProtocol, "2");

server.close();

// Global credentials as there is no listener-specific JAAS entry

server = createEchoServer(new ListenerName("other"), securityProtocol);

saslClientConfigs.put(SaslConfigs.SASL_JAAS_CONFIG,

TestJaasConfig.jaasConfigProperty("PLAIN", "global1", "gsecret1"));

createAndCheckClientConnection(securityProtocol, "3");

saslClientConfigs.put(SaslConfigs.SASL_JAAS_CONFIG,

TestJaasConfig.jaasConfigProperty("PLAIN", "client1", "csecret1"));

createAndCheckClientConnectionFailure(securityProtocol, "4");

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:41,

示例22: createSelector

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private void createSelector(SecurityProtocol securityProtocol, Map clientConfigs) {

if (selector != null) {

selector.close();

selector = null;

}

String saslMechanism = (String) saslClientConfigs.get(SaslConfigs.SASL_MECHANISM);

this.channelBuilder = ChannelBuilders.clientChannelBuilder(securityProtocol, JaasContext.Type.CLIENT,

new TestSecurityConfig(clientConfigs), null, saslMechanism, true);

this.selector = NetworkTestUtils.createSelector(channelBuilder);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:12,

示例23: updateScramCredentialCache

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

@SuppressWarnings("unchecked")

private void updateScramCredentialCache(String username, String password) throws NoSuchAlgorithmException {

for (String mechanism : (List) saslServerConfigs.get(SaslConfigs.SASL_ENABLED_MECHANISMS)) {

ScramMechanism scramMechanism = ScramMechanism.forMechanismName(mechanism);

if (scramMechanism != null) {

ScramFormatter formatter = new ScramFormatter(scramMechanism);

ScramCredential credential = formatter.generateCredential(password, 4096);

server.credentialCache().cache(scramMechanism.mechanismName(), ScramCredential.class).put(username, credential);

}

}

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:12,

示例24: createChannelBuilder

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* @param configs client/server configs

* @return configured ChannelBuilder based on the configs.

*/

public static ChannelBuilder createChannelBuilder(Map 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,

示例25: configure

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

public void configure(Map configs) throws KafkaException {

try {

this.configs = configs;

boolean hasKerberos;

if (mode == Mode.SERVER) {

List enabledMechanisms = (List) this.configs.get(SaslConfigs.SASL_ENABLED_MECHANISMS);

hasKerberos = enabledMechanisms == null || enabledMechanisms.contains(SaslConfigs.GSSAPI_MECHANISM);

} else {

hasKerberos = clientSaslMechanism.equals(SaslConfigs.GSSAPI_MECHANISM);

}

if (hasKerberos) {

String defaultRealm;

try {

defaultRealm = JaasUtils.defaultKerberosRealm();

} catch (Exception ke) {

defaultRealm = "";

}

@SuppressWarnings("unchecked")

List principalToLocalRules = (List) configs.get(SaslConfigs.SASL_KERBEROS_PRINCIPAL_TO_LOCAL_RULES);

if (principalToLocalRules != null)

kerberosShortNamer = KerberosShortNamer.fromUnparsedRules(defaultRealm, principalToLocalRules);

}

this.loginManager = LoginManager.acquireLoginManager(loginType, hasKerberos, configs);

if (this.securityProtocol == SecurityProtocol.SASL_SSL) {

// Disable SSL client authentication as we are using SASL authentication

this.sslFactory = new SslFactory(mode, "none");

this.sslFactory.configure(configs);

}

} catch (Exception e) {

throw new KafkaException(e);

}

}

開發者ID:txazo,項目名稱:kafka,代碼行數:35,

示例26: testInvalidMechanism

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Tests that clients using invalid SASL mechanisms fail authentication.

*/

@Test

public void testInvalidMechanism() throws Exception {

String node = "0";

SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;

configureMechanisms("PLAIN", Arrays.asList("PLAIN"));

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "INVALID");

server = NetworkTestUtils.createEchoServer(securityProtocol, saslServerConfigs);

createClientConnection(securityProtocol, node);

NetworkTestUtils.waitForChannelClose(selector, node);

}

開發者ID:txazo,項目名稱:kafka,代碼行數:15,

示例27: getProducerKeys

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private Properties getProducerKeys() {

Properties props = new Properties();

props.put(ProducerConfig.ACKS_CONFIG, "1");

props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, "33554432");

props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "none");

props.put(ProducerConfig.RETRIES_CONFIG, "0");

props.put(ProducerConfig.BATCH_SIZE_CONFIG, "16384");

props.put(ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG, "540000");

props.put(ProducerConfig.LINGER_MS_CONFIG, "0");

props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, "60000");

props.put(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, "1048576");

props.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, KafkaConstants.KAFKA_DEFAULT_PARTITIONER);

props.put(ProducerConfig.RECEIVE_BUFFER_CONFIG, "32768");

props.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, "30000");

props.put(ProducerConfig.SEND_BUFFER_CONFIG, "131072");

props.put(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, "5");

props.put(ProducerConfig.METADATA_MAX_AGE_CONFIG, "300000");

props.put(ProducerConfig.METRICS_NUM_SAMPLES_CONFIG, "2");

props.put(ProducerConfig.METRICS_SAMPLE_WINDOW_MS_CONFIG, "30000");

props.put(ProducerConfig.RECONNECT_BACKOFF_MS_CONFIG, "50");

props.put(ProducerConfig.RETRY_BACKOFF_MS_CONFIG, "100");

props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaConstants.KAFKA_DEFAULT_SERIALIZER);

props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, KafkaConstants.KAFKA_DEFAULT_SERIALIZER);

props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "PLAINTEXT");

props.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, "TLSv1.2, TLSv1.1, TLSv1");

props.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, "JKS");

props.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLS");

props.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, "JKS");

props.put(SaslConfigs.SASL_KERBEROS_KINIT_CMD, "/usr/bin/kinit");

props.put(SaslConfigs.SASL_KERBEROS_MIN_TIME_BEFORE_RELOGIN, "60000");

props.put(SaslConfigs.SASL_KERBEROS_TICKET_RENEW_JITTER, "0.05");

props.put(SaslConfigs.SASL_KERBEROS_TICKET_RENEW_WINDOW_FACTOR, "0.8");

props.put(SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, "SunX509");

props.put(SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, "PKIX");

return props;

}

開發者ID:HydAu,項目名稱:Camel,代碼行數:39,

示例28: getServiceName

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private static String getServiceName(String loginContext, Map configs) throws IOException {

// BEGIN changes for SDC-2430

// Comment out existing implementation of this method which looks up service names from both

// kafka client jaas file as well as client configuration.

// Support reading service name from "sasl.kerberos.service.name" client configuration.

/*

String jaasServiceName = JaasUtils.jaasConfig(loginContext, JaasUtils.SERVICE_NAME);

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");

*/

String configServiceName = (String) configs.get(SaslConfigs.SASL_KERBEROS_SERVICE_NAME);

if (configServiceName != null) {

return configServiceName;

}

throw new IllegalArgumentException("No serviceName defined in Kafka config. " +

"Please specify the kafka service name using the \"sasl.kerberos.service.name\" configuration in the client.");

// END changes for SDC-2430

}

開發者ID:streamsets,項目名稱:datacollector,代碼行數:34,

示例29: handleKafkaRequest

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private boolean handleKafkaRequest(byte[] requestBytes) throws IOException, AuthenticationException {

boolean isKafkaRequest = false;

String clientMechanism = null;

try {

ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes);

RequestHeader requestHeader = RequestHeader.parse(requestBuffer);

ApiKeys apiKey = ApiKeys.forId(requestHeader.apiKey());

// A valid Kafka request header was received. SASL authentication tokens are now expected only

// following a SaslHandshakeRequest since this is not a GSSAPI client token from a Kafka 0.9.0.x client.

// 狀態切換

setSaslState(SaslState.HANDSHAKE_REQUEST);

isKafkaRequest = true;

// 檢測apikye、version是否合法

if (!Protocol.apiVersionSupported(requestHeader.apiKey(), requestHeader.apiVersion())) {

if (apiKey == ApiKeys.API_VERSIONS)

sendKafkaResponse(ApiVersionsResponse.unsupportedVersionSend(node, requestHeader));

else

throw new UnsupportedVersionException("Version " + requestHeader.apiVersion() + " is not supported for apiKey " + apiKey);

} else {

AbstractRequest request = AbstractRequest.getRequest(requestHeader.apiKey(), requestHeader.apiVersion(),

requestBuffer).request;

LOG.debug("Handle Kafka request {}", apiKey);

switch (apiKey) {

case API_VERSIONS:

handleApiVersionsRequest(requestHeader);

break;

case SASL_HANDSHAKE:

clientMechanism = handleHandshakeRequest(requestHeader, (SaslHandshakeRequest) request);

break;

default:

throw new IllegalSaslStateException("Unexpected Kafka request of type " + apiKey + " during SASL handshake.");

}

}

} catch (SchemaException | IllegalArgumentException e) {

if (saslState == SaslState.GSSAPI_OR_HANDSHAKE_REQUEST) {

// SchemaException is thrown if the request is not in Kafka format. IllegalArgumentException is thrown

// if the API key is invalid. For compatibility with 0.9.0.x where the first packet is a GSSAPI token

// starting with 0x60, revert to GSSAPI for both these exceptions.

if (LOG.isDebugEnabled()) {

StringBuilder tokenBuilder = new StringBuilder();

for (byte b : requestBytes) {

tokenBuilder.append(String.format("%02x", b));

if (tokenBuilder.length() >= 20)

break;

}

LOG.debug("Received client packet of length {} starting with bytes 0x{}, process as GSSAPI packet", requestBytes.length, tokenBuilder);

}

if (enabledMechanisms.contains(SaslConfigs.GSSAPI_MECHANISM)) {

LOG.debug("First client packet is not a SASL mechanism request, using default mechanism GSSAPI");

clientMechanism = SaslConfigs.GSSAPI_MECHANISM;

} else

throw new UnsupportedSaslMechanismException("Exception handling first SASL packet from client, GSSAPI is not supported by server", e);

} else

throw e;

}

if (clientMechanism != null) {

// sasl機製檢測通過,創建PlainSaslServer

createSaslServer(clientMechanism);

setSaslState(SaslState.AUTHENTICATE);

}

return isKafkaRequest;

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:66,

示例30: configure

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

@Override

public void configure(Map 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,

示例31: testDynamicJaasConfiguration

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Tests dynamic JAAS configuration property for SASL clients. Invalid client credentials

* are set in the static JVM-wide configuration instance to ensure that the dynamic

* property override is used during authentication.

*/

@Test

public void testDynamicJaasConfiguration() throws Exception {

SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "PLAIN");

saslServerConfigs.put(SaslConfigs.SASL_ENABLED_MECHANISMS, Arrays.asList("PLAIN"));

Map serverOptions = new HashMap<>();

serverOptions.put("user_user1", "user1-secret");

serverOptions.put("user_user2", "user2-secret");

TestJaasConfig staticJaasConfig = new TestJaasConfig();

staticJaasConfig.createOrUpdateEntry(TestJaasConfig.LOGIN_CONTEXT_SERVER, PlainLoginModule.class.getName(),

serverOptions);

staticJaasConfig.setPlainClientOptions("user1", "invalidpassword");

Configuration.setConfiguration(staticJaasConfig);

server = createEchoServer(securityProtocol);

// Check that client using static Jaas config does not connect since password is invalid

createAndCheckClientConnectionFailure(securityProtocol, "1");

// Check that 'user1' can connect with a Jaas config property override

saslClientConfigs.put(SaslConfigs.SASL_JAAS_CONFIG, TestJaasConfig.jaasConfigProperty("PLAIN", "user1", "user1-secret"));

createAndCheckClientConnection(securityProtocol, "2");

// Check that invalid password specified as Jaas config property results in connection failure

saslClientConfigs.put(SaslConfigs.SASL_JAAS_CONFIG, TestJaasConfig.jaasConfigProperty("PLAIN", "user1", "user2-secret"));

createAndCheckClientConnectionFailure(securityProtocol, "3");

// Check that another user 'user2' can also connect with a Jaas config override without any changes to static configuration

saslClientConfigs.put(SaslConfigs.SASL_JAAS_CONFIG, TestJaasConfig.jaasConfigProperty("PLAIN", "user2", "user2-secret"));

createAndCheckClientConnection(securityProtocol, "4");

// Check that clients specifying multiple login modules fail even if the credentials are valid

String module1 = TestJaasConfig.jaasConfigProperty("PLAIN", "user1", "user1-secret").value();

String module2 = TestJaasConfig.jaasConfigProperty("PLAIN", "user2", "user2-secret").value();

saslClientConfigs.put(SaslConfigs.SASL_JAAS_CONFIG, new Password(module1 + " " + module2));

try {

createClientConnection(securityProtocol, "1");

fail("Connection created with multiple login modules in sasl.jaas.config");

} catch (IllegalArgumentException e) {

// Expected

}

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:47,

示例32: configureMechanisms

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private TestJaasConfig configureMechanisms(String clientMechanism, List serverMechanisms) {

saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, clientMechanism);

saslServerConfigs.put(SaslConfigs.SASL_ENABLED_MECHANISMS, serverMechanisms);

return TestJaasConfig.createConfiguration(clientMechanism, serverMechanisms);

}

開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:6,

示例33: handleKafkaRequest

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private boolean handleKafkaRequest(byte[] requestBytes) throws IOException, AuthenticationException {

boolean isKafkaRequest = false;

String clientMechanism = null;

try {

ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes);

RequestHeader requestHeader = RequestHeader.parse(requestBuffer);

ApiKeys apiKey = ApiKeys.forId(requestHeader.apiKey());

// A valid Kafka request header was received. SASL authentication tokens are now expected only

// following a SaslHandshakeRequest since this is not a GSSAPI client token from a Kafka 0.9.0.x client.

setSaslState(SaslState.HANDSHAKE_REQUEST);

isKafkaRequest = true;

if (!Protocol.apiVersionSupported(requestHeader.apiKey(), requestHeader.apiVersion())) {

if (apiKey == ApiKeys.API_VERSIONS)

sendKafkaResponse(requestHeader, ApiVersionsResponse.fromError(Errors.UNSUPPORTED_VERSION));

else

throw new UnsupportedVersionException("Version " + requestHeader.apiVersion() + " is not supported for apiKey " + apiKey);

} else {

AbstractRequest request = AbstractRequest.getRequest(requestHeader.apiKey(), requestHeader.apiVersion(), requestBuffer);

LOG.debug("Handle Kafka request {}", apiKey);

switch (apiKey) {

case API_VERSIONS:

handleApiVersionsRequest(requestHeader, (ApiVersionsRequest) request);

break;

case SASL_HANDSHAKE:

clientMechanism = handleHandshakeRequest(requestHeader, (SaslHandshakeRequest) request);

break;

default:

throw new IllegalSaslStateException("Unexpected Kafka request of type " + apiKey + " during SASL handshake.");

}

}

} catch (SchemaException | IllegalArgumentException e) {

if (saslState == SaslState.GSSAPI_OR_HANDSHAKE_REQUEST) {

// SchemaException is thrown if the request is not in Kafka format. IIlegalArgumentException is thrown

// if the API key is invalid. For compatibility with 0.9.0.x where the first packet is a GSSAPI token

// starting with 0x60, revert to GSSAPI for both these exceptions.

if (LOG.isDebugEnabled()) {

StringBuilder tokenBuilder = new StringBuilder();

for (byte b : requestBytes) {

tokenBuilder.append(String.format("%02x", b));

if (tokenBuilder.length() >= 20)

break;

}

LOG.debug("Received client packet of length {} starting with bytes 0x{}, process as GSSAPI packet", requestBytes.length, tokenBuilder);

}

if (enabledMechanisms.contains(SaslConfigs.GSSAPI_MECHANISM)) {

LOG.debug("First client packet is not a SASL mechanism request, using default mechanism GSSAPI");

clientMechanism = SaslConfigs.GSSAPI_MECHANISM;

} else

throw new UnsupportedSaslMechanismException("Exception handling first SASL packet from client, GSSAPI is not supported by server", e);

} else

throw e;

}

if (clientMechanism != null) {

createSaslServer(clientMechanism);

setSaslState(SaslState.AUTHENTICATE);

}

return isKafkaRequest;

}

開發者ID:txazo,項目名稱:kafka,代碼行數:61,

示例34: createSelector

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

private void createSelector(SecurityProtocol securityProtocol, Map 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,

示例35: createProducerProperties

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

public Properties createProducerProperties() {

Properties props = new Properties();

addPropertyIfNotNull(props, ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, getKeySerializerClass());

addPropertyIfNotNull(props, ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, getSerializerClass());

addPropertyIfNotNull(props, ProducerConfig.ACKS_CONFIG, getRequestRequiredAcks());

addPropertyIfNotNull(props, ProducerConfig.BUFFER_MEMORY_CONFIG, getBufferMemorySize());

addPropertyIfNotNull(props, ProducerConfig.COMPRESSION_TYPE_CONFIG, getCompressionCodec());

addPropertyIfNotNull(props, ProducerConfig.RETRIES_CONFIG, getRetries());

// SSL

addPropertyIfNotNull(props, SslConfigs.SSL_KEY_PASSWORD_CONFIG, getSslKeyPassword());

addPropertyIfNotNull(props, SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, getSslKeystoreLocation());

addPropertyIfNotNull(props, SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, getSslKeystorePassword());

addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, getSslTruststoreLocation());

addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, getSslTruststorePassword());

addPropertyIfNotNull(props, ProducerConfig.SEND_BUFFER_CONFIG, getRetries());

addPropertyIfNotNull(props, ProducerConfig.BATCH_SIZE_CONFIG, getProducerBatchSize());

addPropertyIfNotNull(props, ProducerConfig.CLIENT_ID_CONFIG, getClientId());

addPropertyIfNotNull(props, ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG, getConnectionMaxIdleMs());

addPropertyIfNotNull(props, ProducerConfig.LINGER_MS_CONFIG, getLingerMs());

addPropertyIfNotNull(props, ProducerConfig.MAX_BLOCK_MS_CONFIG, getMaxBlockMs());

addPropertyIfNotNull(props, ProducerConfig.MAX_REQUEST_SIZE_CONFIG, getMaxRequestSize());

addPropertyIfNotNull(props, ProducerConfig.PARTITIONER_CLASS_CONFIG, getPartitioner());

addPropertyIfNotNull(props, ProducerConfig.RECEIVE_BUFFER_CONFIG, getReceiveBufferBytes());

addPropertyIfNotNull(props, ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, getRequestTimeoutMs());

//SASL

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_SERVICE_NAME, getSaslKerberosServiceName());

// Security protocol

addPropertyIfNotNull(props, CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, getSecurityProtocol());

addPropertyIfNotNull(props, ProducerConfig.SEND_BUFFER_CONFIG, getSendBufferBytes());

//SSL

addPropertyIfNotNull(props, SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, getSslEnabledProtocols());

addPropertyIfNotNull(props, SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, getSslKeystoreType());

addPropertyIfNotNull(props, SslConfigs.SSL_PROTOCOL_CONFIG, getSslProtocol());

addPropertyIfNotNull(props, SslConfigs.SSL_PROVIDER_CONFIG, getSslProvider());

addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, getSslTruststoreType());

addPropertyIfNotNull(props, ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, getMaxInFlightRequest());

addPropertyIfNotNull(props, ProducerConfig.METADATA_MAX_AGE_CONFIG, getMetadataMaxAgeMs());

addPropertyIfNotNull(props, ProducerConfig.METRIC_REPORTER_CLASSES_CONFIG, getMetricReporters());

addPropertyIfNotNull(props, ProducerConfig.METRICS_NUM_SAMPLES_CONFIG, getNoOfMetricsSample());

addPropertyIfNotNull(props, ProducerConfig.METRICS_SAMPLE_WINDOW_MS_CONFIG, getMetricsSampleWindowMs());

addPropertyIfNotNull(props, ProducerConfig.RECONNECT_BACKOFF_MS_CONFIG, getReconnectBackoffMs());

addPropertyIfNotNull(props, ProducerConfig.RETRY_BACKOFF_MS_CONFIG, getRetryBackoffMs());

//SASL

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_KINIT_CMD, getKerberosInitCmd());

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_MIN_TIME_BEFORE_RELOGIN, getKerberosBeforeReloginMinTime());

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_TICKET_RENEW_JITTER, getKerberosRenewJitter());

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_TICKET_RENEW_WINDOW_FACTOR, getKerberosRenewWindowFactor());

//SSL

addPropertyIfNotNull(props, SslConfigs.SSL_CIPHER_SUITES_CONFIG, getSslCipherSuites());

addPropertyIfNotNull(props, SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, getSslEndpointAlgorithm());

addPropertyIfNotNull(props, SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, getSslKeymanagerAlgorithm());

addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, getSslTrustmanagerAlgorithm());

return props;

}

開發者ID:HydAu,項目名稱:Camel,代碼行數:56,

示例36: createConsumerProperties

​點讚 2

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

public Properties createConsumerProperties() {

Properties props = new Properties();

addPropertyIfNotNull(props, ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, getKeyDeserializer());

addPropertyIfNotNull(props, ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, getValueDeserializer());

addPropertyIfNotNull(props, ConsumerConfig.FETCH_MIN_BYTES_CONFIG, getFetchMinBytes());

addPropertyIfNotNull(props, ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, getHeartbeatIntervalMs());

addPropertyIfNotNull(props, ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, getMaxPartitionFetchBytes());

addPropertyIfNotNull(props, ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, getSessionTimeoutMs());

// SSL

addPropertyIfNotNull(props, SslConfigs.SSL_KEY_PASSWORD_CONFIG, getSslKeyPassword());

addPropertyIfNotNull(props, SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, getSslKeystoreLocation());

addPropertyIfNotNull(props, SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, getSslKeystorePassword());

addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, getSslTruststoreLocation());

addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, getSslTruststorePassword());

addPropertyIfNotNull(props, ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, getAutoOffsetReset());

addPropertyIfNotNull(props, ConsumerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG, getConnectionMaxIdleMs());

addPropertyIfNotNull(props, ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, isAutoCommitEnable());

addPropertyIfNotNull(props, ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, getPartitionAssignor());

addPropertyIfNotNull(props, ConsumerConfig.RECEIVE_BUFFER_CONFIG, getReceiveBufferBytes());

addPropertyIfNotNull(props, ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, getConsumerRequestTimeoutMs());

//SASL

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_SERVICE_NAME, getSaslKerberosServiceName());

// Security protocol

addPropertyIfNotNull(props, CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, getSecurityProtocol());

addPropertyIfNotNull(props, ProducerConfig.SEND_BUFFER_CONFIG, getSendBufferBytes());

//SSL

addPropertyIfNotNull(props, SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, getSslEnabledProtocols());

addPropertyIfNotNull(props, SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, getSslKeystoreType());

addPropertyIfNotNull(props, SslConfigs.SSL_PROTOCOL_CONFIG, getSslProtocol());

addPropertyIfNotNull(props, SslConfigs.SSL_PROVIDER_CONFIG, getSslProvider());

addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, getSslTruststoreType());

addPropertyIfNotNull(props, ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, getAutoCommitIntervalMs());

addPropertyIfNotNull(props, ConsumerConfig.CHECK_CRCS_CONFIG, getCheckCrcs());

addPropertyIfNotNull(props, ConsumerConfig.CLIENT_ID_CONFIG, getClientId());

addPropertyIfNotNull(props, ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG, getFetchWaitMaxMs());

addPropertyIfNotNull(props, ConsumerConfig.METADATA_MAX_AGE_CONFIG, getMetadataMaxAgeMs());

addPropertyIfNotNull(props, ConsumerConfig.METRIC_REPORTER_CLASSES_CONFIG, getMetricReporters());

addPropertyIfNotNull(props, ConsumerConfig.METRICS_NUM_SAMPLES_CONFIG, getNoOfMetricsSample());

addPropertyIfNotNull(props, ConsumerConfig.METRICS_SAMPLE_WINDOW_MS_CONFIG, getMetricsSampleWindowMs());

addPropertyIfNotNull(props, ConsumerConfig.RECONNECT_BACKOFF_MS_CONFIG, getReconnectBackoffMs());

addPropertyIfNotNull(props, ConsumerConfig.RETRY_BACKOFF_MS_CONFIG, getRetryBackoffMs());

//SASL

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_KINIT_CMD, getKerberosInitCmd());

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_MIN_TIME_BEFORE_RELOGIN, getKerberosBeforeReloginMinTime());

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_TICKET_RENEW_JITTER, getKerberosRenewJitter());

addPropertyIfNotNull(props, SaslConfigs.SASL_KERBEROS_TICKET_RENEW_WINDOW_FACTOR, getKerberosRenewWindowFactor());

//SSL

addPropertyIfNotNull(props, SslConfigs.SSL_CIPHER_SUITES_CONFIG, getSslCipherSuites());

addPropertyIfNotNull(props, SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, getSslEndpointAlgorithm());

addPropertyIfNotNull(props, SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, getSslKeymanagerAlgorithm());

addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, getSslTrustmanagerAlgorithm());

return props;

}

開發者ID:HydAu,項目名稱:Camel,代碼行數:54,

示例37: configure

​點讚 1

import org.apache.kafka.common.config.SaslConfigs; //導入依賴的package包/類

/**

* Login constructor. The constructor starts the thread used

* to periodically re-login to the Kerberos Ticket Granting Server.

* @param loginContextName

* name of section in JAAS file that will be use to login.

* Passed as first param to javax.security.auth.login.LoginContext().

* @param configs configure Login with the given key-value pairs.

* @throws javax.security.auth.login.LoginException

* Thrown if authentication fails.

*/

public void configure(Map configs, final String loginContextName) {

super.configure(configs, loginContextName);

this.loginContextName = loginContextName;

this.ticketRenewWindowFactor = (Double) configs.get(SaslConfigs.SASL_KERBEROS_TICKET_RENEW_WINDOW_FACTOR);

this.ticketRenewJitter = (Double) configs.get(SaslConfigs.SASL_KERBEROS_TICKET_RENEW_JITTER);

this.minTimeBeforeRelogin = (Long) configs.get(SaslConfigs.SASL_KERBEROS_MIN_TIME_BEFORE_RELOGIN);

this.kinitCmd = (String) configs.get(SaslConfigs.SASL_KERBEROS_KINIT_CMD);

this.serviceName = getServiceName(configs, loginContextName);

}

開發者ID:txazo,項目名稱:kafka,代碼行數:20,

注:本文中的org.apache.kafka.common.config.SaslConfigs類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值