I have a JSON problem while returning custom attributes in my custom authentication handler:
return createHandlerResult( credential,
this.getPrincipalFactory( ).createPrincipal( credential.getId( ), attributes) );
which createPrincipal method accepts Map<String, Object>
Principal createPrincipal(String id, Map<String, Object> attributes);
When I put Map<String, List> here, it returns toString representation of the List instead of its JSON representation. Or when I add Map, it returns {"left": "key", "right": "value"}.I have been debugging for 1 week, I see how CAS uses json-smart-2.3 library. I see that when I send Map in the Object of Map<String, Object> for the attributes, json-smart library uses its writers, for the map it uses
BeansWriter which gets fields of the class and uses as keys. So it makes sense for the HashMap, it adds left and right fields to the JSON body which I don't want.
In short I want my CAS server return Map of attributes in correct JSON way like how org.json.JSONMapper does. How can I achieve this?
(
Also I tried directly return JSON representation in the Object section of attributes:
Map<String, Object> attributes = new HashMap<>();
String roles = "{"TestModule":["Name1"]}"; (didn't add escape quotes for simplicity)attributes.put("roles", roles);
But CAS somehow returns my String as LinkedList to the json-smart library. So library uses its Writer for LinkedLists, which adds [] to the response which I don't want like:
I don't want this:
{"rolesPerModule":["{\"TestModuleForBouncer_LIVE\":[\"ADMIN\"]}"]}
I want like:
{"rolesPerModule":{"{\"TestModuleForBouncer_LIVE\":[\"ADMIN\"]}"}}
)