1

TomEE 7.0.3 サーバーで ejb を実行しています。ところで、これはすべて Tomee 1.7.4 で機能していました。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>

ユーザー「admin」の資格情報を提供することで、URL http://127.0.0.1/tomee/ejbにアクセスできます。私の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" />

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

問題は、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

以下は、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");
}

ご覧のとおり、正しいユーザー名とパスワードを提供していますが、次の例外が発生します

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)

誰でもこれに光を当てることができますか?

4

1 に答える 1

0

tomcat-users.xml を使用すると、UserDatabaseRealm を server.xml のレルムとして使用したと想定されますが、そうではない可能性があります (質問には書かれていません)。これはまた、サーブレット/Tomcat バックボーンを介して認証が行われることを前提としています。tomee webapp に追加するまで、これはデフォルトでは当てはまりません (物理的に作成して ejbd サーブレットを定義できます - http://tomee.apache.org/ejbd-transport.htmlを参照してください- request.login( )。

ejbd プロトコル tomee を使用すると、デフォルトで server.xml の最初のレルムに依存する tomee セキュリティ サービスを使用して自動的にログインします。

于 2017-04-30T15:34:21.687 に答える