Skip to content
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

Avoid to retain SessionIdGenerator in session object #2387

Closed
wants to merge 2 commits into from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Jul 20, 2023

session id generation shouldn't be the responsibility of session object, since SessionIdGenerator held by session object is only used by changeSessionId(), we could introduce overload method passing it as parameter to avoid that.

@quaff
Copy link
Contributor Author

quaff commented Jul 25, 2023

Could you review this PR? @rwinch @marcusdacoregio @vpavic

@marcusdacoregio marcusdacoregio self-assigned this Jul 25, 2023
@marcusdacoregio marcusdacoregio added type: enhancement A general enhancement in: core and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 25, 2023
@quaff quaff changed the title Avoid to retain SessionIdGenerationStrategy in session object Avoid to retain SessionIdGenerator in session object Aug 7, 2023
@quaff
Copy link
Contributor Author

quaff commented Aug 7, 2023

Rebased and split to multiple commits for better code review.

@marcusdacoregio
Copy link
Contributor

Hi, @quaff. I am not so sure about the pros and cons here. Imagine a scenario where I am migrating users from a legacy db to a new db and both have different strategies to generate session ids.

The problem would arise when a session need to changeSessionId(). Currently, the session implementation will use the strategy provided by the repository, in the scenario above, the legacy or new strategy. If we move the responsibility to the filter, how do we know which strategy to use when changing the session id? The interface contract does not provide any context about the session.

@quaff
Copy link
Contributor Author

quaff commented Aug 10, 2023

Hi, @quaff. I am not so sure about the pros and cons here. Imagine a scenario where I am migrating users from a legacy db to a new db and both have different strategies to generate session ids.

The problem would arise when a session need to changeSessionId(). Currently, the session implementation will use the strategy provided by the repository, in the scenario above, the legacy or new strategy. If we move the responsibility to the filter, how do we know which strategy to use when changing the session id? The interface contract does not provide any context about the session.

We could introduce a default method for SessionIdGenerator

public interface SessionIdGenerator {

	@NonNull
	String generate();

	@NonNull
	default String regenerate(Session session) {
		return generate();
	}

}
	@Override
	public String changeSessionId(SessionIdGenerator sessionIdGenerator) {
		String newSessionId = sessionIdGenerator.regenerate(this);
		setId(newSessionId);
		return newSessionId;
	}

Now we can choose strategy base on original session id.

EDIT: I've pushed a new commit to accomplish this.

organize code via centralizing the default SessionIdGenerator instance
session id generation shouldn't be the responsibility of session object, since SessionIdGenerator held by session object is only used by changeSessionId(), we could introduce overload method passing it as parameter to avoid that.
@quaff
Copy link
Contributor Author

quaff commented Oct 25, 2023

I really think it's not a good choice that domain object holds non-domain object reference, any thoughts?

@marcusdacoregio
Copy link
Contributor

Hi, @quaff. This is not something that we want to do now. I'd prefer to receive more feedback from the community and see where the SessionIdGenerator support has its flaws and then change accordingly.

It is also strange that a low-level SessionRepositoryFilter depends on SessionIdGenerator. That would make it impossible to have a strategy per session repository.

With that said, I'll close this issue and wait for community feedback to proceed with further changes related to it.

@marcusdacoregio marcusdacoregio added the status: declined A suggestion or change that we don't feel we should currently apply label Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants