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

Password is not used from spring.data.redis.url property without username #35850

Closed
vuzem opened this issue Jun 12, 2023 · 4 comments
Closed
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@vuzem
Copy link

vuzem commented Jun 12, 2023

Hi team,

it appears that a provided password in the spring.data.redis.url property is not taken into account since Spring Boot 3 (version used 3.1.0), which lets a Redis connection fail.

For example, the password is provided in this spring.data.redis.url property:

spring.data.redis.url=redis://password@redis-host:6379

And when retrieving the password from, for example, a RedisStandaloneConfiguration, the password is empty:

import org.apache.commons.lang3.reflect.FieldUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
public class RedisConfig {

    @Bean
    RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory)
                                                      throws IllegalAccessException {

    	RedisStandaloneConfiguration configuration = 
    			(RedisStandaloneConfiguration) FieldUtils.readField(redisConnectionFactory,
    			   "configuration", true);
    			   
    	System.out.println("password present: " + configuration.getPassword().isPresent());
    	
    	RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
    	redisTemplate.setConnectionFactory(redisConnectionFactory);

        return redisTemplate;
    }

}

As mentioned above, the password is provided when running this configuration with Spring Boot 2 (2.7.12).

Thanks and cheers
Alex

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 12, 2023
@mhalbritter
Copy link
Contributor

Thanks for the report, I've edited your description to replace "guys" with "team". While it may seem like a small thing, some people feel excluded by "guys" and we don't want them to.

@snicoll
Copy link
Member

snicoll commented Jun 12, 2023

@vuzem I am confused that you're saying it works with Spring Boot 2.7. In Spring Boot 2.7, the property was spring.redis.url and was changed to spring.data.redis.url. Can you please double check and attach a small sample rather than a code snippet.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2023
@snicoll snicoll added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 12, 2023
@snicoll snicoll reopened this Jun 12, 2023
@vuzem
Copy link
Author

vuzem commented Jun 12, 2023

Hi @snicoll,

thanks for your answer. Sorry for not being precise enough, for Spring Boot 2, the property needs to be spring.redis.url of course. I have attached two sample projects including the RedisConfig from above.

Sample project with Spring Boot 2.7.12 and property spring.redis.url:
RedisPropertiesSpringBoot2.zip

Sample project with Spring Boot 3.1.0 and property spring.data.redis.url:
RedisPropertiesSpringBoot3.zip

Cheers
Alex

@scottfrederick scottfrederick added type: regression A regression from a previous release and removed status: invalid An issue that we don't feel is valid labels Jun 12, 2023
@scottfrederick scottfrederick added this to the 3.1.x milestone Jun 12, 2023
@scottfrederick
Copy link
Contributor

Thanks very much for the sample. The Redis URL in the sample is redis://password@redis-host:6379, which has a userinfo with a password but no username. The changes in 3.1 currently require the userinfo to contain a :, so a URL like redis://:password@redis-host:6379 (with a : before the password) is likely to work.

The previous code assumed that a userinfo without a : contained just a password, which matches the documentation for the Lettuce driver. We should restore this behavior.

@scottfrederick scottfrederick self-assigned this Jun 12, 2023
@scottfrederick scottfrederick changed the title Password not taken into account from spring.data.redis.url property since Spring Boot 3 Password is not used from spring.data.redis.url property without username Jun 13, 2023
@scottfrederick scottfrederick modified the milestones: 3.1.x, 3.1.1 Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

5 participants