Browse Source

拦截验证方式更新

hejq 7 years ago
parent
commit
f190763c94

+ 2 - 6
src/main/java/com/uas/platform/b2b/filter/SSOInterceptor.java

@@ -33,7 +33,6 @@ import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
 import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
-import org.springframework.ui.ModelMap;
 import org.springframework.util.StringUtils;
 
 import javax.servlet.http.HttpServletRequest;
@@ -191,11 +190,8 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
      */
     protected void setResponseAuthorized(HttpServletResponse response, boolean authorized) {
         response.setStatus(authorized ? HttpStatus.OK.value() : HttpStatus.UNAUTHORIZED.value());
-        try {
-            printJson(response, new ModelMap("authorized", authorized));
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
+        String authorizedValue = authorized ? HttpStatus.OK.name() : HttpStatus.UNAUTHORIZED.name();
+        response.setHeader("authorized", authorizedValue);
     }
 
     /**

+ 8 - 1
src/main/webapp/resources/js/index/app.js

@@ -12,7 +12,14 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
     app.factory('httpInterceptor', ['$window', '$q', function ($window, $q) {
         var httpInterceptor = {
             'responseError': function (response) {
-                if (response.status == 401 && !response.authorized) {// UNAUTHORIZED
+                var authorized = false;
+                var headers = response.headers();
+                angular.forEach(headers, function(header) {
+                    if (header.authorized == 'OK') {
+                        authorized = true;
+                    }
+                })
+                if (response.status == 401 && !authorized) {// UNAUTHORIZED
                     // window.location.href = response.data.loginUrl || 'index';
                     // window.location.href = window.location.origin + window.location.pathname + '/login';
                     window.location.reload();