WildFly Naming Client的程序化远程ejb调用问题?

时间:2019-06-17 13:38:47

标签: wildfly wildfly-10 ejb-3.2

WildFly Naming Client是否必须使用wildfly-config.xml?

由于以下原因,我将其删除并使用了程序化方法:

wildfly-config.xml包含用户凭据,这些凭据将在EJB中用作主体。我们有多个用户使用同一客户端。还使用自定义安全领域。因此,用户信誉每次都会改变。

但是使用Programmatic Approach进行查找会失败,但可以使用wildfly-config.xml方法进行查找。

这是wildfly-config.xml:

<configuration> 

    <authentication-client xmlns="urn:elytron:1.0"> 

        <authentication-rules> 

            <rule use-configuration="default"/> 

        </authentication-rules> 

        <authentication-configurations> 

            <configuration name="default">

<sasl-mechanism-selector selector="PLAIN"/>

                 <providers>

                     <use-service-loader />

                 </providers>

<set-user-name name="ejbuser1"/> 

                <credentials> 

                    <clear-password password="*****"/> 

                </credentials>

<set-mechanism-realm name="SSLRealm" />

            </configuration> 

        </authentication-configurations> 

    </authentication-client> 

    <jboss-ejb-client xmlns="urn:jboss:wildfly-client-ejb:3.0"> 

        <connections> 

            <connection uri="remote+http://localhost:8080" /> 

        </connections> 

    </jboss-ejb-client> 

</configuration>

完成此操作后,我删除了该文件并添加了程序化方法的代码:

    // create your authentication configuration

    AuthenticationConfiguration namingConfig = AuthenticationConfiguration.empty()

    .setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("PLAIN"))

    .useRealm("SSLRealm")

    .useName(username)

    .usePassword(password);



    // create your authentication context

    AuthenticationContext context = AuthenticationContext.empty()

    .with(MatchRule.ALL.matchHost("localhost"), namingConfig);



    // create a callable that creates and uses an InitialContext

    Callable<Void> callable = () -> {

        Properties properties1 = new Properties();

        properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");

        properties1.put(Context.PROVIDER_URL, ejbProperties.get("java.naming.provider.url"));

        ctx = new InitialContext(properties1);


        return null;

    };



    // use your authentication context to run your callable

    try {

       context.runCallable(callable);
       // ERROR HERE
       appBean = (AppRemote) ctx.lookup(getJNDIPrefix() + "AppBean!" + AppRemote.class.getName());
  } catch (NamingException e) {

       throw e;

  } catch (Exception e) {

       e.printStackTrace();

  }

然后出现以下错误:

  

原因:javax.security.sasl.SaslException:身份验证失败:   不支持服务器(PLAIN)提出的任何机制         在   org.jboss.remoting3.remote.ClientConnectionOpenListener $ Capabilities.handleEvent(ClientConnectionOpenListener.java:444)         在   org.jboss.remoting3.remote.ClientConnectionOpenListener $ Capabilities.handleEvent(ClientConnectionOpenListener.java:242)         在   org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)         在   org.xnio.conduits.ReadReadyHandler $ ChannelListenerHandler.readReady(ReadReadyHandler.java:66)         在   org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89)         在org.xnio.nio.WorkerThread.run(WorkerThread.java:591)处   ...异步调用...(来源未知)   org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:571)位于   org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:537)在   org.jboss.remoting3.ConnectionInfo $ None.getConnection(ConnectionInfo.java:82)         在   org.jboss.remoting3.ConnectionInfo.getConnection(ConnectionInfo.java:55)         在   org.jboss.remoting3.EndpointImpl.doGetConnection(EndpointImpl.java:488)         在   org.jboss.remoting3.EndpointImpl.getConnectedIdentity(EndpointImpl.java:434)         在   org.jboss.remoting3.UncloseableEndpoint.getConnectedIdentity(UncloseableEndpoint.java:52)         在   org.jboss.remoting3.Endpoint.getConnectedIdentity(Endpoint.java:123)         在   org.jboss.ejb.protocol.remote.RemoteEJBReceiver.lambda $ getConnection $ 2(RemoteEJBReceiver.java:185)         在java.security.AccessController.doPrivileged(本机方法)

有人猜猜怎么了?

0 个答案:

没有答案