简体   繁体   中英

Form Based authentication support for RestEasy webservice client

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

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM