• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TrustStoreTrustManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getLDAPConnection

import com.unboundid.util.ssl.TrustStoreTrustManager; //导入依赖的package包/类
public LDAPConnection getLDAPConnection(String userDN, String password)
    throws LDAPException, GeneralSecurityException {
  TrustStoreTrustManager trust = new TrustStoreTrustManager(trustStorePath, trustStorePassword.toCharArray(), trustStoreType, false);
  LDAPConnectionOptions options = new LDAPConnectionOptions();
  options.setSSLSocketVerifier(new HostNameSSLSocketVerifier(false));
  SSLUtil sslUtil = new SSLUtil(trust);
  SocketFactory factory = new EndpointIdentificationSocketFactory(sslUtil.createSSLSocketFactory("TLSv1.2"));
  LDAPConnection ldapConnection = new LDAPConnection(factory, options);

  // Connect, retrieve the DN of the user (if any)
  ldapConnection.connect(server, port);
  ldapConnection.bind(userDN, password);

  return ldapConnection;
}
 
开发者ID:square,项目名称:keywhiz,代码行数:16,代码来源:LdapConnectionFactory.java


示例2: InMemoryTestLdapDirectoryServer

import com.unboundid.util.ssl.TrustStoreTrustManager; //导入依赖的package包/类
/**
 * Instantiates a new Ldap directory server.
 * Parameters need to be streams so they can be read from JARs.
 */
public InMemoryTestLdapDirectoryServer(final InputStream properties,
                                       final InputStream ldifFile,
                                       final InputStream schemaFile) {
    try {
        final Properties p = new Properties();
        p.load(properties);

        final InMemoryDirectoryServerConfig config =
                new InMemoryDirectoryServerConfig(p.getProperty("ldap.rootDn"));
        config.addAdditionalBindCredentials(p.getProperty("ldap.managerDn"), p.getProperty("ldap.managerPassword"));

        final File keystoreFile = File.createTempFile("key", "store");
        try (OutputStream outputStream = new FileOutputStream(keystoreFile)) {
            IOUtils.copy(new ClassPathResource("/ldapServerTrustStore").getInputStream(), outputStream);
        }

        final String serverKeyStorePath = keystoreFile.getCanonicalPath();
        final SSLUtil serverSSLUtil = new SSLUtil(
                new KeyStoreKeyManager(serverKeyStorePath, "changeit".toCharArray()), new TrustStoreTrustManager(serverKeyStorePath));
        final SSLUtil clientSSLUtil = new SSLUtil(new TrustStoreTrustManager(serverKeyStorePath));
        config.setListenerConfigs(
                InMemoryListenerConfig.createLDAPConfig("LDAP", // Listener name
                        null, // Listen address. (null = listen on all interfaces)
                        1389, // Listen port (0 = automatically choose an available port)
                        serverSSLUtil.createSSLSocketFactory()), // StartTLS factory
                InMemoryListenerConfig.createLDAPSConfig("LDAPS", // Listener name
                        null, // Listen address. (null = listen on all interfaces)
                        1636, // Listen port (0 = automatically choose an available port)
                        serverSSLUtil.createSSLServerSocketFactory(), // Server factory
                        clientSSLUtil.createSSLSocketFactory())); // Client factory

        config.setEnforceSingleStructuralObjectClass(false);
        config.setEnforceAttributeSyntaxCompliance(true);


        final File file = File.createTempFile("ldap", "schema");
        try (OutputStream outputStream = new FileOutputStream(file)) {
            IOUtils.copy(schemaFile, outputStream);
        }

        final Schema s = Schema.mergeSchemas(Schema.getSchema(file));
        config.setSchema(s);


        this.directoryServer = new InMemoryDirectoryServer(config);
        LOGGER.debug("Populating directory...");

        final File ldif = File.createTempFile("ldiff", "file");
        try (OutputStream outputStream = new FileOutputStream(ldif)) {
            IOUtils.copy(ldifFile, outputStream);
        }

        this.directoryServer.importFromLDIF(true, ldif.getCanonicalPath());
        this.directoryServer.restartServer();

        final LDAPConnection c = getConnection();
        LOGGER.debug("Connected to {}:{}", c.getConnectedAddress(), c.getConnectedPort());

        populateDefaultEntries(c);

        c.close();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:70,代码来源:InMemoryTestLdapDirectoryServer.java


示例3: InMemoryTestLdapDirectoryServer

import com.unboundid.util.ssl.TrustStoreTrustManager; //导入依赖的package包/类
/**
 * Instantiates a new Ldap directory server.
 * Parameters need to be streams so they can be read from JARs.
 */
public InMemoryTestLdapDirectoryServer(final InputStream properties,
                                       final InputStream ldifFile,
                                       final InputStream schemaFile) {
    try {
        final Properties p = new Properties();
        p.load(properties);

        final InMemoryDirectoryServerConfig config =
                new InMemoryDirectoryServerConfig(p.getProperty("ldap.rootDn"));
        config.addAdditionalBindCredentials(p.getProperty("ldap.managerDn"), p.getProperty("ldap.managerPassword"));

        final File keystoreFile = File.createTempFile("key", "store");
        try (final OutputStream outputStream = new FileOutputStream(keystoreFile)) {
            IOUtils.copy(new ClassPathResource("/ldapServerTrustStore").getInputStream(), outputStream);
        }

        final String serverKeyStorePath = keystoreFile.getCanonicalPath();
        final SSLUtil serverSSLUtil = new SSLUtil(
                new KeyStoreKeyManager(serverKeyStorePath, "changeit".toCharArray()), new TrustStoreTrustManager(serverKeyStorePath));
        final SSLUtil clientSSLUtil = new SSLUtil(new TrustStoreTrustManager(serverKeyStorePath));
        config.setListenerConfigs(
                InMemoryListenerConfig.createLDAPConfig("LDAP", // Listener name
                        null, // Listen address. (null = listen on all interfaces)
                        1389, // Listen port (0 = automatically choose an available port)
                        serverSSLUtil.createSSLSocketFactory()), // StartTLS factory
                InMemoryListenerConfig.createLDAPSConfig("LDAPS", // Listener name
                        null, // Listen address. (null = listen on all interfaces)
                        1636, // Listen port (0 = automatically choose an available port)
                        serverSSLUtil.createSSLServerSocketFactory(), // Server factory
                        clientSSLUtil.createSSLSocketFactory())); // Client factory

        config.setEnforceSingleStructuralObjectClass(false);
        config.setEnforceAttributeSyntaxCompliance(true);


        final File file = File.createTempFile("ldap", "schema");
        try (final OutputStream outputStream = new FileOutputStream(file)) {
            IOUtils.copy(schemaFile, outputStream);
        }

        final Schema s = Schema.mergeSchemas(Schema.getSchema(file));
        config.setSchema(s);


        this.directoryServer = new InMemoryDirectoryServer(config);
        LOGGER.debug("Populating directory...");

        final File ldif = File.createTempFile("ldiff", "file");
        try (final OutputStream outputStream = new FileOutputStream(ldif)) {
            IOUtils.copy(ldifFile, outputStream);
        }

        this.directoryServer.importFromLDIF(true, ldif.getCanonicalPath());
        this.directoryServer.restartServer();

        final LDAPConnection c = getConnection();
        LOGGER.debug("Connected to {}:{}", c.getConnectedAddress(), c.getConnectedPort());

        populateDefaultEntries(c);

        c.close();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:70,代码来源:InMemoryTestLdapDirectoryServer.java


示例4: LdapServer

import com.unboundid.util.ssl.TrustStoreTrustManager; //导入依赖的package包/类
/**
 * Instantiates a new Ldap directory server.
 * Parameters need to be streams so they can be read from JARs.
 */
public LdapServer(final InputStream properties,
                  final InputStream ldifFile,
                  final InputStream schemaFile) {
    try {
        final Properties p = new Properties();
        p.load(properties);

        final InMemoryDirectoryServerConfig config =
                new InMemoryDirectoryServerConfig(p.getProperty("ldap.rootDn"));
        config.addAdditionalBindCredentials(p.getProperty("ldap.managerDn"), p.getProperty("ldap.managerPassword"));

        final File keystoreFile = File.createTempFile("key", "store");
        try (final OutputStream outputStream = new FileOutputStream(keystoreFile)) {
            IOUtils.copy(new ClassPathResource("/ldapServerTrustStore").getInputStream(), outputStream);
        }

        final String serverKeyStorePath = keystoreFile.getCanonicalPath();
        final SSLUtil serverSSLUtil = new SSLUtil(
                new KeyStoreKeyManager(serverKeyStorePath, "changeit".toCharArray()), new TrustStoreTrustManager(serverKeyStorePath));
        final SSLUtil clientSSLUtil = new SSLUtil(new TrustStoreTrustManager(serverKeyStorePath));
        config.setListenerConfigs(
                InMemoryListenerConfig.createLDAPConfig("LDAP", // Listener name
                        null, // Listen address. (null = listen on all interfaces)
                        1389, // Listen port (0 = automatically choose an available port)
                        serverSSLUtil.createSSLSocketFactory()), // StartTLS factory
                InMemoryListenerConfig.createLDAPSConfig("LDAPS", // Listener name
                        null, // Listen address. (null = listen on all interfaces)
                        1636, // Listen port (0 = automatically choose an available port)
                        serverSSLUtil.createSSLServerSocketFactory(), // Server factory
                        clientSSLUtil.createSSLSocketFactory())); // Client factory

        config.setEnforceSingleStructuralObjectClass(false);
        config.setEnforceAttributeSyntaxCompliance(true);
        config.setMaxConnections(-1);

        final File file = File.createTempFile("ldap", "schema");
        try (final OutputStream outputStream = new FileOutputStream(file)) {
            IOUtils.copy(schemaFile, outputStream);
        }

        final Schema s = Schema.mergeSchemas(Schema.getSchema(file));
        config.setSchema(s);


        this.directoryServer = new InMemoryDirectoryServer(config);
        LOGGER.debug("Populating directory...");

        final File ldif = File.createTempFile("ldiff", "file");
        try (final OutputStream outputStream = new FileOutputStream(ldif)) {
            IOUtils.copy(ldifFile, outputStream);
        }

        this.directoryServer.importFromLDIF(true, ldif.getCanonicalPath());
        this.directoryServer.restartServer();

        final LDAPConnection c = getConnection();
        LOGGER.debug("Connected to {}:{}", c.getConnectedAddress(), c.getConnectedPort());

        LOGGER.debug("Bind DN: {}",  p.getProperty("ldap.managerDn"));
        LOGGER.debug("Bind credential: {}", p.getProperty("ldap.managerPassword"));

        populateDefaultEntries(c);

        c.close();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:UniconLabs,项目名称:unboundid-ldap-server,代码行数:73,代码来源:LdapServer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DeleteSnapshotResponseProto类代码示例发布时间:2022-05-22
下一篇:
Java HSSFFormulaEvaluator类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap