mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-16 23:33:31 +00:00
Polish
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
This commit is contained in:
parent
37b8d019fa
commit
7bca17cb5a
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -65,8 +65,8 @@ public final class BearerTokenAuthenticationEntryPoint implements Authentication
|
|||||||
if (this.realmName != null) {
|
if (this.realmName != null) {
|
||||||
parameters.put("realm", this.realmName);
|
parameters.put("realm", this.realmName);
|
||||||
}
|
}
|
||||||
if (authException instanceof OAuth2AuthenticationException) {
|
if (authException instanceof OAuth2AuthenticationException oAuth2AuthenticationException) {
|
||||||
OAuth2Error error = ((OAuth2AuthenticationException) authException).getError();
|
OAuth2Error error = oAuth2AuthenticationException.getError();
|
||||||
parameters.put("error", error.getErrorCode());
|
parameters.put("error", error.getErrorCode());
|
||||||
if (StringUtils.hasText(error.getDescription())) {
|
if (StringUtils.hasText(error.getDescription())) {
|
||||||
parameters.put("error_description", error.getDescription());
|
parameters.put("error_description", error.getDescription());
|
||||||
@ -78,7 +78,7 @@ public final class BearerTokenAuthenticationEntryPoint implements Authentication
|
|||||||
if (StringUtils.hasText(bearerTokenError.getScope())) {
|
if (StringUtils.hasText(bearerTokenError.getScope())) {
|
||||||
parameters.put("scope", bearerTokenError.getScope());
|
parameters.put("scope", bearerTokenError.getScope());
|
||||||
}
|
}
|
||||||
status = ((BearerTokenError) error).getHttpStatus();
|
status = bearerTokenError.getHttpStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String wwwAuthenticate = computeWWWAuthenticateHeaderValue(parameters);
|
String wwwAuthenticate = computeWWWAuthenticateHeaderValue(parameters);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -64,7 +64,7 @@ public final class DefaultBearerTokenResolver implements BearerTokenResolver {
|
|||||||
return authorizationHeaderToken;
|
return authorizationHeaderToken;
|
||||||
}
|
}
|
||||||
if (parameterToken != null && isParameterTokenEnabledForRequest(request)) {
|
if (parameterToken != null && isParameterTokenEnabledForRequest(request)) {
|
||||||
if (!StringUtils.hasText(parameterToken)) {
|
if (parameterToken.isBlank()) {
|
||||||
BearerTokenError error = BearerTokenErrors
|
BearerTokenError error = BearerTokenErrors
|
||||||
.invalidRequest("The requested token parameter is an empty string");
|
.invalidRequest("The requested token parameter is an empty string");
|
||||||
throw new OAuth2AuthenticationException(error);
|
throw new OAuth2AuthenticationException(error);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -73,8 +73,8 @@ public final class BearerTokenServerAuthenticationEntryPoint implements ServerAu
|
|||||||
if (this.realmName != null) {
|
if (this.realmName != null) {
|
||||||
parameters.put("realm", this.realmName);
|
parameters.put("realm", this.realmName);
|
||||||
}
|
}
|
||||||
if (authException instanceof OAuth2AuthenticationException) {
|
if (authException instanceof OAuth2AuthenticationException oAuth2AuthenticationException) {
|
||||||
OAuth2Error error = ((OAuth2AuthenticationException) authException).getError();
|
OAuth2Error error = oAuth2AuthenticationException.getError();
|
||||||
parameters.put("error", error.getErrorCode());
|
parameters.put("error", error.getErrorCode());
|
||||||
if (StringUtils.hasText(error.getDescription())) {
|
if (StringUtils.hasText(error.getDescription())) {
|
||||||
parameters.put("error_description", error.getDescription());
|
parameters.put("error_description", error.getDescription());
|
||||||
@ -82,20 +82,19 @@ public final class BearerTokenServerAuthenticationEntryPoint implements ServerAu
|
|||||||
if (StringUtils.hasText(error.getUri())) {
|
if (StringUtils.hasText(error.getUri())) {
|
||||||
parameters.put("error_uri", error.getUri());
|
parameters.put("error_uri", error.getUri());
|
||||||
}
|
}
|
||||||
if (error instanceof BearerTokenError bearerTokenError) {
|
if (error instanceof BearerTokenError bearerTokenError
|
||||||
if (StringUtils.hasText(bearerTokenError.getScope())) {
|
&& StringUtils.hasText(bearerTokenError.getScope())) {
|
||||||
parameters.put("scope", bearerTokenError.getScope());
|
parameters.put("scope", bearerTokenError.getScope());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpStatus getStatus(AuthenticationException authException) {
|
private HttpStatus getStatus(AuthenticationException authException) {
|
||||||
if (authException instanceof OAuth2AuthenticationException) {
|
if (authException instanceof OAuth2AuthenticationException oAuth2AuthenticationException) {
|
||||||
OAuth2Error error = ((OAuth2AuthenticationException) authException).getError();
|
OAuth2Error error = oAuth2AuthenticationException.getError();
|
||||||
if (error instanceof BearerTokenError) {
|
if (error instanceof BearerTokenError bearerTokenError) {
|
||||||
return ((BearerTokenError) error).getHttpStatus();
|
return bearerTokenError.getHttpStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return HttpStatus.UNAUTHORIZED;
|
return HttpStatus.UNAUTHORIZED;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user