Skip to content

Commit ab93541

Browse files
ngocnhan-tran1996jzheaux
authored andcommitted
Simplify condition in some methods
1 parent e76de93 commit ab93541

File tree

7 files changed

+15
-39
lines changed

7 files changed

+15
-39
lines changed

cas/src/main/java/org/springframework/security/cas/authentication/CasAuthenticationToken.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,8 @@ public boolean equals(final Object obj) {
115115
if (!super.equals(obj)) {
116116
return false;
117117
}
118-
if (obj instanceof CasAuthenticationToken) {
119-
CasAuthenticationToken test = (CasAuthenticationToken) obj;
120-
if (!this.assertion.equals(test.getAssertion())) {
121-
return false;
122-
}
123-
if (this.getKeyHash() != test.getKeyHash()) {
124-
return false;
125-
}
126-
return true;
118+
if (obj instanceof CasAuthenticationToken test) {
119+
return this.assertion.equals(test.getAssertion()) && this.getKeyHash() == test.getKeyHash();
127120
}
128121
return false;
129122
}

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/converter/ObjectToListStringConverter.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 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.
@@ -43,12 +43,9 @@ public Set<ConvertiblePair> getConvertibleTypes() {
4343

4444
@Override
4545
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
46-
if (targetType.getElementTypeDescriptor() == null
47-
|| targetType.getElementTypeDescriptor().getType().equals(String.class) || sourceType == null
48-
|| ClassUtils.isAssignable(sourceType.getType(), targetType.getElementTypeDescriptor().getType())) {
49-
return true;
50-
}
51-
return false;
46+
TypeDescriptor typeDescriptor = targetType.getElementTypeDescriptor();
47+
return typeDescriptor == null || typeDescriptor.getType().equals(String.class) || sourceType == null
48+
|| ClassUtils.isAssignable(sourceType.getType(), typeDescriptor.getType());
5249
}
5350

5451
@Override

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/converter/ObjectToMapStringObjectConverter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ public Set<ConvertiblePair> getConvertibleTypes() {
3737

3838
@Override
3939
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
40-
if (targetType.getElementTypeDescriptor() == null
41-
|| targetType.getMapKeyTypeDescriptor().getType().equals(String.class)) {
42-
return true;
43-
}
44-
return false;
40+
return targetType.getElementTypeDescriptor() == null
41+
|| targetType.getMapKeyTypeDescriptor().getType().equals(String.class);
4542
}
4643

4744
@Override

web/src/main/java/org/springframework/security/web/access/intercept/AuthorizationFilter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ private boolean skipDispatch(HttpServletRequest request) {
109109
if (DispatcherType.ERROR.equals(request.getDispatcherType()) && !this.filterErrorDispatch) {
110110
return true;
111111
}
112-
if (DispatcherType.ASYNC.equals(request.getDispatcherType()) && !this.filterAsyncDispatch) {
113-
return true;
114-
}
115-
return false;
112+
113+
return DispatcherType.ASYNC.equals(request.getDispatcherType()) && !this.filterAsyncDispatch;
116114
}
117115

118116
private boolean isApplied(HttpServletRequest request) {

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

Lines changed: 2 additions & 5 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.
@@ -87,10 +87,7 @@ private boolean containsInvalidUrlEncodedSlash(String uri) {
8787
if (this.allowUrlEncodedSlash || uri == null) {
8888
return false;
8989
}
90-
if (uri.contains("%2f") || uri.contains("%2F")) {
91-
return true;
92-
}
93-
return false;
90+
return uri.contains("%2f") || uri.contains("%2F");
9491
}
9592

9693
/**

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,7 @@ private static boolean decodedUrlContains(HttpServletRequest request, String val
611611
if (valueContains(request.getServletPath(), value)) {
612612
return true;
613613
}
614-
if (valueContains(request.getPathInfo(), value)) {
615-
return true;
616-
}
617-
return false;
614+
return valueContains(request.getPathInfo(), value);
618615
}
619616

620617
private static boolean containsOnlyPrintableAsciiCharacters(String uri) {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 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.
@@ -354,10 +354,7 @@ private boolean propertyEquals(Object arg1, Object arg2) {
354354
if (arg1 == null || arg2 == null) {
355355
return false;
356356
}
357-
if (arg1.equals(arg2)) {
358-
return true;
359-
}
360-
return false;
357+
return arg1.equals(arg2);
361358
}
362359

363360
@Override

0 commit comments

Comments
 (0)