public static User parseUser()

in src/main/java/org/opensearch/search/asynchronous/utils/UserAuthUtils.java [19:51]


    public static User parseUser(Map<String, Object> userDetails) throws IOException {
        if(userDetails == null) {
            return null;
        }
        String name = "";
        List<String> backendRoles = new ArrayList<>();
        List<String> roles = new ArrayList<>();
        List<String> customAttNames = new ArrayList<>();
        for (Map.Entry<String,Object> userDetail : userDetails.entrySet())
        {
            String fieldName = userDetail.getKey();
            switch (fieldName) {
                case User.NAME_FIELD:
                    name = (String) userDetail.getValue();
                    break;
                case User.BACKEND_ROLES_FIELD:
                    if(userDetail.getValue()!= null)
                        backendRoles = (List<String>) userDetail.getValue();
                    break;
                case User.ROLES_FIELD:
                    if(userDetail.getValue()!= null)
                        roles = (List<String>) userDetail.getValue();
                    break;
                case User.CUSTOM_ATTRIBUTE_NAMES_FIELD:
                    if(userDetail.getValue()!= null)
                        customAttNames = (List<String>) userDetail.getValue();
                    break;
                default:
                    break;
            }
        }
        return new User(name, backendRoles, roles, customAttNames);
    }