spring-projects / spring-security

Spring Security
http://spring.io/projects/spring-security
Apache License 2.0
8.72k stars 5.86k forks source link

Illegal group reference #15458

Open itl-coder opened 1 month ago

itl-coder commented 1 month ago

java.lang.IllegalArgumentException: Illegal group reference at java.base/java.util.regex.Matcher.appendExpandedReplacement(Matcher.java:1067) at java.base/java.util.regex.Matcher.appendReplacement(Matcher.java:997) at java.base/java.util.regex.Matcher.replaceFirst(Matcher.java:1407) at java.base/java.lang.String.replaceFirst(String.java:2900) at com.linkkou.mybatis.log.LogInterceptor.replaceFirst(LogInterceptor.java:152) at com.linkkou.mybatis.log.LogInterceptor.getCompleteSql(LogInterceptor.java:123) Occurs when storing encrypted data Error:
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); // password include: return passwordEncoder.encode(password); image Will consider $ xxx $ to be regular This method will be called automatically: at java.base/java.util.regex.Matcher.appendExpandedReplacement(Matcher.java:1067)

jzheaux commented 1 month ago

Hi, @itl-coder, thanks for reaching out. I'm going to need a bit more information in order to address your issue. Can you provide a sample unit test that causes BCryptPasswordEncoder to fail how you describe?

itl-coder commented 1 month ago

You only need to customize a save(User user) in the SpringSecurity environment and encrypt the password field to trigger;

@Data class User{ private String username; private String password; }

public static String encodePassword(String password) {
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    return passwordEncoder.encode(password);
}

User user = new User(); user.setUsername("zs"); // encrypt password user.setPassword(encodePassword("12345678$")); //
userMapper.save(user);

itl-coder commented 1 month ago

recording