Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to secure a RESTful API in Spring Boot without mantain a jsessionid

I need to create a SpringBoot RESTful API to be consumed either by a web project or a mobile app.

My question is how to secure it without the typically basic authorization that returns you a "jsessionid" to the web browser and mantains the session with it. It's not a problem for the web project, because it could store that jsessionid. But how about to secure the mobile app request to the API?

Sorry for my english. Thanks.

like image 573
Fernando Fradegrada Avatar asked Jun 07 '16 13:06

Fernando Fradegrada


People also ask

What is the best way to secure a RESTful API?

Always use TLS Every web API should use TLS (Transport Layer Security). TLS protects the information your API sends (and the information that users send to your API) by encrypting your messages while they're in transit. You might know TLS by its predecessor's name, SSL.

How do I remove Jsessionid from spring boot?

Prevent Using URL Parameters for Session Tracking Starting with Spring 3.0, the URL rewriting logic that would append the jsessionid to the URL can now be disabled by setting the disable-url-rewriting=”true” in the <http> namespace.


1 Answers

One of the architectural constraints of REST is that it must be stateless.

Your REST API must not have sessions that authenticate the client. Instead, the client should pass some sort of token, commonly placed in the Authentication HTTP Header.

JWT and OAuth 2.0 are both very popular ways of doing this, and you can absolutely use HTTP Basic Authentication with OAuth 2.0 if you wish.

Here's an article called Stateless Authenticaiton with Spring Security and JWT. Hopefully that will help!

like image 110
Phil Sturgeon Avatar answered Nov 15 '22 05:11

Phil Sturgeon