2016-11-04 64 views
0

在我們的應用程序中,我們有幾個webservices.i需要獲得userids(意味着誰已經和webservice的名稱)爲了我需要存儲的審計目的。 任何人都可以建議哪個將是過濾器鏈或攔截器以及如何獲得webservice名稱。審覈用戶名,在restfull webservices中的服務

回答

1

您可以使用PreSecurityInterceptor做這件事,客戶端的請求將首先轉到它並且您可以在數據庫或文件中記錄數據。

import java.util.Date; 

import javax.servlet.http.HttpServletRequest; 
import javax.ws.rs.WebApplicationException; 
import javax.ws.rs.core.Context; 
import javax.ws.rs.core.Response; 
import javax.ws.rs.ext.Provider; 

/** 
* This interceptor verify the method name and log the details 
* */ 
import org.jboss.resteasy.annotations.interception.ServerInterceptor; 
import org.jboss.resteasy.core.ResourceMethod; 
//import org.jboss.resteasy.core.ResourceMethodInvoker; 
import org.jboss.resteasy.core.ServerResponse; 
import org.jboss.resteasy.spi.Failure; 
import org.jboss.resteasy.spi.HttpRequest; 
import org.jboss.resteasy.spi.interception.PreProcessInterceptor; 

@Provider 
@ServerInterceptor 
public class PreSecurityInterceptor implements PreProcessInterceptor { 
    @Context HttpServletRequest req; 

    @Override 
    public ServerResponse preProcess(HttpRequest request, ResourceMethod method) 
      throws Failure, WebApplicationException { 

     System.out.println("********************************************* pre process *****************************"); 

     System.out.println(new Date() + " Method : " + method.getMethod().getName() + " being called from " 
       + req.getRemoteHost()+":"+req.getLocalPort()+": Remote Port "+req.getRemotePort()); 

     if ("defaultMethod".equalsIgnoreCase(method.getMethod().getName())) { 
      return null; // normal flow continues 
     } else { 
      System.out.println(new Date() + " Method : " + method.getMethod().getName() + " Precondition failed "); 
      return (ServerResponse) Response 
        .status(Response.Status.PRECONDITION_FAILED).entity("invalid method details provided !!").build(); 
     } 
    } 
} 
+0

It Works Thanks Ravikant – Mahesh