Package org.imixs.melman
Class FormAuthenticator
java.lang.Object
org.imixs.melman.FormAuthenticator
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionFormAuthenticator(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
Modifier and TypeMethodDescriptionvoidfilter(jakarta.ws.rs.client.ClientRequestContext requestContext) This filter method is called for each request.returns the current JESSIONIDvoidsetJsessionID(String jsessionID) Set a new JSESSIONID
-
Constructor Details
-
FormAuthenticator
Creates a new FormAuthenticator based on a baseUri and a valid JSESSIONID- Parameters:
_baseUri-_jsessionid-- Throws:
RestAPIExceptionMalformedURLException
-
FormAuthenticator
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
returns the current JESSIONID- Returns:
-
setJsessionID
Set a new JSESSIONID- Parameters:
jsessionID-
-
filter
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:
filterin interfacejakarta.ws.rs.client.ClientRequestFilter- Throws:
IOException
-