|
@@ -2,17 +2,21 @@ package com.keao.edu.common.security;
|
|
|
|
|
|
import com.keao.edu.common.constant.CommonConstants;
|
|
|
import com.keao.edu.common.entity.HttpResponseResult;
|
|
|
+
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
import org.codehaus.jackson.map.ObjectMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.security.access.AccessDeniedException;
|
|
|
+import org.springframework.security.authentication.InsufficientAuthenticationException;
|
|
|
+import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
|
|
|
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
import java.io.IOException;
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
@@ -35,8 +39,16 @@ public class BaseAccessDeniedHandler extends OAuth2AccessDeniedHandler {
|
|
|
if (e == null) {
|
|
|
e = authException;
|
|
|
}
|
|
|
+
|
|
|
+ int errorCode = 500;
|
|
|
+ if (e instanceof InvalidTokenException) {
|
|
|
+ errorCode = HttpServletResponse.SC_UNAUTHORIZED;
|
|
|
+ }
|
|
|
+ if (e instanceof InsufficientAuthenticationException) {
|
|
|
+ errorCode = HttpServletResponse.SC_FORBIDDEN;
|
|
|
+ }
|
|
|
|
|
|
- HttpResponseResult result = new HttpResponseResult(false, HttpServletResponse.SC_FORBIDDEN, null, e.getMessage());
|
|
|
+ HttpResponseResult<Object> result = new HttpResponseResult<Object>(false, errorCode, null, e.getMessage());
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|