Skip to content

Commit e08de06

Browse files
Update javadoc and apply StringUtils#hasLength
Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent 7c436a2 commit e08de06

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

cas/src/main/java/org/springframework/security/cas/web/authentication/DefaultServiceAuthenticationDetails.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ public String toString() {
110110
*/
111111
private String getQueryString(final HttpServletRequest request, final Pattern artifactPattern) {
112112
final String query = request.getQueryString();
113-
if (query == null) {
114-
return null;
115-
}
116-
String result = artifactPattern.matcher(query).replaceFirst("");
113+
String result = query == null ? "" : artifactPattern.matcher(query).replaceFirst("");
117114
if (result.isEmpty()) {
118115
return null;
119116
}
@@ -126,8 +123,7 @@ private String getQueryString(final HttpServletRequest request, final Pattern ar
126123
* {@link Pattern} to be reused for every instance of
127124
* {@link DefaultServiceAuthenticationDetails}.
128125
* @param artifactParameterName the artifactParameterName that is removed from the
129-
* current URL. The result becomes the service url. Cannot be null and cannot be an
130-
* empty String.
126+
* current URL. The result becomes the service url. Cannot be null or an empty String.
131127
* @return a {@link Pattern}
132128
*/
133129
static Pattern createArtifactPattern(String artifactParameterName) {

core/src/main/java/org/springframework/security/access/annotation/Jsr250MethodSecurityMetadataSource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.core.annotation.AnnotationUtils;
3232
import org.springframework.security.access.ConfigAttribute;
3333
import org.springframework.security.access.method.AbstractFallbackMethodSecurityMetadataSource;
34+
import org.springframework.util.StringUtils;
3435

3536
/**
3637
* Sources method security metadata from major JSR 250 security annotations.
@@ -108,7 +109,7 @@ private String getRoleWithDefaultPrefix(String role) {
108109
if (role == null) {
109110
return role;
110111
}
111-
if (this.defaultRolePrefix == null || this.defaultRolePrefix.isEmpty()) {
112+
if (!StringUtils.hasLength(this.defaultRolePrefix)) {
112113
return role;
113114
}
114115
if (role.startsWith(this.defaultRolePrefix)) {

core/src/main/java/org/springframework/security/access/expression/SecurityExpressionRoot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.security.core.GrantedAuthority;
3232
import org.springframework.security.core.authority.AuthorityUtils;
3333
import org.springframework.util.Assert;
34+
import org.springframework.util.StringUtils;
3435
import org.springframework.util.function.SingletonSupplier;
3536

3637
/**
@@ -238,7 +239,7 @@ private static String getRoleWithDefaultPrefix(@Nullable String defaultRolePrefi
238239
if (role == null) {
239240
return role;
240241
}
241-
if (defaultRolePrefix == null || defaultRolePrefix.isEmpty()) {
242+
if (!StringUtils.hasLength(defaultRolePrefix)) {
242243
return role;
243244
}
244245
if (role.startsWith(defaultRolePrefix)) {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.jspecify.annotations.Nullable;
2020

21+
import org.springframework.util.StringUtils;
22+
2123
/**
2224
* Implementation of PasswordEncoder.
2325
*
@@ -38,20 +40,20 @@ public abstract class AbstractValidatingPasswordEncoder implements PasswordEncod
3840

3941
@Override
4042
public final boolean matches(@Nullable CharSequence rawPassword, @Nullable String encodedPassword) {
41-
if (rawPassword == null || rawPassword.isEmpty() || encodedPassword == null || encodedPassword.isEmpty()) {
42-
return false;
43+
if (StringUtils.hasLength(rawPassword) && StringUtils.hasLength(encodedPassword)) {
44+
return matchesNonNull(rawPassword.toString(), encodedPassword);
4345
}
44-
return matchesNonNull(rawPassword.toString(), encodedPassword);
46+
return false;
4547
}
4648

4749
protected abstract boolean matchesNonNull(String rawPassword, String encodedPassword);
4850

4951
@Override
5052
public final boolean upgradeEncoding(@Nullable String encodedPassword) {
51-
if (encodedPassword == null || encodedPassword.isEmpty()) {
52-
return false;
53+
if (StringUtils.hasLength(encodedPassword)) {
54+
return upgradeEncodingNonNull(encodedPassword);
5355
}
54-
return upgradeEncodingNonNull(encodedPassword);
56+
return false;
5557
}
5658

5759
protected boolean upgradeEncodingNonNull(String encodedPassword) {

web/src/main/java/org/springframework/security/web/savedrequest/DefaultSavedRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.security.web.util.UrlUtils;
3737
import org.springframework.util.Assert;
3838
import org.springframework.util.ObjectUtils;
39+
import org.springframework.util.StringUtils;
3940
import org.springframework.web.util.UriComponentsBuilder;
4041

4142
/**
@@ -375,7 +376,7 @@ private static String createQueryString(String queryString, String matchingReque
375376
if (matchingRequestParameterName == null) {
376377
return queryString;
377378
}
378-
if (queryString == null || queryString.isEmpty()) {
379+
if (!StringUtils.hasLength(queryString)) {
379380
return matchingRequestParameterName;
380381
}
381382
return UriComponentsBuilder.newInstance()

web/src/main/java/org/springframework/security/web/util/TextEscapeUtils.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.web.util;
1818

19+
import org.springframework.util.StringUtils;
20+
1921
/**
2022
* Internal utility for escaping characters in HTML strings.
2123
*
@@ -25,7 +27,7 @@
2527
public abstract class TextEscapeUtils {
2628

2729
public static String escapeEntities(String s) {
28-
if (s == null || s.isEmpty()) {
30+
if (!StringUtils.hasLength(s)) {
2931
return s;
3032
}
3133
StringBuilder sb = new StringBuilder();

0 commit comments

Comments
 (0)