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


Java Password类代码示例

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


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

示例1: acquireLoginManager

import org.apache.kafka.common.config.types.Password; //导入依赖的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<String, ?> 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,代码来源:LoginManager.java

示例2: release

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
/**
 * Decrease the reference count for this instance and release resources if it reaches 0.
 */
public void release() {
    synchronized (LoginManager.class) {
        if (refCount == 0)
            throw new IllegalStateException("release called on LoginManager with refCount == 0");
        else if (refCount == 1) {
            if (cacheKey instanceof Password) {
                DYNAMIC_INSTANCES.remove(cacheKey);
            } else {
                STATIC_INSTANCES.remove(cacheKey);
            }
            login.close();
        }
        --refCount;
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:LoginManager.java

示例3: createSSLContext

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
private SSLContext createSSLContext() throws GeneralSecurityException, IOException  {
    SSLContext sslContext;
    if (provider != null)
        sslContext = SSLContext.getInstance(protocol, provider);
    else
        sslContext = SSLContext.getInstance(protocol);

    KeyManager[] keyManagers = null;
    if (keystore != null) {
        String kmfAlgorithm = this.kmfAlgorithm != null ? this.kmfAlgorithm : KeyManagerFactory.getDefaultAlgorithm();
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
        KeyStore ks = keystore.load();
        Password keyPassword = this.keyPassword != null ? this.keyPassword : keystore.password;
        kmf.init(ks, keyPassword.value().toCharArray());
        keyManagers = kmf.getKeyManagers();
    }

    String tmfAlgorithm = this.tmfAlgorithm != null ? this.tmfAlgorithm : TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
    KeyStore ts = truststore == null ? null : truststore.load();
    tmf.init(ts);

    sslContext.init(keyManagers, tmf.getTrustManagers(), this.secureRandomImplementation);
    return sslContext;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:SslFactory.java

示例4: load

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
static JaasContext load(JaasContext.Type contextType, String listenerContextName,
                        String globalContextName, Map<String, ?> 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,代码来源:JaasContext.java

示例5: configurationEntry

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
private AppConfigurationEntry configurationEntry(JaasContext.Type contextType, String jaasConfigProp) {
    Map<String, Object> 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<AppConfigurationEntry> entries = context.configurationEntries();
    assertEquals(1, entries.size());
    return entries.get(0);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:JaasContextTest.java

示例6: testSslPasswords

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
@Test
public void testSslPasswords() {
    ConfigDef def = new ConfigDef();
    SslConfigs.addClientSslSupport(def);

    Properties props = new Properties();
    props.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, "key_password");
    props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, "keystore_password");
    props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "truststore_password");

    Map<String, Object> vals = def.parse(props);
    assertEquals(new Password("key_password"), vals.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG));
    assertEquals(Password.HIDDEN, vals.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG).toString());
    assertEquals(new Password("keystore_password"), vals.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG));
    assertEquals(Password.HIDDEN, vals.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG).toString());
    assertEquals(new Password("truststore_password"), vals.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG));
    assertEquals(Password.HIDDEN, vals.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG).toString());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:ConfigDefTest.java

示例7: createSslConfig

import org.apache.kafka.common.config.types.Password; //导入依赖的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

示例8: createSslConfig

import org.apache.kafka.common.config.types.Password; //导入依赖的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

示例9: createSSLContext

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
private SSLContext createSSLContext() throws GeneralSecurityException, IOException  {
    SSLContext sslContext;
    if (provider != null)
        sslContext = SSLContext.getInstance(protocol, provider);
    else
        sslContext = SSLContext.getInstance(protocol);

    KeyManager[] keyManagers = null;
    if (keystore != null) {
        String kmfAlgorithm = this.kmfAlgorithm != null ? this.kmfAlgorithm : KeyManagerFactory.getDefaultAlgorithm();
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
        KeyStore ks = keystore.load();
        Password keyPassword = this.keyPassword != null ? this.keyPassword : keystore.password;
        kmf.init(ks, keyPassword.value().toCharArray());
        keyManagers = kmf.getKeyManagers();
    }

    String tmfAlgorithm = this.tmfAlgorithm != null ? this.tmfAlgorithm : TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
    KeyStore ts = truststore == null ? null : truststore.load();
    tmf.init(ts);

    sslContext.init(keyManagers, tmf.getTrustManagers(), null);
    return sslContext;
}
 
开发者ID:txazo,项目名称:kafka,代码行数:26,代码来源:SslFactory.java

示例10: createSslConfig

import org.apache.kafka.common.config.types.Password; //导入依赖的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

示例11: S3ProxyConfig

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
public S3ProxyConfig(S3SinkConnectorConfig config) {
  try {
    URL url = new URL(config.getString(S3_PROXY_URL_CONFIG));
    protocol = extractProtocol(url.getProtocol());
    host = url.getHost();
    port = url.getPort();
    String username = config.getString(S3_PROXY_USER_CONFIG);
    user = StringUtils.isNotBlank(username)
           ? username
           : extractUser(url.getUserInfo());
    Password password = config.getPassword(S3_PROXY_PASS_CONFIG);
    pass = StringUtils.isNotBlank(password.value())
           ? password.value()
           : extractPass(url.getUserInfo());
  } catch (MalformedURLException e) {
    throw new ConfigException(
        S3_PROXY_URL_CONFIG,
        config.getString(S3_PROXY_URL_CONFIG),
        e.toString()
    );
  }
}
 
开发者ID:confluentinc,项目名称:kafka-connect-storage-cloud,代码行数:23,代码来源:S3ProxyConfig.java

示例12: LoginManager

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
private LoginManager(JaasContext jaasContext, boolean hasKerberos, Map<String, ?> configs,
                     Password jaasConfigValue) throws IOException, LoginException {
    this.cacheKey = jaasConfigValue != null ? jaasConfigValue : jaasContext.name();
    login = hasKerberos ? new KerberosLogin() : new DefaultLogin();
    login.configure(configs, jaasContext);
    login.login();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:8,代码来源:LoginManager.java

示例13: createKeystore

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
private void createKeystore(String type, String path, Password password, Password keyPassword) {
    if (path == null && password != null) {
        throw new KafkaException("SSL key store is not specified, but key store password is specified.");
    } else if (path != null && password == null) {
        throw new KafkaException("SSL key store is specified, but key store password is not specified.");
    } else if (path != null && password != null) {
        this.keystore = new SecurityStore(type, path, password);
        this.keyPassword = keyPassword;
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:11,代码来源:SslFactory.java

示例14: createTruststore

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
private void createTruststore(String type, String path, Password password) {
    if (path == null && password != null) {
        throw new KafkaException("SSL trust store is not specified, but trust store password is specified.");
    } else if (path != null) {
        this.truststore = new SecurityStore(type, path, password);
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:8,代码来源:SslFactory.java

示例15: testInvalidKeyPassword

import org.apache.kafka.common.config.types.Password; //导入依赖的package包/类
/**
 * Tests that client connections cannot be created to a server
 * if key password is invalid
 */
@Test
public void testInvalidKeyPassword() throws Exception {
    String node = "0";
    sslServerConfigs.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, new Password("invalid"));
    server = createEchoServer(SecurityProtocol.SSL);
    createSelector(sslClientConfigs);
    InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
    selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);

    NetworkTestUtils.waitForChannelClose(selector, node, ChannelState.AUTHENTICATE);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:16,代码来源:SslTransportLayerTest.java


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