3

I am trying to create a RestEasy client for services host in JBPM server. The service url is always redirecting to a form based login screen which expects j_username and j_password.

I need to login to the service and also have to store the cookies to avoid authentication everytime. Please suggest the best implementation to achieve this.

Now all the service calls ends up in returning the login html page.

I tried some of the solutions posted here, but not works in my scenario.

RESTEasy client framework authentication credentials

RestEasy Client Authentication and HTTP Put with Marshalling

4

1 回答 1

0
  1. 首先,编写一个身份验证 servlet(您可以在其中拦截登录凭据并将它们存储到您的 cookie 中):

    @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. 在 中login_form,将操作映射到 servlet URL,例如:

    <form method="post" action="security_check">
    
  3. 对于除登录以外的所有其他请求,定义一个 url 模式(例如 protectedResourceUrlPattern)并使用来自 cookie 的凭据进行身份验证

于 2013-02-13T21:00:30.023 回答