Dozen
Dozen

Reputation: 11

Spring request response send null value

Hi i built a backend with Spring and was thinking about whats the best solution in this case:

I normally respond a request with a pojo with some data. But when the requesting user is not authorized i respond with null, what seems to be a ugly way.

I thought it could be the better way, to return a response entity http unauthorized but the return type is the data pojo.

Maybe i have to change my security config and must! filter the users before the controller method is called?

Upvotes: 0

Views: 176

Answers (2)

Udara Gunathilake
Udara Gunathilake

Reputation: 224

Yes, You should validate the request before calling the Controllers by creating Interceptor.You can use JWT tokens for validations.If the user is unauthorised application should respond with Unauthorised.

Upvotes: 1

Related Questions