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

Community
  • 1
  • 1
Rahul
  • 111
  • 2
  • 7

1 Answers1

0
  1. First, write an authetication servlet (where you can intercept the login credentials and store them to your 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. in the login_form, map the action to the servlet URL eg:

    <form method="post" action="security_check">
    
  3. for all other requests other than login, define a url pattern(eg protectedResourceUrlPattern) and autheticate using the credentials from cookie

Jules
  • 14,200
  • 13
  • 56
  • 101
  • Thank you for your fast Reply Sunitha. But my client is a standalone Resteasy client which is trying to communicate with the JBPM servers where we dont have access to their presenstation layers for authentication. When I give the service url in the browser it is redirecting to a login page which has a form based authentication and the username and password remains the same for all my requests. – Rahul Feb 13 '13 at 22:43