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>

0 commit comments

Comments
 (0)