Search code examples
jsonspringshiro

get the json data in shiro filter


I have a problem .
The json is posted by clinet using post method and is in request body.
I want to get the json data in my shiro filter.
But I didn't find any method to get it.
Is there any solution? I am using spring boot.

Thanks for your help


Solution

  • Firstly you would need to create your own filter class which extends one of Shiro's filters. Shiro provides a number of methods that you could overide to gain access to the request object, at diffent points in the lifecycle.

    The method you decide to override would depend on what you want to do, and you have not explained that in your question.

    Once you you have the request object simply read the body as follows:

        StringBuilder builder = new StringBuilder();
        BufferedReader reader = request.getReader();
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        return builder.toString();