Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 30 2019 21:15
    vpavic milestoned #333
  • Jan 30 2019 21:15
    vpavic milestoned #204
  • Jan 30 2019 20:50
    vpavic milestoned #1329
  • Jan 30 2019 20:50
    vpavic labeled #1329
  • Jan 30 2019 20:50
    vpavic opened #1329
  • Jan 30 2019 20:42
    vpavic labeled #78
  • Jan 30 2019 20:42
    vpavic closed #78
  • Jan 30 2019 20:41
    vpavic labeled #22
  • Jan 30 2019 20:41
    vpavic closed #22
  • Jan 30 2019 20:41
    vpavic labeled #21
  • Jan 30 2019 20:41
    vpavic closed #21
  • Jan 30 2019 20:41
    vpavic labeled #19
  • Jan 30 2019 20:41
    vpavic closed #19
  • Jan 30 2019 18:22
    ltzdby opened #1328
  • Jan 29 2019 20:57
    vpavic closed #1327
  • Jan 29 2019 20:56

    vpavic on 2.0.x

    Ignore failed rename operation … (compare)

  • Jan 29 2019 20:50
    vpavic labeled #1327
  • Jan 29 2019 20:50
    vpavic milestoned #1327
  • Jan 29 2019 20:50
    vpavic labeled #1327
  • Jan 29 2019 20:50
    vpavic labeled #1327
Nuno Marujo
@nhmarujo

Hi everyone. I’m using Spring Session Hazelcast in my stack. The ecosystem is composed by several microservices that are all connected as nodes on Hazelcast.
I’m facing an issue when trying to use those services with different versions of Spring Security. I basically get this error when I try do deserialize the session:

java.io.InvalidClassException: org.springframework.security.core.context.SecurityContextImpl; local class incompatible: stream classdesc serialVersionUID = 420, local class serialVersionUID = 520

from what I digged so far, it seems that Spring Security uses different serialVersionUID for different Spring Security versions intentionally:
image.png
So, the issue seems to be when desirializing the MapSession object from Hazelcast, since this object contains Spring Security specific classes. But by the way Spring Session works, it seems to me that what goes into MapSession is out of our control (except for the Principal part)
Nuno Marujo
@nhmarujo
What is the correct way to use Spring Session so that we don’t fall into this limitations when we try to bump versions?
Greg L. Turnquist
@gregturn
Does Hazelcast support using Jackson instead of native serialization? If so, you might consider that. @vpavic may know if this is a way to side step serial UIDs.
Joseph Nicholas R. Alcantara
@josephnicholas
Does spring session have concurrent session management like Spring security session? If not, is there a way it implement one?
Eleftheria Stein-Kousathana
@eleftherias
@josephnicholas Yes, you can use Spring Security concurrent session management with Spring Session.
Joseph Nicholas R. Alcantara
@josephnicholas
@eleftherias Good to see you here, we can continue our discussion from StackOverflow, did you have anymore questions?
Joseph Nicholas R. Alcantara
@josephnicholas

Hello again, when creating a SessionRegistryImpl bean, f.e

   @Bean
    fun sessionRegistry(): SessionRegistryImpl {
        return SessionRegistryImpl()
    }

Is it automatic that when I autowire it, it will be the registy will be populated with user sessions?

Eleftheria Stein-Kousathana
@eleftherias
@josephnicholas The SessionRegistry bean will not be automatically picked up when you are using concurrent session control with Spring Security.
You will need to specify it in your Security DSL.
http
    .sessionManagement { sessionManagement -> sessionManagement
        .sessionConcurrency { sessionConcurrency -> sessionConcurrency
            .maximumSessions(1)
            .sessionRegistry(sessionRegistry())
    }
}
Joseph Nicholas R. Alcantara
@josephnicholas

@eleftherias Yep, I already added that on my SecurityConfig. By then I can @Autowire sessionRegistry right?
What if sessionRegistry always returns empty or 0, does that mean I have wrongly configured it?

And also will it also be the same if I am using HttpSessionJDBC?

Joseph Nicholas R. Alcantara
@josephnicholas
How do I override onExpiredSessionDetectedand throw an error in JSON instead of redirecting to a URL?
Eleftheria Stein-Kousathana
@eleftherias
@josephnicholas As part of Spring Security, you can create a custom SessionInformationExpiredStrategy and override onExpiredSessionDetected.
You can then specify your custom strategy in the DSL
http
    .sessionManagement()
        .maximumSessions(1)
            .expiredSessionStrategy(new CustomSessionInformationExpiredStrategy());
choubani amir
@amirensit
Hello.
I started learning spring sessions. I started by HttpSession with Redis Guide.
The first problem I encounter is that the github repo does not contain the tips provided here.
Here is where I looked.
Any idea ?
Eleftheria Stein-Kousathana
@eleftherias

@amirensit The Spring Boot Redis sample is intended to be simple, so that users can add the customizations that they need.
The additional properties mentioned in the documentation are not included in the sample because they are not applicable to all use-cases.
I can see that it confusing that we are not specifying the store-type in the Redis sample.
This is explained in the Spring Boot documentation:

If a single Spring Session module is present on the classpath, Spring Boot uses that store implementation automatically. If you have more than one implementation, you must choose the StoreType that you wish to use to store the sessions.

I have also created spring-projects/spring-session#1610 to clarify that part in the Spring Session docs.

choubani amir
@amirensit
@eleftherias ok Thanks
Joseph Nicholas R. Alcantara
@josephnicholas
In spring session, is it possible to add attributes in the current user’s session? I have tried doing setAttributes but it doesn’t add the custom attribute in the session.
Joseph Nicholas R. Alcantara
@josephnicholas
Another question, about AuthenticationSuccessHandler…. When does a session get created? Because it seems when I query a session by username with a custom AuthenticationSuccessHandler, it seems that the session is still not created.
please help
Eleftheria Stein-Kousathana
@eleftherias
@josephnicholas Where does the setAttributes method you are referring to come from? Are you using Session.setAttribute(String attributeName, Object attributeValue. There are some examples using that function in the reference docs https://docs.spring.io/spring-session/docs/2.2.2.RELEASE/reference/html5/#api-session
Joseph Nicholas R. Alcantara
@josephnicholas
@eleftherias Hey, thanks for the reply. Yes, I am using that method. One clarification I want to ask is, when does the user session get created. I tried doing a custom SessionAuthenticationStrategy and on the onAuthentication I tried to get the user’s session, but it seem it can’t be found, maybe not created yet. When would be the best time to query the user’s session?
Eleftheria Stein-Kousathana
@eleftherias
@josephnicholas How are you getting the session? RegisterSessionAuthenticationStrategy is an example of getting the session from the request in the onAuthentication method. Perhaps you can follow the same pattern used there.
This discussion is not specific to using spring-session, it is really about spring-security functionality.
It would be helpful if you could post any followup questions or comments in the spring-security gitter instead.
Keeping the topics separated like this can help anyone facing the same issue easily find this discussion.
Joseph Nicholas R. Alcantara
@josephnicholas
Thanks @eleftherias
Mohd Rashid
@MohdRashid01
Hi All, I'm getting below issue in IntelliJ
Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint spring_session_attributes_pk
anyone help me how to solve this above issue
Eleftheria Stein-Kousathana
@eleftherias
@CloudNetwork Check out spring-projects/spring-session#1031, you may be having the same issue
Jeffrey Fate
@jeffreyfate

Hey there spring-session experts!

I'm hoping someone here will be willing to help solve an issue I have with our SB 1.5.22 application with spring-session and JDBC:

Any transactions that occur on a separate thread (most common use case is inside of methods annotated with @Scheduled), are marked as NOT_ACTIVE as the TransactionStatus, so they don't commit.

If I remove spring session by setting

spring.session.store-type=none

the transactions are marked as ACTIVE and commit successfully.

Perhaps there is a configuration I missed or had already configured our application incorrectly.

Where should I start?

8 replies
choubani amir
@amirensit
Hi
Not sure but I think this part of documentation does not make sense.
(the Servlet Container Initialization for httpSession with hazelcast)
@eleftherias
Craig Andrews
@candrews
I've set up Spring Session JDBC and Spring Security in my Spring Boot 2.2.7 application. I've set the maximum number of sessions for a user to 1 with http.sessionManagement().maximumSessions(1)
And that works. Which surprises me.
I did not do .sessionRegistry(sessionRegistry()) as documented at https://docs.spring.io/spring-session/docs/current/reference/html5/#spring-security-concurrent-sessions
So it seems that .sessionRegistry(sessionRegistry()) is not necessary leading me to believe that the documentation should be updated to remove this step.
Thoughts?
Craig Andrews
@candrews
Reported including sample project at spring-projects/spring-session#1629
Smalis Sklavos
@ssklavos-ed

Hello, I have a strange issue during the initialization of Redis data session. : org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisMessageListenerContainer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Unsatisfied dependency expressed through method 'redisMessageListenerContainer' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionRepository' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid @Scheduled method 'cleanupExpiredSessions': For
input string: "${spring.session.cleanup.cron.expression:0"

Seems that the spring.session.cleanup.cron.expression: does not properly read the value it has .. and reads only the fires 0 from the cron. (Spring Session 1.3.5 / Regular spring MVC configuration)

Enes Ozcan
@enozcan
Hi,
As I see there is a scheduled clean up task for expired sessions in JDBC solutions. How about in memory ones? Are session evictions from datastore completely up to in memory store - other than the expiry check when a session is fetched from the session repository? I wonder what happens when no eviction size/policy is set for the data store and a session is never fetched from the repository after it's created. In that case, will the session live forever in data store?
Carlos B
@balbuenac_twitter
Currently when using spring-session and DB2 looks like we are having lock timeouts with this query:
private static final String GET_SESSION_QUERY =
"SELECT S.SESSION_ID, S.CREATION_TIME, S.LAST_ACCESS_TIME, S.MAX_INACTIVE_INTERVAL, SA.ATTRIBUTE_NAME, SA.ATTRIBUTE_BYTES " +
"FROM %TABLE_NAME% S " +
"LEFT OUTER JOIN %TABLE_NAME%_ATTRIBUTES SA ON S.SESSION_ID = SA.SESSION_ID " +
"WHERE S.SESSION_ID = ?";
Im guessing this is doing full scan. New version of the same query do index scan. I wonder if this could be the problem.
Stephan R
@mrpubnight_gitlab

I'm reaching out here in hopes that someone will be able to help. We've recently upgraded from Zuul (backed by JDBC for session persistence) to Spring Cloud Gateway, (running Netty) using Redis for the sessions. We're seeing a large number of IllegalStateException: Session was invalidated exceptions.

Digging through the code we see that this exception gets thrown if/when the session doesn't exist, however, I'm not entirely sure I understand the conditions by which this can happen and how/why we're seeing this exception so often. The exception in itself isn't a big deal, however, we also observe that occasionally we get stuck in a strange loop whereby user's can't seem to establish a new session successfully and Gateway serves up a 500 with [authorization_request_not_found] error. If I monitor the redis commands I can see the hset commands but it continuously fails.

Unfortunately I can't figure out a consistent pattern to repro this (making it increasingly more frustrating) and I'm hoping someone can provide some insight.

Thanks

Stephan R
@mrpubnight_gitlab
^^ I should add that we're connecting to Redis (on AWS) using Lettuce and have configured the master to be the primary endpoint of the cluster and the read-only to be an additional node. Previously we had physically set up the other nodes in the cluster individually, however, we found the primary switching often because of fail-overs.
Akhilesh Tyagi
@tyagiakhilesh

Hello All,

I have a java application and I use spring-session backed by redis for that. I have another application written in PHP which is hosted on same domain. Some requests go to that php application as well. I want to have some mechanism where a user first lands on java application. Shall authenticate and now a cookie shall be created. Now when hits some pages which are in PHP, I want the php application to work seamlessly and use java created session for authentication.

Question 1: Is it possible to do ?
Question 2: If answer to above question is yes, then how ?

Looking forward to suggestions/comments/help.

sachinsaju
@sachinsaju
Hi I am using redis as my session store. Getting and Setting session works fine for me when redis is up.But when redis goes down, I get exceptions.
Is there any way I can set and get session attributes in the server itself when the redis goes down ? I searched for solutions in stackoverflow but reaching questions with no answers. Any suggestions or approaches for this scenario? Thanks
frothyauthy
@frothyauthy
any way to disable the keyspace notifications? It doesnt look like they actually do anything in my app (im not using the events) and im having anxiety over the excess cpu usage and scaling implications (the notifications hit every instance of my app)
Petar Tahchiev
@ptahchiev
hello everyone. Has any of you tried to implement multi-tenant connection to Redis key-value store? Would be nice if spring-session provided a way resolve the database number at runtime. I believe by default it is all stored in the 0 database. Can you give me some guidance how to override it?
Florian Beaufumé
@fbeaufume
Hello guys. I'm an exprienced Spring and backend developer, but new to Spring Session Redis.
I plugged it in a backend and was surprised by the added latency, about 60 msec in my case. For simple web requests that do not modifiy the HttpSession I counted 9 Redis calls (the commands are : HGETALL, HMSET, SADD, PEXPIRE, APPEND, PEXPIRE, PEXPIRE, HGETALL, HGETALL). That seems high.
Question 1 : is it normal ?
Question 2 : is there tuning or optimization to reduce the Spring Session Redis latency ?
Question 3 : could using a different store (MongoDB or other) reduce the Spring Session latency ?
Thank you for your help.
Florian Beaufumé
@fbeaufume
With Lettuce traces I see that all 3 "HGETALL" commands seem similar (same request, same response), surprising...
Semyon Danilov
@SammyVimes
Hello everyone! I've just submitted spring-projects/spring-session#1730 where I added Apache Ignite (it's a distributed In-Memory Computation Platform) integration module. I will be glad to hear your thoughts on this and also I'd like someone to review it :)