-
Couldn't load subscription status.
- Fork 6.2k
Cleanup #17801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup #17801
Conversation
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
...org/springframework/security/cas/web/authentication/DefaultServiceAuthenticationDetails.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot be null and cannot be an empty String -> Cannot be null or empty String
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there are several uses of str == null || str.isEmpty() I think a common util function will be helpful
boolean isEmpty(String str) {
return str == null || str.length == 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use !org.springframework.util.StringUtils#hasLength
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
ec9b7b9 to
f77e0b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the great cleanup, @ngocnhan-tran1996. I've left some feedback inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please stay with this == obj as this is a bit more obvious what kind of shortcut we are doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change. In Spring Security, it's preferred to exit early for simple cases. Would you please flip the logic here to:
if (!(obj instanceof DefaultServiceAuthenticationDetails that)) { return false; } // ... continue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please keep checking for null here since that allows us to exit early without needing to instantiate a variable.
...org/springframework/security/cas/web/authentication/DefaultServiceAuthenticationDetails.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please give an example here since "role prefix" could be a bit esoteric. For example:
the default prefix to add to roles, for example {@code ROLE_}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't quite say that this is an implementation as much as it is an abstract class that allows subclasses to except the password to be non-{@code null}.
Perhaps change this to:
/** * An abstract {@link PasswordEncoder} that implementers can use for expecting the * password to be non-{@code null}. Each common password API method is accompanied * with an abstract method with a {@code NonNull} prefix. By implementing this, the concrete * class is specifying what to do with the password when it is non-{@code null}, allowing this * class to handle the {@code null} case. * * @author Rob Winch * @since 7.0 */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please favor the simpler exits coming first:
if (!StringUtils.hasLength(encodedPassword)) { return false; } return upgradeEncodingNonNull(encodedPassword);
This also has the added benefit of making the overall change smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would !StringUtils.hasLength(pathInfo)) work here as well?
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
This PR includes
StringUtils#hasLength