2017-01-18 1 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

연결 연결 = RemotingContext.getConnection() << is null :( – user1028269

+0

@user1028269이 솔루션을 EAP7에서 확인하고 작동합니다 (https://github.com/fedesierr/eap7-ejb-remote 참조) –

+0

jboss-ejb3을 놓쳤습니다. .xml 인터셉터 설정, 고마워. – user1028269

-1

이 기사 [1]은 (는) JBoss 커뮤니티 위키에서 정확히 문제를 해결합니다. 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

관련 문제