2014-01-19 50 views
7


调用EJB从WildFly安全

我想重新写我的旧的应用程序的企业,“经营”的方式。
因此,我有一个带登录模块的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 
[email protected] 

我有基本的数据源配置

<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> 

上述的一切正常。

我读过一些导游,但还没有找到一个介绍如何使用的复合材料:通过SSL EJB(而不是web)+ WildFly 8(不JBoss的7)+加密+通过与数据源进行身份验证和授权登录客户端模块

任何帮助将不胜感激。

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

回答

2

你会NEET创建一个安全域映射到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+projecthttps://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 
+0

感谢您的回答。据我所知,CR1版本的WildFly根本不使用4447端口。我想使用新版本的ejb查找,但它根本无法工作。 – Kaskader

+0

是的,你是对的 - 我的坏 - 我忘了新的HTTP升级机制。现在是8080 - 我固定了这个帖子。我的意思是,你没有使用新的远程堆栈 - 因此指向了JBoss 7文章的链接。远程工作的最小属性集为:remote.connections = default remote.connection.default.host = localhost remote.connection.default.port = 8080。我还添加了一个快速启动从蜻蜓ejb-remoting的链接。它不适用于CR 1,但应该工作(在更新pom版本到 8.0.0.CR1后适用于我) – mcmil

+0

不幸的是,它不起作用。我已按照您的建议指定了安全领域和域。在域:远程处理我有'<子系统xmlns =“urn:jboss:域:远程处理:2.0”>'。您的版本在启动时导致服务器崩溃。然后按照你的建议填充jboss-ejb3.xml和jboss-ejb-client.properties,只留下'java.naming.factory.url.pkgs = org.jboss.ejb.client.naming'和'java.naming。 factory.initial = org.jboss.naming.remote.client.InitialContextFactory'。现在,我在上下文初始化方面有例外 – Kaskader