我的 ehcache 复制在没有 SSL 支持的情况下也能正常工作。 我希望通过 SSL 支持我的 ehcache 复制,即我希望通过 SSL 进行 RMI
我怎样才能做到这一点?
这是我正在使用的手动对等发现示例。
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//10.100.10.12:40002/ssoSessionStore"/>
我可以为 RMI 调用提供一些 SSL 支持吗?
谢谢
最佳答案
我必须更改 ehcache 源代码并更改一些类来支持 SSL。当 ehcache 通过 rmi bootsup 时,它会在 rmiregistry 上注册自身。我需要通过 SSL 上下文启动此注册表
查看类 RMICacheManagerPeerListener.java
中的方法 startRegistry()
这是 RMI 注册表启动的主类。修改代码的人首先需要了解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()
关于ssl - 如何在 ehcache 中配置 RMI over SSL 进行复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31117458/