Skip to content

Commit 8373336

Browse files
Use pattern matching
Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent b529e98 commit 8373336

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/server/BearerTokenServerAuthenticationEntryPoint.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -73,8 +73,8 @@ private Map<String, String> createParameters(AuthenticationException authExcepti
7373
if (this.realmName != null) {
7474
parameters.put("realm", this.realmName);
7575
}
76-
if (authException instanceof OAuth2AuthenticationException) {
77-
OAuth2Error error = ((OAuth2AuthenticationException) authException).getError();
76+
if (authException instanceof OAuth2AuthenticationException oAuth2AuthenticationException) {
77+
OAuth2Error error = oAuth2AuthenticationException.getError();
7878
parameters.put("error", error.getErrorCode());
7979
if (StringUtils.hasText(error.getDescription())) {
8080
parameters.put("error_description", error.getDescription());
@@ -92,10 +92,10 @@ private Map<String, String> createParameters(AuthenticationException authExcepti
9292
}
9393

9494
private HttpStatus getStatus(AuthenticationException authException) {
95-
if (authException instanceof OAuth2AuthenticationException) {
96-
OAuth2Error error = ((OAuth2AuthenticationException) authException).getError();
97-
if (error instanceof BearerTokenError) {
98-
return ((BearerTokenError) error).getHttpStatus();
95+
if (authException instanceof OAuth2AuthenticationException oAuth2AuthenticationException) {
96+
OAuth2Error error = oAuth2AuthenticationException.getError();
97+
if (error instanceof BearerTokenError bearerTokenError) {
98+
return bearerTokenError.getHttpStatus();
9999
}
100100
}
101101
return HttpStatus.UNAUTHORIZED;

0 commit comments

Comments
 (0)