Wildfly 10.1下OpenShift 3远程调用EJB遇Sasl认证失败求助
作为经常处理Wildfly EJB远程调用问题的开发者,我来帮你一步步排查这个认证失败的问题,结合你的OpenShift 3和Wildfly 10.1环境,给你几个关键的解决方向:
1. 先检查OpenShift中Wildfly Pod的EJB远程核心配置
这个错误的核心原因是服务器端未提供任何可用的SASL认证机制,首先得确认Wildfly的remoting子系统配置是否正确:
- 登录到Wildfly Pod中,查看
standalone.xml(或domain.xml)里的remoting子系统配置,确保连接器关联了正确的安全域:<subsystem xmlns="urn:jboss:domain:remoting:3.0"> <endpoint worker="default"/> <http-connector name="http-remoting-connector" connector-ref="default" security-realm="ApplicationRealm"/> </subsystem> - 确认
ApplicationRealm中存在有权限访问EJB的用户,并且给该用户分配了ejb相关角色(比如默认的guest角色,或者自定义角色)。可以通过Wildfly的add-user.sh工具在Pod内添加用户:./bin/add-user.sh -a -u ejb-user -p your-password -g guest
2. 修正手动配置EJBClientContext的参数
既然你选择手动创建上下文,必须明确指定认证相关属性,否则客户端无法和服务器协商认证机制:
Properties props = new Properties(); // 基础EJB命名前缀 props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); // 开启上下文隔离 props.put("jboss.ejb.client.scoped.context", "true"); // 关闭SSL(如果你的环境没配置SSL) props.put("jboss.remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false"); // 配置认证账号密码 props.put("jboss.remoting.username", "ejb-user"); props.put("jboss.remoting.password", "your-password"); // 指定OpenShift Service的地址和端口(比如http-remoting默认映射8080) props.put("jboss.ejb.client.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false"); // 初始化客户端上下文 EJBClientConfiguration config = new PropertiesBasedEJBClientConfiguration(props); ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(config); EJBClientContext.setSelector(selector);
3. 排查SASL机制不匹配问题
如果还是报错,需要确认客户端和服务器的SASL机制是否对齐:
- 查看Wildfly启动日志,搜索关键词
SASL,应该能看到类似Registered SASL mechanism: PLAIN的日志条目,如果没有,说明服务器端未加载任何SASL机制,需要检查安全域配置是否正确。 - 客户端可以强制指定SASL机制,比如在属性中添加:
props.put("jboss.remote.connection.default.connect.options.org.xnio.Options.SASL_MECHANISMS", "PLAIN");
4. OpenShift环境的特殊注意事项
- 不要直接连接Pod的IP,必须通过OpenShift Service的ClusterIP或者外部Route访问EJB远程服务。如果是外部客户端,需要创建Route暴露Wildfly的
http-remoting-connector对应的端口(通常是8080)。 - 检查OpenShift的NetworkPolicy,确保客户端所在的Namespace可以访问Wildfly Pod所在Namespace的EJB远程端口。
5. 回退到jboss-ejb-client.properties的正确配置
之前用配置文件连不上大概率是配置项不全,正确的配置文件示例如下,放在客户端classpath下即可:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=default remote.connection.default.host=your-openshift-service-name remote.connection.default.port=8080 remote.connection.default.username=ejb-user remote.connection.default.password=your-password remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
内容的提问来源于stack exchange,提问作者Mostafa Man
相关产品推荐
相关产品推荐

