8000 Use SessionExpirationUtils for validate user and client sessions. Check client session is valid in TokenManager. by rmartinc · Pull Request #29013 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
8000

Use SessionExpirationUtils for validate user and client sessions. Check client session is valid in TokenManager. - #29013

Merged
ahus1 merged 1 commit into
keycloak:mainfrom
rmartinc:issue-24936
May 22, 2024
Merged

ahus1 merged 1 commit into
keycloak:mainfrom
rmartinc:issue-24936

Conversation

@rmartinc
Copy link
Copy Markdown
Contributor

Closes #24936

This PR checks the client session in the token manager to not manage a expired client session that generates negative values. Besides I have also unified the AuthenticationManager.isSessionValid to also use SessionExpirationUtils calculations. I'm sending a draft because of the last change. This is modifying some tests because previously the isSessionValid used just the remember-me values when the session was remember-me. Now it uses teh max value between the remember-me value and the normal sso value (as SessionExpirationUtils does). I think we should add a little upgrade note if we decide to continue this way. There are other two options: continue doing the calculation like before; change calculation in SessionExpirationUtils to use one or the other value. I prefer this way.

@mposolda @douglaspalmer Can you please test and review if you see something wrong?

This was referenced Apr 23, 2024
@douglaspalmer douglaspalmer left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

8000

@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmartinc @douglaspalmer Thanks for the fix and review!

I've added some nitpick comments, which can be easily fixed (if you think they make sense) as the rebase in fixing conflict is needed anyway.

+1 for adding some migration documentation

@rmartinc
rmartinc commented May 16, 2024 •
Copy link
Copy Markdown
Contributor Author

@mposolda Moving from draft as we all agreed to change the calculation like in the other parts. Requested changes added and rebased because there was a conflict. Liitle note in the upgrade guide also added.

@rmartinc
rmartinc marked this pull request as ready for review May 16, 2024 08:32
@rmartinc
rmartinc requested review from a team as code owners May 16, 2024 08:32
Check client session is valid in TokenManager
Closes keycloak#24936

Signed-off-by: rmartinc <rmartinc@redhat.com>
@rmartinc
Copy link
Copy Markdown
Contributor Author

The new Persistent Session IT tests were failing. The reason seems to be that if the client session is removed and added in the same transaction the old session remains. I have changed to (instead of remove/add) do a restart similar to what we do in the user session. I'm adding @ahus1 to review because maybe I'm doing something wrong. 😄
All tests pass now in my branch.

@rmartinc
rmartinc requested a review from ahus1 May 16, 2024 15:06
@ahus1
ahus1 commented May 16, 2024
Copy link
Copy Markdown
Member

@rmartinc - can you please point me to where you did this change?

@rmartinc
Copy link
Copy Markdown
Contributor Author
< 8000 /div>

@rmartinc - can you please point me to where you did this change?

Yes, here. In the previous version of the PR there was a remove/create of the client session. Now I created a restartClientSession that just cleans/adds the default client session values again. For that I added that method in AuthenticatedClientSessionModel and AuthenticatedClientSessionAdapter

@mposolda mposolda self-assigned this May 22, 2024
@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmartinc Thanks for the updates!

@ahus1 Could you please review or delegate to someone from the cross-dc team for the review?

@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, looks good to me.

@ahus1
ahus1 merged commit f7044ba into keycloak:main May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative token expiration when changing client session max lifetime

4 participants

0