|
|
@@ -2,11 +2,15 @@ package com.uas.sso.sso.backend.config;
|
|
|
|
|
|
import com.uas.sso.sso.backend.entity.Admin;
|
|
|
import com.uas.sso.sso.backend.support.AccountSession;
|
|
|
+import com.uas.sso.sso.backend.support.ResultBean;
|
|
|
+import com.uas.sso.sso.backend.util.JacksonUtils;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
|
|
|
|
/**
|
|
|
@@ -32,8 +36,17 @@ public class SecurityInterceptor extends HandlerInterceptorAdapter {
|
|
|
}
|
|
|
|
|
|
if (!flag) {
|
|
|
- response.sendRedirect("/login");
|
|
|
- // response.sendError(HttpStatus.UNAUTHORIZED.value(), "请您进行登录认证");
|
|
|
+ String accept = request.getHeader("Accept");
|
|
|
+ if (StringUtils.hasText(accept) && accept.contains(MediaType.APPLICATION_JSON_VALUE)) {
|
|
|
+ String loginUrl = request.getHeader("Referer") + "login";
|
|
|
+ ResultBean<String> resultBean = new ResultBean<>(loginUrl);
|
|
|
+
|
|
|
+ response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
|
|
+ response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
|
|
+ response.getWriter().append(JacksonUtils.toJson(resultBean)).flush();
|
|
|
+ } else {
|
|
|
+ response.sendRedirect("/login");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return flag;
|