Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
ngocnhan-tran1996 wants to merge 11 commits into spring-projects:main
base: main
Choose a base branch
Loading
from ngocnhan-tran1996:cleanup
Open

Conversation

@ngocnhan-tran1996
Copy link
Contributor

@ngocnhan-tran1996 ngocnhan-tran1996 commented Aug 24, 2025
edited
Loading

This PR includes

  • Use StringUtils#hasLength
  • Remove redundant check and exception
  • Update javadoc
  • Polish some methods

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>
* @return
* @param artifactParameterName the artifactParameterName that is removed from the
* current URL. The result becomes the service url. Cannot be null and cannot be an
* empty String.
Copy link
Contributor

@ronodhirSoumik ronodhirSoumik Aug 26, 2025

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

return role;
}
if (defaultRolePrefix == null || defaultRolePrefix.length() == 0) {
if (defaultRolePrefix == null || defaultRolePrefix.isEmpty()) {
Copy link
Contributor

@ronodhirSoumik ronodhirSoumik Aug 26, 2025
edited
Loading

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;
}

Copy link
Contributor Author

@ngocnhan-tran1996 ngocnhan-tran1996 Aug 26, 2025

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>
Copy link
Contributor

@jzheaux jzheaux left a 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.

@Override
public boolean equals(Object obj) {
if (this == obj) {
if (super.equals(obj)) {
Copy link
Contributor

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.

}
if (!super.equals(obj) || !(objinstanceof DefaultServiceAuthenticationDetails)) {
return false;
if (objinstanceof DefaultServiceAuthenticationDetailsthat) {
Copy link
Contributor

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

*/
private String getQueryString(final HttpServletRequest request, final Pattern artifactPattern) {
final String query = request.getQueryString();
if (query == null) {
Copy link
Contributor

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.

* @param defaultRolePrefix
* @param role
* @return
* @param defaultRolePrefix the default prefix to add to roles.
Copy link
Contributor

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_}

import org.springframework.util.StringUtils;

/**
* Implementation of PasswordEncoder.
Copy link
Contributor

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
 */

public final boolean upgradeEncoding(@Nullable String encodedPassword) {
if (encodedPassword == null || encodedPassword.length() == 0) {
return false;
if (StringUtils.hasLength(encodedPassword)) {
Copy link
Contributor

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.

this.strippedServletPath = strip(request.getServletPath());
String pathInfo = strip(request.getPathInfo());
if (pathInfo != null && pathInfo.length() == 0) {
if (pathInfo != null && pathInfo.isEmpty()) {
Copy link
Contributor

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?

@jzheaux jzheaux self-assigned this Oct 20, 2025
@jzheaux jzheaux added in: core An issue in spring-security-core type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 20, 2025
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jzheaux jzheaux Awaiting requested review from jzheaux

1 more reviewer

@ronodhirSoumik ronodhirSoumik ronodhirSoumik left review comments

Reviewers whose approvals may not affect merge requirements

Labels

in: core An issue in spring-security-core type: enhancement A general enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /