WildFly 8.x,使用JAAS调用远程EJB 3

时间:2015-05-24 11:25:23

标签: ejb wildfly jaas

我创建了一个EJB 3并部署在wildfly

@Stateless
@Remote(ICoreParameterService.class)
@RolesAllowed("$APP_USER$")
@SecurityDomain("AppJaasRealm") 
public class CoreParameterService extends BaseService implements ICoreParameterService{
some public functions;

} 当EJB和Web部署在同一台服务器上时,一切都很完美。 现在我想通过在tomcat上部署Web应用程序或从swing应用程序调用EJB来调用EJB 下面是我的客户端,如果我从EJB

中删除@RolesAllowed,@ SecureDomain,它的工作方式非常完美
public class TestStatelessSessionBeans {
public static void main(String arg[]){
try {

     final Properties clientConfigProps = new Properties();  
        clientConfigProps.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");

        clientConfigProps.put("remote.connection.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS","false");
        clientConfigProps.put("remote.connection.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");

        clientConfigProps.put("remote.connections", "default");  
        clientConfigProps.put("remote.connection.default.host", "localhost");  
        clientConfigProps.put("remote.connection.default.port", "8080");  
        clientConfigProps.put("remote.connection.default.protocol", "http-remoting");  
        clientConfigProps.put("remote.connection.default.username", "admin");   // JAAS user
       clientConfigProps.put("remote.connection.default.password", "sohail");   // JAAS password ; the encryption of pwd is 36+e2V2o0eKO3DOMG2YHI4Qd6NWL1wpd4S0z3sTuo90=
       final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(clientConfigProps);  
        final ContextSelector<EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);  

        EJBClientContext.setSelector(ejbClientContextSelector);  

        final Properties jndiProperties = new Properties();   

        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

      Context context = new InitialContext(jndiProperties);  

    String  lookUpName ="java:global/fortune-ear/fortune-service/CoreParameterService!com.autosoft.fortune.interfaces.ICoreParameterService";
            lookUpName ="ejb:fortune-ear/fortune-service/CoreParameterService!com.autosoft.fortune.interfaces.ICoreParameterService";


            ICoreParameterService service = (ICoreParameterService)context.lookup(lookUpName);
          List<ApplicationParameterHeaderDTO> list =  service.getApplicationParameterHeaderList("200000");
          System.out.println(list);
    System.out.println ("Object Saved..!!");
} catch (Exception e) {
    e.printStackTrace();
}

}
}

否则我收到错误JBAS013323:用户无效

standalone.xml中的My Security域代码如下所示

 <security-domain name="AppJaasRealm" cache-type="default">
                <authentication>
                    <login-module code="Database" flag="required">
                        <module-option name="dsJndiName" value="java:/jdbc/fortuneDataSource"/>
                        <module-option name="principalsQuery" value="select vUser_Password from userinformation where vLogin_ID= ?"/>
                        <module-option name="rolesQuery" value="select '$APP_USER$', 'Roles' from userinformation where vLogin_ID= ?"/>
                        <module-option name="hashAlgorithm" value="SHA-256"/>
                        <module-option name="hashEncoding" value="Base64"/>
                    </login-module>
                </authentication>
            </security-domain>

什么是摆脱“JBAS013323:无效用户”错误并成功调用Rmote EJB的解决方案。 我看过tonz的帖子,但无法找到从远程调用我的EJB的正确解决方案。 我试图将所有可能的条目放在jndi属性和客户端属性中,但没有成功。

1 个答案:

答案 0 :(得分:0)

尝试在安全域下添加远程验证:

<security-domain name="AppJaasRealm" cache-type="default">
  <authentication>
    <login-module code="Remoting" flag="optional">
      <module-option name="password-stacking" value="useFirstPass"/>
    </login-module>
    <login-module code="Database" flag="required">
      <module-option name="dsJndiName" value="java:/jdbc/fortuneDataSource"/>
      <module-option name="principalsQuery" value="select vUser_Password from userinformation where vLogin_ID= ?"/>
      <module-option name="rolesQuery" value="select '$APP_USER$', 'Roles' from userinformation where vLogin_ID= ?"/>
      <module-option name="hashAlgorithm" value="SHA-256"/>
      <module-option name="hashEncoding" value="Base64"/>
    </login-module>
  </authentication>
</security-domain>
相关问题