7

我正在尝试以企业“业务”方式重写我的旧应用程序。
所以,我有一个带有登录模块的 Swing 客户端和我自己从头开始创建的服务器。客户端使用 ssl 证书加密与服务器的 TCP 连接(我检查服务器上的客户端证书和客户端上的服务器证书),然后服务器使用数据库对用户进行身份验证和授权。

现在我正试图让它与 WildFly 8 CR1 托管的 ejb 一起工作。我想使用相同的客户端-服务器密钥对将 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 加密+ 使用登录客户端模块通过数据源进行身份验证和授权

任何帮助将不胜感激。

对不起我的英语,我经常用这种语言阅读,而不是写作:)

4

1 回答 1

2

您需要在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
于 2014-01-19T18:46:04.497 回答