From cbf8fb0da909f2328e124a612404cb9e718b09e5 Mon Sep 17 00:00:00 2001 From: wjie Date: Thu, 5 Aug 2021 17:54:27 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20cl?= =?UTF-8?q?osed=20#3013=20=E3=80=90=E9=87=8D=E6=9E=84=E3=80=91=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E5=89=8D=E7=AB=AFindex.vue=20=E7=9A=84=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E9=80=BB=E8=BE=91=E6=8A=BD=E5=8F=96=E6=88=90=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PigxWebResponseExceptionTranslator.java | 4 +- .../exception/TokenInvalidException.java | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/TokenInvalidException.java diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxWebResponseExceptionTranslator.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxWebResponseExceptionTranslator.java index 857d55cf1..a2a8755be 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxWebResponseExceptionTranslator.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxWebResponseExceptionTranslator.java @@ -76,11 +76,11 @@ public class PigxWebResponseExceptionTranslator implements WebResponseExceptionT return handleOAuth2Exception(new MethodNotAllowedException(ase.getMessage(), ase)); } - // 处理不合法的令牌错误 401 返回 + // 处理不合法的令牌错误 427 返回 ase = (InvalidTokenException) throwableAnalyzer.getFirstThrowableOfType(InvalidTokenException.class, causeChain); if (ase != null) { - return handleOAuth2Exception(new UnauthorizedException(ase.getMessage(), ase)); + return handleOAuth2Exception(new TokenInvalidException(ase.getMessage(), ase)); } ase = (OAuth2Exception) throwableAnalyzer.getFirstThrowableOfType(OAuth2Exception.class, causeChain); diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/TokenInvalidException.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/TokenInvalidException.java new file mode 100644 index 000000000..599b1dd08 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/exception/TokenInvalidException.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.exception; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer; + +/** + * @author lengleng + * @date 2021-08-05 + *

+ * 令牌不合法 + */ +@JsonSerialize(using = PigxAuth2ExceptionSerializer.class) +public class TokenInvalidException extends PigxAuth2Exception { + + public TokenInvalidException(String msg, Throwable t) { + super(msg); + } + + @Override + public String getOAuth2ErrorCode() { + return "invalid_token"; + } + + @Override + public int getHttpErrorCode() { + return 427; + } + +}