简体   繁体   English

为什么在TomEE上远程调用EJB时​​会出现AuthenticationException?

[英]Why do I get a AuthenticationException when invoking the EJB remotely on TomEE?

I have a ejb running on a TomEE 7.0.3 server. 我在TomEE 7.0.3服务器上运行了一个ejb。 btw, all this was working in Tomee 1.7.4. 顺便说一下,这一切都在Tomee 1.7.4中有效。 I have setup a set of users using the tomcat-users.xml file 我使用tomcat-users.xml文件设置了一组用户

<tomcat-users>
    <role rolename="admin" />
    <role rolename="admin-gui" />
    <role rolename="admin-script" />
    <role rolename="manager" />
    <role rolename="manager-gui" />
    <role rolename="manager-script" />
    <role rolename="manager-jmx" />
    <role rolename="manager-status" />
    <role rolename="tomee-admin" />
    <user
        name="admin"
        password="admin"
        roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status,tomee-admin" />
    <role rolename="tomcat" />
    <user
        name="tomcat"
        password="tomcat"
        roles="tomcat" />
    <user
        name="manager"
        password="manager"
        roles="manager" />
</tomcat-users>

I am able able to access the url http://127.0.0.1/tomee/ejb by providing the credentials for user 'admin'. 我能够通过提供用户'admin'的凭据来访问URL http://127.0.0.1/tomee/ejb My server.xml file has the following entries 我的server.xml文件包含以下条目

<Resource auth="Container" description="User database that can be updated and saved"
    factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase"
    pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase" />

and

    <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI resources 
            under the key "UserDatabase". Any edits that are performed against this UserDatabase 
            are immediately available for use by the Realm. -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
            resourceName="UserDatabase" />
    </Realm>

The problem is when I try to invoke the ejb remotely, my JNDI InitialContext uses the following properties. 问题是当我尝试远程调用ejb时,我的JNDI InitialContext使用以下属性。

java.naming.factory.initial=org.apache.openejb.client.RemoteInitialContextFactory
java.naming.provider.url=http://127.0.0.1:8082/tomee/ejb
java.naming.security.principal=admin
java.naming.security.credentials=admin

Following is the code for calling the ejb. 以下是调用ejb的代码。

public static Object locateService(String serviceName) throws NamingException, IOException {
    InputStream in = ServiceLocator.class.getClassLoader().getResourceAsStream("servicelocator.properties");
    Properties p = new Properties();
    p.load(in);
    InitialContext ctx = new InitialContext(p);
    return ctx.lookup("PaymentManagerRemote");
}

As you can see I am supplying the correct username and password but I get the following exception 如您所见,我提供了正确的用户名和密码,但我得到以下异常

Apr 27, 2017 12:39:07 PM org.apache.openejb.client.EventLogger log
INFO: RemoteInitialContextCreated{providerUri=http://127.0.0.1:8082/tomee/ejb}
Exception in thread "main" javax.naming.AuthenticationException: Error while communicating with server: ; nested exception is: 
    javax.naming.AuthenticationException
    at org.apache.openejb.client.JNDIContext.authenticate(JNDIContext.java:381)
    at org.apache.openejb.client.JNDIContext.getInitialContext(JNDIContext.java:289)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
    at javax.naming.InitialContext.init(InitialContext.java:244)
    at javax.naming.InitialContext.<init>(InitialContext.java:216)
    at co.uk.meghdoot.core.util.ServiceLocator.locateService(ServiceLocator.java:20)
    at co.uk.meghdoot.core.test.DeviceLocationTest.setUp(DeviceLocationTest.java:53)
    at co.uk.meghdoot.core.test.DeviceLocationTest.main(DeviceLocationTest.java:109)

Can anyone shed some light on this? 任何人都可以对此有所了解吗?

using tomcat-users.xml assumes you used UserDatabaseRealm as realm in server.xml which is maybe not the case (not written in your question). 使用tomcat-users.xml假设您在server.xml中使用UserDatabaseRealm作为域,这可能不是这种情况(未在您的问题中写入)。 This also assume the authentication is done through servlet/tomcat backbone. 这也假设认证是通过servlet / tomcat骨干完成的。 This is not the case by default until you added in tomee webapp (you can create it physically and define the ejbd servlet - see http://tomee.apache.org/ejbd-transport.html - a filter doing a request.login(). 默认情况下不是这种情况,直到您添加到tomee webapp(您可以在物理上创建它并定义ejbd servlet - 请参阅http://tomee.apache.org/ejbd-transport.html - 执行request.login的过滤器( )。

Using ejbd protocol tomee will automatically log in using tomee security service which will rely on the first realm of the server.xml by default. 使用ejbd协议tomee将使用tomee安全服务自动登录,该服务默认依赖于server.xml的第一个领域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM