Reputation: 11
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
Reputation: 169
Use spring security basic authorization
http://websystique.com/spring-security/secure-spring-rest-api-using-basic-authentication/
Upvotes: 0
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