1.11.10.3. 在 Elytron 中使用自定义信任管理器


通过实施自定义信任管理器,可以在 Undertow、LDAPS(在 dir-context )或 Elytron 用于 SSL 连接的任何位置使用 HTTPS 时扩展证书验证。此组件负责为服务器做出信任决策,强烈建议在使用自定义信任管理器时实施这些决策。

重要

当使用 FIPS 时,无法使用自定义信任管理器,因为 FIPS 要求出于安全原因将这个管理器嵌入 JDK 中。通过实施可验证 X509 事实的 SecurityRealm,可以实现类似的行为。

实施自定义信任管理器的要求

使用自定义信任管理器时,必须实施以下内容:

  • 实施 X509ExtendedTrustManager 接口的信任管理器。
  • 扩展 TrustManagerFactorySpi 的信任管理器工厂。
  • 信任经理工厂的供应商。

该提供程序必须包含在要添加到 JBoss EAP 的 JAR 文件中。任何实施的类都必须作为模块包含在 JBoss EAP 中。 类不需要位于一个模块中,可以从模块依赖项加载。

实施示例

以下示例演示了将自定义信任管理器工厂注册为服务的供应商。

示例:provider

import org.kohsuke.MetaInfServices;
import javax.net.ssl.TrustManagerFactory;
import java.security.Provider;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@MetaInfServices(Provider.class)
public class CustomProvider extends Provider {

    public CustomProvider() {
        super("CustomProvider", 1.0, "Demo provider");

        System.out.println("CustomProvider initialization.");

        final List<String> emptyList = Collections.emptyList();
        final Map<String, String> emptyMap = Collections.emptyMap();

        putService(new Service(this, TrustManagerFactory.class.getSimpleName(),"CustomAlgorithm", CustomTrustManagerFactorySpi.class.getName(), emptyList, emptyMap));
    }

}
Copy to Clipboard Toggle word wrap

以下示例演示了自定义信任管理器。此信任管理器包含过载方法来检查客户端或服务器是否受信任。

示例:trustedManager

import javax.net.ssl.SSLEngine;
import javax.net.ssl.X509ExtendedTrustManager;
import java.net.Socket;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

public class CustomTrustManager extends X509ExtendedTrustManager {

    public void checkClientTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException {
        // Insert your code here
    }

    public void checkServerTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException {
        // Insert your code here
    }

    public void checkClientTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException {
        // Insert your code here
    }

    public void checkServerTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException {
        // Insert your code here
    }

    public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
        // Insert your code here
    }

    public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
        // Insert your code here
    }

    public X509Certificate[] getAcceptedIssuers() {
        // Insert your code here
    }

}
Copy to Clipboard Toggle word wrap

以下示例是用于返回信任管理器的实例的工厂。

示例:trustedManagerFactorySpi

import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactorySpi;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;

public class CustomTrustManagerFactorySpi extends TrustManagerFactorySpi {

    protected void engineInit(KeyStore keyStore) throws KeyStoreException {
        // Insert your code here
    }

    protected void engineInit(ManagerFactoryParameters managerFactoryParameters) throws InvalidAlgorithmParameterException {
        // Insert your code here
    }

    protected CustomTrustManager[] engineGetTrustManagers() {
        // Insert your code here
    }

}
Copy to Clipboard Toggle word wrap

添加自定义信任管理器

创建了提供程序和信任管理器后,使用将 自定义组件添加到 E lytron 中的步骤,将它们添加到 e lytron 子系统。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat