♻️ Refactoring code.包装check_token端点校验失败后的InvalidTokenException为自定义的401 UnauthorizedException异常

This commit is contained in:
lishangbu 2021-07-07 09:05:33 +08:00
parent 9caa82e34e
commit f695626161
1 changed files with 7 additions and 4 deletions

View File

@ -26,10 +26,7 @@ import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.common.DefaultThrowableAnalyzer;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.exceptions.ClientAuthenticationException;
import org.springframework.security.oauth2.common.exceptions.InsufficientScopeException;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.common.exceptions.*;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
import org.springframework.security.web.util.ThrowableAnalyzer;
import org.springframework.web.HttpRequestMethodNotSupportedException;
@ -68,6 +65,12 @@ public class PigWebResponseExceptionTranslator implements WebResponseExceptionTr
return handleOAuth2Exception(new InvalidException(ase.getMessage(), ase));
}
ase = (InvalidTokenException) throwableAnalyzer.getFirstThrowableOfType(InvalidTokenException.class,
causeChain);
if (ase != null) {
return handleOAuth2Exception(new UnauthorizedException(ase.getMessage(), ase));
}
ase = (HttpRequestMethodNotSupportedException) throwableAnalyzer
.getFirstThrowableOfType(HttpRequestMethodNotSupportedException.class, causeChain);
if (ase != null) {