2013-02-13 87 views
2

我正在嘗試在JBPM服務器上創建服務主機的RestEasy客戶端。服務url總是重定向到一個基於表單的登錄屏幕,它需要j_username和j_password。RestEasy webservice客戶端的表單驗證支持

我需要登錄到服務,並且還必須存儲cookie以避免每次都進行身份驗證。請提出最佳實施方案以實現此目標。

現在所有的服務調用都以返回登錄html頁面結束。

我嘗試了一些在這裏發佈的解決方案,但不適用於我的方案。

RESTEasy client framework authentication credentials

RestEasy Client Authentication and HTTP Put with Marshalling

回答

0
  1. 首先,寫一個authetication的servlet(在這裏你可以攔截登錄憑據,並將它們存儲到您的Cookie):在login_form

    @WebServlet(urlPatterns = {"/security_check"}) 
    
    public class AuthenticationServlet extends HttpServlet 
    
    { 
    
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throwsServletException, IOException 
        { 
    
    request.login(userName, userPassword); 
    
    StoreInCookieMethod(request.getUserPrincipal().getName(), userPassword); 
    
    response.sendRedirect(request.getContextPath() + "/protectedResourceUrlPattern/"); 
    
        } 
    } 
    
  2. ,將操作映射到servlet URL 例如:

    <form method="post" action="security_check"> 
    
  3. 除登錄以外的所有其他請求,利用cookie中的憑證定義URL模式(例如protectedResourceUrlPattern)和autheticate

+0

謝謝您的回覆快Sunitha。但是我的客戶端是一個獨立的Resteasy客戶端,它試圖與JBPM服務器進行通信,在這些服務器中,我們沒有訪問他們的前臺層進行身份驗證。當我在瀏覽器中提供服務URL時,它將重定向到具有基於表單身份驗證的登錄頁面,並且用戶名和密碼對於我的所有請求都保持不變。 – Rahul 2013-02-13 22:43:15