Skip to content

Authx Token Management Not Working With Spring Data Redis #46

@asmith-r7

Description

@asmith-r7

I am trying to use the token based auth approach with Jedis version 6.0.0 and Spring data redis 3.5.7.

I have created a new Identify provider to handle AWS elasticache IAM based authentication. (I can contribute this if it works)

My project is using Spring data redis version 3.5.7 but is failing due to the token being null on initial startup. I believe the issue is being caused by the token manager never being started due to how spring hooks into the Jedis connection creation.

I hook into the authx manager using the spring customiser:

      jedisClientConfigurationBuilder
          .customize(customizer -> customizer.authXManager(new AuthXManager(getTokenAuthConfig())))
          .useSsl();

Based on the stack trace, it looks like spring is hooking into Jedis Pool directly in such a way that the Authx manager start method is never called and therefore the token is not given an initial value before initial retrieval:

[2025-12-02 16:06:25.823] ERROR [main] SpringApplication: Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'redisContainer'
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:408)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:394)
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:586)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:364)
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:310)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:1009)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:630)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149)
	at com.rapid7.live.loader.ContentLoaderApplication.main(ContentLoaderApplication.java:55)
Caused by: org.springframework.data.redis.listener.adapter.RedisListenerExecutionFailedException: org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection
	at org.springframework.data.redis.listener.RedisMessageListenerContainer.lazyListen(RedisMessageListenerContainer.java:383)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer.start(RedisMessageListenerContainer.java:361)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:405)
	... 13 common frames omitted
Caused by: org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:940)
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:902)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer$Subscriber.lambda$initialize$0(RedisMessageListenerContainer.java:1241)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer$Subscriber.doInLock(RedisMessageListenerContainer.java:1455)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer$Subscriber.initialize(RedisMessageListenerContainer.java:1235)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer.doSubscribe(RedisMessageListenerContainer.java:428)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer.lazyListen(RedisMessageListenerContainer.java:404)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer.lazyListen(RedisMessageListenerContainer.java:374)
	... 15 common frames omitted
Caused by: redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool
	at redis.clients.jedis.util.Pool.getResource(Pool.java:42)
	at redis.clients.jedis.JedisPool.getResource(JedisPool.java:378)
	at redis.clients.jedis.JedisPool.getResource(JedisPool.java:17)
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:930)
	... 22 common frames omitted
Caused by: java.lang.NullPointerException: Cannot invoke "redis.clients.authentication.core.Token.getUser()" because "token" is null
	at redis.clients.jedis.authentication.TokenCredentials.<init>(TokenCredentials.java:11)
	at redis.clients.jedis.authentication.AuthXManager.get(AuthXManager.java:125)
	at redis.clients.jedis.authentication.AuthXManager.get(AuthXManager.java:24)
	at redis.clients.jedis.Connection.initializeFromClientConfig(Connection.java:475)
	at redis.clients.jedis.Connection.<init>(Connection.java:77)
	at redis.clients.jedis.Jedis.<init>(Jedis.java:233)
	at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:170)
	at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:557)

Just wondering if there is something I am missing here or is spring data redis simply not supported here? It would that it might be simple enough to support if the token manager is started during this execution path.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions