Spring boot + Vaadin Flow + Spring session (REDIS) + Spring Security. Sessi

Thanks @leif Astrand. Do you know if this will allow me to make a flow app stateless? The examples don’t seem to insinuate the vaadin services are just creating json which is what my REST controllers already do. I am looking for a way to have a stateless vaadin application that has no need for a maintained session across requests.

I am looking for a way to have a stateless vaadin application that has no need for a maintained session across requests.

There is currently no established way to do that, since the whole idea of idea of Vaadin is to make possible to create the UI logic in Java, which means that UI logic will be running on jvm in server. This means that there will some state maintained in server, and Vaadin in that way is inherently statefull.

We however have been experimenting with idea of stateless here https://vaadin.com/labs/vaadin-connect This solution is still a draft (and further polished version is being development in our future development track here https://github.com/vaadin/platform/releases/tag/15.0.0.alpha5 ). The idea of this Connect solution is that you can augment Vaadin application with stateless parts, but in that case you can’t develop those with Java, but need to use TypeScript for the UI logic, since it will be run browser side.

Is it possible and how, just to store jsessionid in Redis map and after server restart get it from request? And login user automatically (value in map are credentials) without storing all session data (maybe last url, or some json with descriptive state). It will cause reloading but it is better than nothing. At least user wouldn’t need to login again manually.

We tried to store jsession id from vaadin wrapped session but it is changed after tomcat restart and we cannot catch that old one from new request and replace it with new. Is it ok to check in cookies and match if exists in redis map?

Yes it would be a good alternative.

You don’t need the jessionId. Just create your own Id that you save in the cookie. If your info is not that big, even only the cookie could be necessary, not even Redis.

Be careful to encrypt your cookie or use some other security mechanism like a signature. A user could change the cookie value with another user Session Id and steal the session.

Alejandro R.:
Hi Alejandro, of course.

Download the vaadin bakery starter project https://vaadin.com/start/latest/full-stack-spring

Add the following dependencies to the pom.xml to use spring sessions:

<dependency>
	<groupId>org.springframework.session</groupId>
	<artifactId>spring-session-data-redis</artifactId>
</dependency>
	
<dependency>
    <groupId>io.lettuce</groupId>
    <artifactId>lettuce-core</artifactId>
    <version>5.0.5.RELEASE</version>
</dependency>

And finally configure the application.properties with these lines:

spring.session.store-type=redis
spring.redis.host= #my redis server ip
spring.redis.port=6379

When I login, the main page of the application is continuously refreshing giving me the following lines in the browser console:

Navega a http://localhost:8080/login
Setting heartbeat interval to 300sec. client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Scheduling heartbeat in 300 seconds client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:196:18
Starting application ROOT-2521314 client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Vaadin application servlet version: 1.0.5 client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Handling message from server client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:976:565
Handling dependencies client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:923:37
StateTree after applying changes: client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:941:114
Object { pushConfiguration: {…}, elementData: {…}, clientDelegateHandlers: [], polymerServerEventHandlers: []

, synchronizedPropertyEvents: , virtualChildrenList:
, elementChildren: (1) […]
, classList: }

client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
handleUIDLMessage: 16 ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
First response processed 2886 ms after fetchStart client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Processing time was 503ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Sending xhr message to server: {“csrfToken”:“e93f7e75-ef36-471a-99c6-4f6fa2cc7a82”,“rpc”:[{“type”:“event”,“node”:41,“event”:“opened-changed”},{“type”:“publishedEventHandler”,“node”:33,“templateEventMethodName”:“setDetailsVisible”,“templateEventMethodArgs”:[null]
},{“type”:“publishedEventHandler”,“node”:33,“templateEventMethodName”:“sortersChanged”,“templateEventMethodArgs”:[
]},{“type”:“publishedEventHandler”,“node”:33,“templateEventMethodName”:“confirmUpdate”,“templateEventMethodArgs”:[0]
}],“syncId”:0,“clientId”:0} client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Server visit took 309ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
JSON parsing took 0ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Received xhr message: for(;;);[{“meta”:{“sessionExpired”:true}}]
client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Response didn’t contain a server id. Please verify that the server is up-to-date and that the response data has not been modified in transmission. client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:961:114
Handling message from server client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:976:565
Handling dependencies client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:923:37
handleUIDLMessage: 0 ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Navega a http://localhost:8080/
Setting heartbeat interval to -1sec. client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Disabling heartbeat client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:815:99
Processing time was 5ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Setting heartbeat interval to 300sec. client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Scheduling heartbeat in 300 seconds client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:196:18
Starting application ROOT-2521314 client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Vaadin application servlet version: 1.0.5 client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Handling message from server client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:976:565
Handling dependencies client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:923:37
StateTree after applying changes: client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:941:114
Object { pushConfiguration: {…}, elementData: {…}, clientDelegateHandlers: , polymerServerEventHandlers:
, synchronizedPropertyEvents: , virtualChildrenList:
, elementChildren: (1) […]
, classList: }
client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
handleUIDLMessage: 16 ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
First response processed 2766 ms after fetchStart client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Processing time was 512ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Sending xhr message to server: {“csrfToken”:“e93f7e75-ef36-471a-99c6-4f6fa2cc7a82”,“rpc”:[{“type”:“event”,“node”:41,“event”:“opened-changed”},{“type”:“publishedEventHandler”,“node”:33,“templateEventMethodName”:“setDetailsVisible”,“templateEventMethodArgs”:[null]
},{“type”:“publishedEventHandler”,“node”:33,“templateEventMethodName”:“sortersChanged”,“templateEventMethodArgs”:[
]},{“type”:“publishedEventHandler”,“node”:33,“templateEventMethodName”:“confirmUpdate”,“templateEventMethodArgs”:[0]
}],“syncId”:0,“clientId”:0} client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Server visit took 307ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
JSON parsing took 0ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Received xhr message: for(;;);[{“meta”:{“sessionExpired”:true}}]
client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Response didn’t contain a server id. Please verify that the server is up-to-date and that the response data has not been modified in transmission. client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:961:114
Handling message from server client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:976:565
Handling dependencies client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:923:37
handleUIDLMessage: 0 ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Navega a http://localhost:8080/
Setting heartbeat interval to -1sec. client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Disabling heartbeat client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:815:99
Processing time was 4ms client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18
Setting heartbeat interval to 300sec. client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js:182:18


The session apparently is working, because when i restart my embedded Tomcat, the login page doesn't appear and I can see in my redis-cli the logged user.


I am getting the below error after adding above dependencies

for(;;);[{“changes”:{},“resources”:{},“locales”:{},“meta”:{“appError”:{“caption”:“Communication problem”,“url”:null,“message”:“Take note of any unsaved data, and click here or press ESC to continue.”,“details”:null}},“syncId”:-1}]