我有独立的Java客户端(在eclipse中运行)我希望连接到外部服务器。如果服务器是localhost,那么我看不出任何问题。但是每当我尝试连接到外部服务器时,我总是会遇到以下异常
- JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
- Could not register a EJB receiver for connection to remote://10.160.148.61:4447
java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
我尝试按照EJB invocations from a remote client using JNDI
提到的步骤进行操作异常告诉我,与身份验证相关的配置文件有问题。这是我的ejb_client_properties文件
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=10.160.148.61
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=tan
remote.connection.default.password=f2b1c3c7d3f1e224cbf6508494cf0418
注意:用户tan被添加到服务器上的mgt.user.properties文件中。我使用add-user.bat在服务器中添加用户。我还添加了一个应用程序用户。我使用相同的凭据传递给服务器。我想不出别的什么。
我的ejb电话如下:
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
InitialContext aJNDI = new InitialContext(jndiProperties);
Ppi handle = (Ppi) aJNDI
.lookup("ejb:PPIEAR/PService/PConnect!com.gem.p.PConnection?stateful");
我看到许多线程与异常相关但无法修复它:(有人可以帮忙。
我还在服务器上安装了合法的SSL证书。我是否需要做一些额外的事情才能解决这个问题?
另请注意:我的服务器在独立模式下运行。
答案 0 :(得分:18)
好的,我已经能够找出问题所在。
这是在服务器端错误地添加应用程序用户的情况。具体见下文。
[userone@localhost bin]$ ./add-user.sh
What type of user do you wish to add?
a) Management User (mgmt-users.properties)
b) Application User (application-users.properties)
(a): b
Enter the details of the new user to add.
Realm (ApplicationRealm) : ApplicationRealm ---->> Careful Here . You need to type this or leave it blank . I filled an incorrect value here and things went wrong from there .
Username : testuser
Password : testpassword
Re-enter Password : testpassword
What roles do you want this user to belong to? (Please enter a comma separated list, or leave blank for none) : testrole
About to add user 'testuser' for realm 'ApplicationRealm'
Is this correct yes/no? yes
Added user 'testuser' to file '/home/userone/jboss-as-7.1.0.Final/standalone/configuration/application-users.properties'
Added user 'testuser' to file '/home/userone/jboss-as-7.1.0.Final/domain/configuration/application-users.properties'
Added user 'testuser' with roles testrole to file '/home/userone/jboss-as-7.1.0.Final/standalone/configuration/application-roles.properties'
Added user 'testuser' with roles testrole to file '/home/userone/jboss-as-7.1.0.Final/domain/configuration/application-roles.properties'
.
.
我花了很长时间才弄明白这一点。有用的链接:: http://middlewaremagic.com/jboss/?p=1466
答案 1 :(得分:1)
一种选择是
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(Context.SECURITY_PRINCIPAL, username);
jndiProperties.put(Context.SECURITY_CREDENTIALS, password);
InitialContext aJNDI = new InitialContext(jndiProperties);
使用具有访问权限的用户名。
jndi.properties中可以提供相同的内容,请参阅documentation