我正在尝试以企业“业务”方式重写我的旧应用程序。
所以,我有一个带有登录模块的 Swing 客户端和我自己从头开始创建的服务器。客户端使用 ssl 证书加密到服务器的 TCP 连接(我检查服务器上的客户端证书和客户端上的服务器证书),然后服务器使用数据库对用户进行身份验证和授权。
现在我正试图让它与由 WildFly 8 CR1 托管的 ejb 一起工作。 我想使用相同的客户端-服务器 key 对将 Swing 客户端连接到 WildFly 服务器,然后使用存储在 MySQL 数据源中的名称和凭据对用户进行身份验证。我还在数据库中存储了角色,我想用它们来配置客户端主体。
我有简单、基本的 EJB 调用:
Context ctx = new InitialContext();
MyBeanRemote bean = (MyBeanRemote)ctx.lookup("AppName/module-0.0.1-SNAPSHOT/MyBean!my.app.MyBeanRemote");
ResultType result = bean.doSomething();
我有 jndi.properties 文件
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.provider.url=http-remoting://myServer:8080
jboss.naming.client.ejb.context=true
java.naming.security.principal=app-user-name
java.naming.security.credentials=password@123
我有基本的数据源配置
<datasource jta="false" jndi-name="java:jboss/datasources/MyDB" pool-name="MyDB" enabled="true" use-ccm="false">
<connection-url>jdbc:mysql://localhost:3306/Mydb</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql-connector-java-5.1.28-bin.jar</driver>
<security>
<user-name>mysqlUser</user-name>
<password>mysqlPass</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
以上一切正常。
我已经阅读了一些指南,但仍然没有找到描述如何使用以下组合的指南:EJB(非 Web)+ WildFly 8(非 JBoss 7)+ SSL 加密 + 通过数据源与登录客户端模块进行身份验证和授权
任何帮助将不胜感激。
对不起我的英语,我经常用这种语言来阅读,而不是写作:)
最佳答案
您需要在 standalone.xml 文件中创建一个映射到远程连接器的安全领域,如下所示:
<management>
<security-realms>
<security-realm name="MyRealm">
<authentication>
<jaas name="my-domain"/>
</authentication>
</security-realm>
</management>
<subsystem xmlns="urn:jboss:domain:remoting:1.1">
<connector name="remoting-connector" socket-binding="remoting" security-realm="MyRealm"/>
</subsystem>
然后您应该使用适当的 LoginModule(内置的或您自己的)启用安全域:
<security-domains>
<security-domain name="my-domain" cache-type="default">
<authentication>
<login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
<module-option name="dsJndiName" value="java:jboss/datasources/serviceDS"/>
<module-option name="principalsQuery" value="SELECT identificationCode FROM devices WHERE name=?"/>
<module-option name="rolesQuery" value="SELECT 'device', 'Roles' FROM devices WHERE name=?"/>
</login-module>
</authentication>
</security-domain>
</security-realms>
当然,数据源应该指向一个数据库,查询可以在其中找到适当的主体(用户)及其角色。 请务必查看两篇有关远程处理的文章:https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project和 https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI .看起来您正在使用“旧”远程处理 - JBoss 7 不再支持客户端登录模块。底线是您的 ejb 远程处理配置应该看起来更像(注意不允许的本地用户!):
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=8080
remote.connection.default.username=userName
remote.connection.default.password=password
remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false
一定要查看https://github.com/wildfly/quickstart/tree/master/ejb-remote
最后,记得在您的 jboss-ejb3.xml 中添加您的安全域映射:
<jboss:ejb-jar>
<assembly-descriptor>
<s:security>
<ejb-name>*</ejb-name>
<s:security-domain>my-domain</s:security-domain>
</s:security>
</assembly-descriptor>
</jboss:ejb-jar
关于java - 从 WildFly 安全地调用 EJB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21217561/