0 Replies Latest reply on Oct 10, 2017 1:43 PM by paatalom

    Client Remote Address(Hostname or IP) into EJB Interceptor.

    paatalom

      hello team,

      I'm trying to retriev remote client address (IP Address)  and client jndi username into my ejb interceptor. but no success.

      Is there any example how to do this ?

      1. EJB Session Bean Sample Code :

       

      @Stateless  
      @Local(MyLocalInterface.class)  
      @Remote(MyRemoteInterface.class)  
      @RolesAllowed({"Role1", "Role2", "Role3"})  
      @Interceptors({MyEjbInterceptor.class})  
      public class MySessionBean implements MyLocalInterface, MyRemoteInterface {  
        
        
          @RolesAllowed("Role1")  
          @Override  
          @TransactionAttribute(TransactionAttributeType.REQUIRED)  
          public String someMethod() throws CentrProcessException {  
              try {  
                  return "Hello From Server";  
              } catch (Exception e) {  
                  e.printStackTrace();              
              }  
          }  
      }
      

       

      Here is my EJB Interceptor Class :

      public class MyEjbInterceptor{  
            
          @AroundInvoke  
          public Object handleEJBCall(InvocationContext context) throws Exception {  
        
        
              Map<String, Object> cData = context.getContextData();  
              if (cData != null) {  
                  Set<String> keys = cData.keySet();  
                  for (String key : keys) {  
                      Object value = cData.get(key);  
        
        
                      System.out.println("key = " + key + ", value = " + value.toString());  
                  }  
              }  
        
        
              Object params[] = context.getParameters();  
              if (params != null) {  
                  for (Object param : params) {  
                      System.out.println(" param = " + param.toString());  
                  }  
              }  
        
        
              System.out.println("context.getTarget() = " + context.getTarget());  
              System.out.println("context.getTimer() = " + context.getTimer());  
              String currentThreadName = Thread.currentThread().getName();  
              System.out.println("currentThreadName = " + currentThreadName);  
              System.out.println("--------------------------" + context.getMethod());  
              return context.proceed();  
          }
      }
      

       

       

      Everything is null or empty.

      I found some forums that told it is possible to get ip address from Thread name , but in my case is doesn't work.  Thread name is like : "default task-14"

       

      Task is very easy : I want check that remote client username has permission to call beans from that ip addres ....   I want set up username and ip address mapping by myself.

       

      Please hint any solution.

       

      Best Regards.

      Paata.