Skip to content

How can I extend the save method in the RedisSessionRepository? #2179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ohHyunJae opened this issue Oct 10, 2022 · 4 comments
Closed

How can I extend the save method in the RedisSessionRepository? #2179

ohHyunJae opened this issue Oct 10, 2022 · 4 comments
Labels
type: bug A general bug

Comments

@ohHyunJae
Copy link

ohHyunJae commented Oct 10, 2022

When I save a session with redis,

I'd like to add custom data.

RedisSessionRepository.class
    
    ....
    
    @Override
        public void save(CustomRedisSessionRepository.RedisSession session) {
            if (!session.isNew) {
                String key = getSessionKey(session.hasChangedSessionId() ? session.originalSessionId : session.getId());
                Boolean sessionExists = this.sessionRedisOperations.hasKey(key);
                if (sessionExists == null || !sessionExists) {
                    throw new IllegalStateException("Session was invalidated");
                }
            }
            session.save();

            //I want add code..... (custom data..)
        }

So I decided to expand.

public class MyRedisSessionRepository extends RedisSessionRepository {
    
    public MyRedisSessionRepository(RedisOperations<String, Object> sessionRedisOperations) {
        super(sessionRedisOperations);
    }
    
    @Override
    public void save(RedisSessionRepository.RedisSession session) {
        super.save(session);
        //add custom data...
    }
}

But I can't. The access modifier for RedisSession is 'default'.

public class RedisSessionRepository implements SessionRepository<RedisSessionRepository.RedisSession> {

...
 final class RedisSession implements Session {
  ....
 }
..
}

So I can't extend the save method of RedisSessionRepository.

Is there any other way Or is there an expandable class?

@ohHyunJae ohHyunJae added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Oct 10, 2022
@sraeuchle
Copy link

Same here. I need to adjust Format of the Session in Redis (Json instead of Hash) the session is stored. This can be achived for UserDetails etc. but not the Core Session Data itself.

@marcusdacoregio
Copy link
Contributor

Hi @ohHyunJae,

can you give us an example of the data that you are trying to add to the session? Did you try to set them in the HttpSession attributes?

@marcusdacoregio marcusdacoregio added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 28, 2023
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Mar 7, 2023
@spring-projects-issues
Copy link

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2023
@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants