Package org.imixs.melman
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 Summary
Constructors Constructor Description FormAuthenticator(String _baseUri, String _jsessionid)Creates a new FormAuthenticator based on a baseUri and a valid JSESSIONIDFormAuthenticator(String _baseUri, String username, String password)Creates a new FormAuthenticator based on a baseUri and a username, password.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfilter(jakarta.ws.rs.client.ClientRequestContext requestContext)This filter method is called for each request.StringgetJsessionID()returns the current JESSIONIDvoidsetJsessionID(String jsessionID)Set a new JSESSIONID
-
-
-
Constructor Detail
-
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:
RestAPIExceptionMalformedURLException
-
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 Detail
-
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 IOExceptionThis 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:
filterin interfacejakarta.ws.rs.client.ClientRequestFilter- Throws:
IOException
-
-