Skip to content

Provide IMMEDIATE session updates on a method level of RedisOperationsSessionRepository #849

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
beku8 opened this issue Aug 11, 2017 · 4 comments
Assignees
Labels
for: stack-overflow A question that's better suited to stackoverflow.com

Comments

@beku8
Copy link

beku8 commented Aug 11, 2017

We wanted to update the session, as new role granted for the user. We can achieve this with the combination of findByIndexNameAndIndexValue methond and by setting RedisOperationsSessionRepository on IMMEDIATE flush mode. Since we can't call save, due to the package access of RedisSession. But I think its not necessary to convert to IMMEDIATE just for this purpose.

Would it be possible to provide a method like setAttributeImmidiate(sessionId, name, value) on RedisOperationsSessionRepository?

@vpavic vpavic self-assigned this Aug 11, 2017
@vpavic vpavic added the for: stack-overflow A question that's better suited to stackoverflow.com label Aug 11, 2017
@vpavic
Copy link
Contributor

vpavic commented Aug 11, 2017

Hi @beku8 - can you explain why you cannot call SessionRepository#save?

@vpavic vpavic added the status: waiting-for-feedback We need additional information before we can continue label Aug 11, 2017
@beku8
Copy link
Author

beku8 commented Aug 11, 2017

Hello, I tried to configure with

 @Autowired
  public UserSessionRefreshHandler(RedisOperationsSessionRepository sessionRepository,
      SessionRepository<Session> repository) {
    this.sessionRepository = sessionRepository;
  }

but it throws exception on the start up

Parameter 0 of constructor in com.nomadays.evento.UserSessionRefreshHandler required a bean of type 'org.springframework.session.SessionRepository' that could not be found.

'sessionRepository' not loaded because Session Condition found spring.session.store-type property REDIS

we are on spring boot 1.5.3, thus spring session 1.3.1.

I've tried with also couple of compinations of FindByIndexNameSessionRepository, RedisOperationsSessionRepository, SessionRepository. I thought they were somehow mutually exclusive.

But as you mentioned, I noticed that I autowired SessionRepository, in other classes successfully.

Any idea why this might be happening?

@vpavic
Copy link
Contributor

vpavic commented Aug 11, 2017

There are basically two ways you can inject a FindByIndexNameSessionRepository instance - either to inject and use raw type, or parameterized (respecting the original contract of FindByIndexNameSessionRepository<S extends Session>).

Raw type approach:

class RawConsumer {

	@Autowired
	private FindByIndexNameSessionRepository sessionRepository;

	void consume() {
		Session session = (Session) this.sessionRepository
				.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal")
				.values().iterator().next();
		session.setAttribute("test", UUID.randomUUID().toString());
		this.sessionRepository.save(session);
	}

}

Parameterized type approach:

class ParameterizedConsumer<S extends Session> {

	@Autowired
	private FindByIndexNameSessionRepository<S> sessionRepository;

	void consume() {
		S session = this.sessionRepository
				.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal")
				.values().iterator().next();
		session.setAttribute("test", UUID.randomUUID().toString());
		this.sessionRepository.save(session);
	}

}

@beku8
Copy link
Author

beku8 commented Aug 11, 2017

It works, and I feel stupid. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stack-overflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

2 participants