Skip to content

Commit c2cfe92

Browse files
committed
Merge branch '6.3.x'
2 parents 98cdb20 + fa5fc6d commit c2cfe92

File tree

25 files changed

+94
-50
lines changed

25 files changed

+94
-50
lines changed

cas/src/main/java/org/springframework/security/cas/userdetails/GrantedAuthorityFromAssertionAttributesUserDetailsService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
21+
import java.util.Locale;
2122

2223
import org.apereo.cas.client.validation.Assertion;
2324

@@ -73,7 +74,8 @@ protected UserDetails loadUserDetails(final Assertion assertion) {
7374
}
7475

7576
private SimpleGrantedAuthority createSimpleGrantedAuthority(Object o) {
76-
return new SimpleGrantedAuthority(this.convertToUpperCase ? o.toString().toUpperCase() : o.toString());
77+
return new SimpleGrantedAuthority(
78+
this.convertToUpperCase ? o.toString().toUpperCase(Locale.ROOT) : o.toString());
7779
}
7880

7981
/**

config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
21+
import java.util.Locale;
2122

2223
import io.micrometer.observation.ObservationRegistry;
2324
import jakarta.servlet.ServletRequest;
@@ -313,7 +314,7 @@ void setCsrfIgnoreRequestMatchers(List<BeanDefinition> requestMatchers) {
313314

314315
// Needed to account for placeholders
315316
static String createPath(String path, boolean lowerCase) {
316-
return lowerCase ? path.toLowerCase() : path;
317+
return lowerCase ? path.toLowerCase(Locale.ENGLISH) : path;
317318
}
318319

319320
BeanMetadataElement getSecurityContextHolderStrategyForAuthenticationFilters() {

core/src/main/java/org/springframework/security/authentication/AuthenticationObservationConvention.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.security.authentication;
1818

19+
import java.util.Locale;
20+
1921
import io.micrometer.common.KeyValues;
2022
import io.micrometer.observation.Observation;
2123
import io.micrometer.observation.ObservationConvention;
@@ -53,7 +55,7 @@ public String getContextualName(AuthenticationObservationContext context) {
5355
if (authenticationType.endsWith("Authentication")) {
5456
authenticationType = authenticationType.substring(0, authenticationType.lastIndexOf("Authentication"));
5557
}
56-
return "authenticate " + authenticationType.toLowerCase();
58+
return "authenticate " + authenticationType.toLowerCase(Locale.ENGLISH);
5759
}
5860
return "authenticate";
5961
}

core/src/main/java/org/springframework/security/core/authority/mapping/SimpleAttributes2GrantedAuthoritiesMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,10 +79,10 @@ public List<GrantedAuthority> getGrantedAuthorities(Collection<String> attribute
7979
*/
8080
private GrantedAuthority getGrantedAuthority(String attribute) {
8181
if (isConvertAttributeToLowerCase()) {
82-
attribute = attribute.toLowerCase(Locale.getDefault());
82+
attribute = attribute.toLowerCase(Locale.ROOT);
8383
}
8484
else if (isConvertAttributeToUpperCase()) {
85-
attribute = attribute.toUpperCase(Locale.getDefault());
85+
attribute = attribute.toUpperCase(Locale.ROOT);
8686
}
8787
if (isAddPrefixIfAlreadyExisting() || !attribute.startsWith(getAttributePrefix())) {
8888
return new SimpleGrantedAuthority(getAttributePrefix() + attribute);

core/src/main/java/org/springframework/security/core/authority/mapping/SimpleAuthorityMapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.Collection;
2020
import java.util.HashSet;
21+
import java.util.Locale;
2122
import java.util.Set;
2223

2324
import org.springframework.beans.factory.InitializingBean;
@@ -71,10 +72,10 @@ public Set<GrantedAuthority> mapAuthorities(Collection<? extends GrantedAuthorit
7172

7273
private GrantedAuthority mapAuthority(String name) {
7374
if (this.convertToUpperCase) {
74-
name = name.toUpperCase();
75+
name = name.toUpperCase(Locale.ROOT);
7576
}
7677
else if (this.convertToLowerCase) {
77-
name = name.toLowerCase();
78+
name = name.toLowerCase(Locale.ROOT);
7879
}
7980
if (this.prefix.length() > 0 && !name.startsWith(this.prefix)) {
8081
name = this.prefix + name;

core/src/main/java/org/springframework/security/core/userdetails/MapReactiveUserDetailsService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.Arrays;
2020
import java.util.Collection;
21+
import java.util.Locale;
2122
import java.util.Map;
2223
import java.util.concurrent.ConcurrentHashMap;
2324

@@ -91,7 +92,7 @@ private UserDetails withNewPassword(UserDetails userDetails, String newPassword)
9192
}
9293

9394
private String getKey(String username) {
94-
return username.toLowerCase();
95+
return username.toLowerCase(Locale.ROOT);
9596
}
9697

9798
}

core/src/main/java/org/springframework/security/core/userdetails/memory/UserAttributeEditor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.beans.PropertyEditorSupport;
2020
import java.util.ArrayList;
2121
import java.util.List;
22+
import java.util.Locale;
2223

2324
import org.springframework.util.StringUtils;
2425

@@ -45,10 +46,10 @@ public void setAsText(String s) throws IllegalArgumentException {
4546
userAttrib.setPassword(currentToken);
4647
}
4748
else {
48-
if (currentToken.toLowerCase().equals("enabled")) {
49+
if (currentToken.toLowerCase(Locale.ENGLISH).equals("enabled")) {
4950
userAttrib.setEnabled(true);
5051
}
51-
else if (currentToken.toLowerCase().equals("disabled")) {
52+
else if (currentToken.toLowerCase(Locale.ENGLISH).equals("disabled")) {
5253
userAttrib.setEnabled(false);
5354
}
5455
else {

core/src/main/java/org/springframework/security/provisioning/InMemoryUserDetailsManager.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020
import java.util.Enumeration;
2121
import java.util.HashMap;
22+
import java.util.Locale;
2223
import java.util.Map;
2324
import java.util.Properties;
2425

@@ -97,35 +98,33 @@ private User createUserDetails(String name, UserAttribute attr) {
9798
@Override
9899
public void createUser(UserDetails user) {
99100
Assert.isTrue(!userExists(user.getUsername()), "user should not exist");
100-
101101
if (user instanceof MutableUserDetails mutable) {
102-
this.users.put(user.getUsername().toLowerCase(), mutable);
102+
this.users.put(user.getUsername().toLowerCase(Locale.ROOT), mutable);
103103
}
104104
else {
105-
this.users.put(user.getUsername().toLowerCase(), new MutableUser(user));
105+
this.users.put(user.getUsername().toLowerCase(Locale.ROOT), new MutableUser(user));
106106
}
107107
}
108108

109109
@Override
110110
public void deleteUser(String username) {
111-
this.users.remove(username.toLowerCase());
111+
this.users.remove(username.toLowerCase(Locale.ROOT));
112112
}
113113

114114
@Override
115115
public void updateUser(UserDetails user) {
116116
Assert.isTrue(userExists(user.getUsername()), "user should exist");
117-
118117
if (user instanceof MutableUserDetails mutable) {
119-
this.users.put(user.getUsername().toLowerCase(), mutable);
118+
this.users.put(user.getUsername().toLowerCase(Locale.ROOT), mutable);
120119
}
121120
else {
122-
this.users.put(user.getUsername().toLowerCase(), new MutableUser(user));
121+
this.users.put(user.getUsername().toLowerCase(Locale.ROOT), new MutableUser(user));
123122
}
124123
}
125124

126125
@Override
127126
public boolean userExists(String username) {
128-
return this.users.containsKey(username.toLowerCase());
127+
return this.users.containsKey(username.toLowerCase(Locale.ROOT));
129128
}
130129

131130
@Override
@@ -156,14 +155,14 @@ public void changePassword(String oldPassword, String newPassword) {
156155
@Override
157156
public UserDetails updatePassword(UserDetails user, String newPassword) {
158157
String username = user.getUsername();
159-
MutableUserDetails mutableUser = this.users.get(username.toLowerCase());
158+
MutableUserDetails mutableUser = this.users.get(username.toLowerCase(Locale.ROOT));
160159
mutableUser.setPassword(newPassword);
161160
return mutableUser;
162161
}
163162

164163
@Override
165164
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
166-
UserDetails user = this.users.get(username.toLowerCase());
165+
UserDetails user = this.users.get(username.toLowerCase(Locale.ROOT));
167166
if (user == null) {
168167
throw new UsernameNotFoundException(username);
169168
}

crypto/src/main/java/org/springframework/security/crypto/password/LdapShaPasswordEncoder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.security.MessageDigest;
2020
import java.util.Base64;
21+
import java.util.Locale;
2122

2223
import org.springframework.security.crypto.codec.Utf8;
2324
import org.springframework.security.crypto.keygen.BytesKeyGenerator;
@@ -50,11 +51,11 @@ public class LdapShaPasswordEncoder implements PasswordEncoder {
5051

5152
private static final String SSHA_PREFIX = "{SSHA}";
5253

53-
private static final String SSHA_PREFIX_LC = SSHA_PREFIX.toLowerCase();
54+
private static final String SSHA_PREFIX_LC = SSHA_PREFIX.toLowerCase(Locale.ENGLISH);
5455

5556
private static final String SHA_PREFIX = "{SHA}";
5657

57-
private static final String SHA_PREFIX_LC = SHA_PREFIX.toLowerCase();
58+
private static final String SHA_PREFIX_LC = SHA_PREFIX.toLowerCase(Locale.ENGLISH);
5859

5960
private BytesKeyGenerator saltGenerator;
6061

etc/checkstyle/checkstyle-suppressions.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@
4444

4545
<!-- CSS content -->
4646
<suppress files="CssUtils\.java" checks="SpringLeadingWhitespace"/>
47+
48+
<!-- Ignore String.toUpperCase() and String.toLowerCase() checks in tests -->
49+
<suppress files="[\\/]src[\\/]test[\\/]" checks="RegexpSinglelineJava" id="toLowerCaseWithoutLocale"/>
50+
<suppress files="[\\/]src[\\/]test[\\/]" checks="RegexpSinglelineJava" id="toUpperCaseWithoutLocale"/>
4751
</suppressions>

etc/checkstyle/checkstyle.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,21 @@
3030
<property name="message" value="Please use assertThatExceptionOfType." />
3131
<property name="ignoreComments" value="true" />
3232
</module>
33+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
34+
<property name="id" value="toLowerCaseWithoutLocale"/>
35+
<property name="format" value="\.toLowerCase\(\)"/>
36+
<property name="maximum" value="0"/>
37+
<property name="message"
38+
value="String.toLowerCase() should be String.toLowerCase(Locale.ROOT) or String.toLowerCase(Locale.ENGLISH)"/>
39+
<property name="ignoreComments" value="true"/>
40+
</module>
41+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
42+
<property name="id" value="toUpperCaseWithoutLocale"/>
43+
<property name="format" value="\.toUpperCase\(\)"/>
44+
<property name="maximum" value="0"/>
45+
<property name="message"
46+
value="String.toUpperCase() should be String.toUpperCase(Locale.ROOT) or String.toUpperCase(Locale.ENGLISH)"/>
47+
<property name="ignoreComments" value="true"/>
48+
</module>
3349
</module>
3450
</module>

ldap/src/main/java/org/springframework/security/ldap/authentication/LdapEncoder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.security.ldap.authentication;
1818

19+
import java.util.Locale;
20+
1921
/**
2022
* Helper class to encode and decode ldap names and values.
2123
*
@@ -53,7 +55,7 @@ private LdapEncoder() {
5355
}
5456

5557
static String toTwoCharHex(char c) {
56-
String raw = Integer.toHexString(c).toUpperCase();
58+
String raw = Integer.toHexString(c).toUpperCase(Locale.ENGLISH);
5759
return (raw.length() > 1) ? raw : "0" + raw;
5860
}
5961

ldap/src/main/java/org/springframework/security/ldap/authentication/ad/ActiveDirectoryLdapAuthenticationProvider.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collection;
2121
import java.util.HashMap;
2222
import java.util.Hashtable;
23+
import java.util.Locale;
2324
import java.util.Map;
2425
import java.util.regex.Matcher;
2526
import java.util.regex.Pattern;
@@ -142,9 +143,9 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
142143
*/
143144
public ActiveDirectoryLdapAuthenticationProvider(String domain, String url, String rootDn) {
144145
Assert.isTrue(StringUtils.hasText(url), "Url cannot be empty");
145-
this.domain = StringUtils.hasText(domain) ? domain.toLowerCase() : null;
146+
this.domain = StringUtils.hasText(domain) ? domain.toLowerCase(Locale.ROOT) : null;
146147
this.url = url;
147-
this.rootDn = StringUtils.hasText(rootDn) ? rootDn.toLowerCase() : null;
148+
this.rootDn = StringUtils.hasText(rootDn) ? rootDn.toLowerCase(Locale.ROOT) : null;
148149
}
149150

150151
/**
@@ -153,7 +154,7 @@ public ActiveDirectoryLdapAuthenticationProvider(String domain, String url, Stri
153154
*/
154155
public ActiveDirectoryLdapAuthenticationProvider(String domain, String url) {
155156
Assert.isTrue(StringUtils.hasText(url), "Url cannot be empty");
156-
this.domain = StringUtils.hasText(domain) ? domain.toLowerCase() : null;
157+
this.domain = StringUtils.hasText(domain) ? domain.toLowerCase(Locale.ROOT) : null;
157158
this.url = url;
158159
this.rootDn = (this.domain != null) ? rootDnFromDomain(this.domain) : null;
159160
}
@@ -335,7 +336,7 @@ private String rootDnFromDomain(String domain) {
335336
}
336337

337338
String createBindPrincipal(String username) {
338-
if (this.domain == null || username.toLowerCase().endsWith(this.domain)) {
339+
if (this.domain == null || username.toLowerCase(Locale.ROOT).endsWith(this.domain)) {
339340
return username;
340341
}
341342
return username + "@" + this.domain;

ldap/src/main/java/org/springframework/security/ldap/userdetails/DefaultLdapAuthoritiesPopulator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collection;
2121
import java.util.HashSet;
2222
import java.util.List;
23+
import java.util.Locale;
2324
import java.util.Map;
2425
import java.util.Set;
2526
import java.util.function.Function;
@@ -179,7 +180,7 @@ else if (groupSearchBase.isEmpty()) {
179180
return null;
180181
}
181182
if (this.convertToUpperCase) {
182-
role = role.toUpperCase();
183+
role = role.toUpperCase(Locale.ROOT);
183184
}
184185
return new SimpleGrantedAuthority(this.rolePrefix + role);
185186
};

ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.LinkedList;
2424
import java.util.List;
2525
import java.util.ListIterator;
26+
import java.util.Locale;
2627

2728
import javax.naming.Context;
2829
import javax.naming.NameNotFoundException;
@@ -125,7 +126,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
125126
NamingEnumeration<?> ne = roleAttr.getAll();
126127
Object group = ne.next();
127128
String role = group.toString();
128-
return new SimpleGrantedAuthority(this.rolePrefix + role.toUpperCase());
129+
return new SimpleGrantedAuthority(this.rolePrefix + role.toUpperCase(Locale.ROOT));
129130
};
130131

131132
private String[] attributesToRetrieve;
@@ -292,7 +293,7 @@ public boolean userExists(String username) {
292293
@Deprecated
293294
protected DistinguishedName buildGroupDn(String group) {
294295
DistinguishedName dn = new DistinguishedName(this.groupSearchBase);
295-
dn.add(this.groupRoleAttributeName, group.toLowerCase());
296+
dn.add(this.groupRoleAttributeName, group.toLowerCase(Locale.ROOT));
296297
return dn;
297298
}
298299

0 commit comments

Comments
 (0)