Class FormAuthenticator

java.lang.Object
org.imixs.melman.FormAuthenticator
All Implemented Interfaces:
jakarta.ws.rs.client.ClientRequestFilter

public class FormAuthenticator extends Object implements jakarta.ws.rs.client.ClientRequestFilter
This RequestFilter performs a form based authentication. The filter can be used with a jakarta.ws.rs.client.Client.

The FormAuthenticator provides two constructors. One expects the base API url and a valid JSESSIONID, the other expects the base API url with userid/password and will request a JESSIONID automatically.

We t use the CookieHandler.setDefault(manger) here. Maybe we should refine the usage because for different threads possible the same CookieHandler is used. See details here: https://stackoverflow.com/questions/16305486/cookiemanager-for-multiple-threads To Avoid this problem we use a internal system to only store the JSESSIONID and set the cookie per each request.

Author:
rsoika
  • Constructor Details

    • FormAuthenticator

      public FormAuthenticator(String _baseUri, String _jsessionid) throws RestAPIException
      Creates a new FormAuthenticator based on a baseUri and a valid JSESSIONID
      Parameters:
      _baseUri -
      _jsessionid -
      Throws:
      RestAPIException
      MalformedURLException
    • FormAuthenticator

      public FormAuthenticator(String _baseUri, String username, String password) throws RestAPIException
      Creates a new FormAuthenticator based on a baseUri and a username, password. The constructor post the user credentials to the endpoint /j_security_check to receive a JSESSIONID.
      Parameters:
      _baseUri -
      username -
      password -
      Throws:
      RestAPIException
  • Method Details

    • getJsessionID

      public String getJsessionID()
      returns the current JESSIONID
      Returns:
    • setJsessionID

      public void setJsessionID(String jsessionID)
      Set a new JSESSIONID
      Parameters:
      jsessionID -
    • filter

      public void filter(jakarta.ws.rs.client.ClientRequestContext requestContext) throws IOException
      This filter method is called for each request. The method generates a new JSESSIONID cookies form the current JSESSIONID and stores the cookie in the header.

      Note: existing cookies will be overwritten!

      Specified by:
      filter in interface jakarta.ws.rs.client.ClientRequestFilter
      Throws:
      IOException