Because after calling mergeAttributes of DefaultAuthenticationResultBuilder 
class, everything in the Principal is returned as List.

2 Eylül 2019 Pazartesi 12:12:51 UTC+3 tarihinde Cemal Önder yazdı:
>
> Hi everyone,
>
> 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\"]}"}}
>
>
> )
>
>

-- 
- Website: https://apereo.github.io/cas
- Gitter Chatroom: https://gitter.im/apereo/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
--- 
You received this message because you are subscribed to the Google Groups "CAS 
Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/a/apereo.org/d/msgid/cas-user/102ff478-6dcc-48b2-92cf-4db7559ffdbc%40apereo.org.

Reply via email to