2017-01-18 8 views

答えて

1

あなたがリモート接続とIPアドレスを取得して試すことができます。 org.jboss.as.security-apiは、将来のバージョンで削除される可能性のある非推奨のモジュールであるため、どの程度信頼性が高いかわかりません。その後

folowingしてみてください:

コンテナインターセプタ:

import javax.interceptor.AroundInvoke; 
import javax.interceptor.InvocationContext; 
import java.net.InetAddress; 
import java.security.Principal; 

import org.jboss.remoting3.Connection; 
import org.jboss.remoting3.security.InetAddressPrincipal; 
import org.jboss.as.security.remoting.RemotingContext; 


public class ClientIpInterceptor { 

    @AroundInvoke 
    private Object iAmAround(final InvocationContext invocationContext) throws Exception { 
     InetAddress remoteAddr = null; 
     Connection connection = RemotingContext.getConnection(); 

     for (Principal p : connection.getPrincipals()) { 
      if (p instanceof InetAddressPrincipal) { 
       remoteAddr = ((InetAddressPrincipal) p).getInetAddress(); 
       break; 
      } 
     } 

     System.out.println("IP " + remoteAddr); 

     return invocationContext.proceed(); 
    } 
} 

のjboss-ejb3.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<jboss xmlns="http://www.jboss.com/xml/ns/javaee" 
     xmlns:jee="http://java.sun.com/xml/ns/javaee" 
     xmlns:ci ="urn:container-interceptors:1.0"> 

    <jee:assembly-descriptor> 
     <ci:container-interceptors> 
      <jee:interceptor-binding> 
       <ejb-name>*</ejb-name> 
       <interceptor-class>ClientIpInterceptor</interceptor-class> 
      </jee:interceptor-binding> 
     </ci:container-interceptors> 
    </jee:assembly-descriptor> 
</jboss> 

のjboss-展開するstructure.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"> 
<deployment> 
    <dependencies> 
     <module name="org.jboss.remoting3" /> 
     <module name="org.jboss.as.security-api" /> 
    </dependencies> 
</deployment> 
</jboss-deployment-structure> 
+0

Connection connection = RemotingContext.getConnection()<< is null :( – user1028269

+0

@ user1028269このソリューションをEAP7でチェックして動作します(https://github.com/fedesierr/eap7-ejb-remoteを参照) –

+0

jboss-ejb3が見つかりませんでした.xmlインターセプターの設定、ありがとう。 – user1028269

-1

JBossコミュニティwikiのこの記事[1]は、あなたの問題を正確に解決します。 JBoss 5より前のバージョンでは、明らかにIPアドレスがワーカースレッド名から解析されていなければなりません。そしてそれが以前のバージョンでそれを行う唯一の方法であるように思われます。

private String getCurrentClientIpAddress() { 
    String currentThreadName = Thread.currentThread().getName(); 
    System.out.println("Threadname: "+currentThreadName); 
    int begin = currentThreadName.indexOf('[') +1; 
    int end = currentThreadName.indexOf(']')-1; 
    String remoteClient = currentThreadName.substring(begin, end); 
    return remoteClient; 
} 

[1] https://developer.jboss.org/wiki/HowtogettheClientipaddressinanEJB3Interceptor

+0

私のアプリケーションはEAP 7で動作します。 – user1028269

関連する問題