Skip to content

Commit dbf9528

Browse files
Resolve feedback
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
1 parent 8f09d93 commit dbf9528

5 files changed

Lines changed: 32 additions & 36 deletions

File tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public String getServiceUrl() {
7272

7373
@Override
7474
public boolean equals(Object obj) {
75-
if (super.equals(obj)) {
75+
if (this == obj) {
7676
return true;
7777
}
78-
if (obj instanceof DefaultServiceAuthenticationDetails that) {
79-
return this.serviceUrl.equals(that.getServiceUrl());
78+
if (!(obj instanceof DefaultServiceAuthenticationDetails that)) {
79+
return false;
8080
}
81-
return false;
81+
return this.serviceUrl.equals(that.getServiceUrl());
8282
}
8383

8484
@Override
@@ -111,7 +111,10 @@ public String toString() {
111111
*/
112112
private @Nullable String getQueryString(final HttpServletRequest request, final Pattern artifactPattern) {
113113
final String query = request.getQueryString();
114-
String result = (query != null) ? artifactPattern.matcher(query).replaceFirst("") : "";
114+
if (query == null) {
115+
return null;
116+
}
117+
String result = artifactPattern.matcher(query).replaceFirst("");
115118
if (result.isEmpty()) {
116119
return null;
117120
}

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
@@ -208,7 +208,8 @@ private boolean isGranted(AuthorizationManager<T> authorizationManager) {
208208
/**
209209
* Convenience method to access {@link Authentication#getPrincipal()} from
210210
* {@link #getAuthentication()}
211-
* @return
211+
* @return the {@code Principal} being authenticated or the authenticated principal
212+
* after authentication.
212213
*/
213214
public @Nullable Object getPrincipal() {
214215
return getAuthentication().getPrincipal();

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
import org.springframework.util.StringUtils;
2222

2323
/**
24-
* Implementation of PasswordEncoder.
24+
* An abstract {@link PasswordEncoder} that implementers can use for expecting the
25+
* password to be non-{@code null}. Each common password API method is accompanied with an
26+
* abstract method with a {@code NonNull} prefix. By implementing this, the concrete class
27+
* is specifying what to do with the password when it is non-{@code null}, allowing this
28+
* class to handle the {@code null} case.
2529
*
2630
* @author Rob Winch
2731
* @since 7.0
@@ -50,10 +54,10 @@ public final boolean matches(@Nullable CharSequence rawPassword, @Nullable Strin
5054

5155
@Override
5256
public final boolean upgradeEncoding(@Nullable String encodedPassword) {
53-
if (StringUtils.hasLength(encodedPassword)) {
54-
return upgradeEncodingNonNull(encodedPassword);
57+
if (!StringUtils.hasLength(encodedPassword)) {
58+
return false;
5559
}
56-
return false;
60+
return upgradeEncodingNonNull(encodedPassword);
5761
}
5862

5963
protected boolean upgradeEncodingNonNull(String encodedPassword) {

web/src/main/java/org/springframework/security/web/firewall/RequestWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import jakarta.servlet.ServletResponse;
2626
import jakarta.servlet.http.HttpServletRequest;
2727
import org.jspecify.annotations.Nullable;
28+
import org.springframework.util.StringUtils;
2829

2930
/**
3031
* Request wrapper which ensures values of {@code servletPath} and {@code pathInfo} are
@@ -58,7 +59,7 @@ final class RequestWrapper extends FirewalledRequest {
5859
super(request);
5960
this.strippedServletPath = strip(request.getServletPath());
6061
String pathInfo = strip(request.getPathInfo());
61-
if (pathInfo != null && pathInfo.isEmpty()) {
62+
if (!StringUtils.hasLength(pathInfo)) {
6263
pathInfo = null;
6364
}
6465
this.strippedPathInfo = pathInfo;

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

Lines changed: 12 additions & 25 deletions
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
/**
@@ -100,7 +101,7 @@ public class DefaultSavedRequest implements SavedRequest {
100101
private final @Nullable String matchingRequestParameterName;
101102

102103
public DefaultSavedRequest(HttpServletRequest request) {
103-
this(request, (String) null);
104+
this(request, null);
104105
}
105106

106107
public DefaultSavedRequest(HttpServletRequest request, @Nullable String matchingRequestParameterName) {
@@ -193,21 +194,17 @@ private void addLocale(Locale locale) {
193194
* @since 4.2
194195
*/
195196
private void addParameters(Map<String, String[]> parameters) {
196-
if (!ObjectUtils.isEmpty(parameters)) {
197-
for (String paramName : parameters.keySet()) {
198-
Object paramValues = parameters.get(paramName);
199-
if (paramValues instanceof String[]) {
200-
this.addParameter(paramName, (String[]) paramValues);
201-
}
202-
else {
203-
logger.warn("ServletRequest.getParameterMap() returned non-String array");
204-
}
205-
}
197+
if (ObjectUtils.isEmpty(parameters)) {
198+
return;
206199
}
207-
}
208200

209-
private void addParameter(String name, String[] values) {
210-
this.parameters.put(name, values);
201+
for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
202+
String name = entry.getKey();
203+
String[] values = entry.getValue();
204+
if (values != null) {
205+
this.parameters.put(name, values);
206+
}
207+
}
211208
}
212209

213210
public @Nullable String getContextPath() {
@@ -301,16 +298,6 @@ public int getServerPort() {
301298
return this.servletPath;
302299
}
303300

304-
private boolean propertyEquals(@Nullable Object arg1, Object arg2) {
305-
if ((arg1 == null) && (arg2 == null)) {
306-
return true;
307-
}
308-
if (arg1 == null || arg2 == null) {
309-
return false;
310-
}
311-
return arg1.equals(arg2);
312-
}
313-
314301
@Override
315302
public String toString() {
316303
return "DefaultSavedRequest [" + getRedirectUrl() + "]";
@@ -321,7 +308,7 @@ public String toString() {
321308
if (matchingRequestParameterName == null) {
322309
return queryString;
323310
}
324-
if (queryString == null || queryString.length() == 0) {
311+
if (!StringUtils.hasLength(queryString)) {
325312
return matchingRequestParameterName;
326313
}
327314
return UriComponentsBuilder.newInstance()

0 commit comments

Comments
 (0)