如何在 ehcache 中通过 SSL 配置 RMI 以进行复制

How to configure RMI over SSL in ehcache for replication

我在没有 SSL 支持的情况下使 ehcache 复制正常工作。 我希望通过 SSL 支持我的 ehcache 复制,即我想通过 SSL

进行 RMI

我该怎么做?

这是我正在使用的示例手动对等发现。

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//10.100.10.12:40002/ssoSessionStore"/> 

我可以为它正在执行的 RMI 调用提供一些 SSL 支持吗?

谢谢

我不得不更改 ehcache 源代码并更改少量 classes 以支持 SSL。当 ehcache 通过 rmi bootsup 时,它会在 rmiregistry 上注册自己。我需要通过 SSL 上下文启动此注册

查看 class RMICacheManagerPeerListener.java 方法 startRegistry() 这是 RMI 注册表开始的主要 class。修改代码的人需要首先了解 ehcache rmi 代码流程。下面的代码是必须完成的代码片段,并分别更改了其他方法。

final String SSL= System.getProperty("isSSL");
  protected void startRegistry() throws RemoteException {
        try {
            LOG.info("Trying to Get Exsisting Registry =========>> ");
            if (SSL != null && SSL.equals("ssl"))
                registry = LocateRegistry.getRegistry(hostName, port.intValue(),
                        new SslRMIClientSocketFactory());
            else
                registry = LocateRegistry.getRegistry(port.intValue());
            try {
                registry.list();
            } catch (RemoteException e) {
                // may not be created. Let's create it.
                if (SSL != null && SSL.equals("ssl")) {
                    LOG.info("Registry not found, Creating New SSL =========>> ");
                    registry = LocateRegistry.createRegistry(port.intValue(),
                            new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory(null, null, true));
                } else {
                    LOG.info("Registry not found, Creating New Naming registry =========>> ");
                    registry = LocateRegistry.createRegistry(port.intValue());
                }

                registryCreated = true;

            }
        } catch (ExportException exception) {
            LOG.error("Exception starting RMI registry. Error was " + exception.getMessage(), exception);
        }
    }

同样,我对方法进行了更改

bind()
notifyCacheAdded()
unbind()
disposeRMICachePeer()
populateListOfRemoteCachePeers()
bind()
init() 

要修补对使用自定义套接字工厂的支持,您应该删除对全局默认值的使用。静态方法调用

java.rmi.Naming

应替换为注册表 return 由

的三参数版本编辑
LocateRegistry.createRegistry

LocateRegistry.getRegistry

并在 ConfigurableRMIClientSocketFactory.java 中更改

getConfiguredRMISocketFactory

到 return 基于 SSL 的实现。

有关示例补丁,请参阅 https://gist.github.com/okhobb/4a504e212aef86d4257c69de892e4d7d