Unable to set Authentication Principal if Using Other Auth Service

Hi everyone,

I am creating a generic rest API project using JMIX version 1.5.3 . I want to use AWS Cognito as authentication service. In simple words, some of the API need to be authenticated first using this service i.e passing Bearer Token. My API structures can be divided into two which are controller & service. The controller handle the https request i.e POST, PUT & DELETE while service handle the business logic i.e if else statement. I had included piece of code in Cognito Config to detect its user detail if there is authentication takes part:

UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, “”, authorities);
authenticationToken.setDetails(claims);
return authenticationToken;

After authentication success then only it will trigger controller and service. FYI, I already enable Traits to detect which user was creating the data. My entity after data created is like this:

buyer_id |created_by
----------------------------------±--------
1064e1cb-24e3-488a-aeea-0c077b147b33|system

My issue are:

  1. Why created_by is “system” eventhough I already do some config
  2. When I want to perform display data I will encountered:

2023-11-28 17:13:40 - java.lang.RuntimeException: Authentication principal must be UserDetails

Overall issue was I unable to set Authentication Principal using the provided authentication service. Please help me & many thanks for your time.

Regards,
Syamil Zamzuri