Skip to content

Is it possible change the access level of RedisSession in class RedisIndexedSessionRepository to public #2586

Closed
@herodotus-ecosystem

Description

@herodotus-ecosystem

I want to use Spring Session in the Spring Security and Spring Authorization Server environments. Currently, I achieve this by configuring the following beans

@Bean
@ConditionalOnMissingBean
public <S extends Session> SessionRegistry sessionRegistry(FindByIndexNameSessionRepository<S> sessionRepository) {
	SpringSessionBackedSessionRegistry<S> springSessionBackedSessionRegistry = new SpringSessionBackedSessionRegistry<>(sessionRepository);
	log.trace("[Herodotus] |- Bean [Spring Session Backed Session Registry] Auto Configure.");
	return springSessionBackedSessionRegistry;
}

This code can make Spring Security run normally without any issues.

My problem is that the above code has some flaws, which are in the idea, as shown in the following figure, Prompt error "No beans of 'FindByIndexNameSessionRepository' type found"

image

  • From the perspective of class inheritance, there is no problem with this approach now, and the code can also run normally.
  • However, from the configuration perspective of Spring beans, there is indeed a small issue, as only RedisIndexedSessionRepository (in org.springframework.session.data.redis.config.annotation.web.http.RedisIndexedHttpSessionConfiguration) beans were injected into the Spring session without FindByIndexNameSessionRepository beans, so the IDE prompts that FindByIndexNameSessionRepository beans cannot be found, which is also correct.

if change the access level of RedisSession in class RedisIndexedSessionRepository to public, can turn the code into the following way

@Bean
@ConditionalOnMissingBean
public SessionRegistry sessionRegistry(RedisIndexedSessionRepository sessionRepository) {
	SpringSessionBackedSessionRegistry<RedisIndexedSessionRepository.RedisSession> springSessionBackedSessionRegistry = new SpringSessionBackedSessionRegistry<>(sessionRepository);
	log.trace("[Herodotus] |- Bean [Spring Session Backed Session Registry] Auto Configure.");
	return springSessionBackedSessionRegistry;
}

This seems more reasonable, and there will be no error prompts in the IDE.

However, RedisSession is currently inaccessible in RedisIndexedSessionRepository, so it cannot be configured using the above code.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions