|
|
@@ -33,11 +33,13 @@ 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;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
@@ -66,6 +68,17 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
|
|
|
|
|
|
private final DeviceResolver deviceResolver = new LiteDeviceResolver();
|
|
|
|
|
|
+ /**
|
|
|
+ * 手机号正则表达式
|
|
|
+ */
|
|
|
+ static final String TEL_REGEXP = "^((\\(\\d{3}\\))|(\\d{3}\\-))?(13|15|18)\\d{9}$";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * UU号正则表达式
|
|
|
+ */
|
|
|
+ static final String UU_REGEXP = "^\\d{4,}$";
|
|
|
+
|
|
|
+
|
|
|
private HashMap<String, Collection<ConfigAttribute>> resourceMap;
|
|
|
private HashMap<Long, Collection<GrantedAuthority>> authorities;
|
|
|
|
|
|
@@ -141,8 +154,8 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- response.setStatus(HttpStatus.OK.value());
|
|
|
- return true;
|
|
|
+ setResponseAuthorized(response, true);
|
|
|
+ return true;
|
|
|
} else {
|
|
|
if (SecurityConstant.AUTHENTICATION_URL.equals(request.getRequestURI())) {
|
|
|
return true;
|
|
|
@@ -151,11 +164,40 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
|
|
|
if (matcher.matches(request)) {
|
|
|
return true;
|
|
|
}
|
|
|
- response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
|
|
+ setResponseAuthorized(response, false);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 输出json格式
|
|
|
+ *
|
|
|
+ * @param obj
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ protected void printJson(HttpServletResponse response, Object obj) throws IOException {
|
|
|
+ response.addHeader("Content-Type", "application/json; charset=UTF-8");
|
|
|
+ PrintWriter printWriter = response.getWriter();
|
|
|
+ printWriter.append(FlexJsonUtils.toJson(obj));
|
|
|
+ printWriter.flush();
|
|
|
+ printWriter.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置response相关状态
|
|
|
+ *
|
|
|
+ * @param response response
|
|
|
+ * @param authorized 验证是否通过
|
|
|
+ */
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 验证成功
|
|
|
*
|
|
|
@@ -188,6 +230,7 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
|
|
|
}
|
|
|
if (user != null) {
|
|
|
SystemSession.setUser(user);
|
|
|
+ setResponseAuthorized(response, true);
|
|
|
try {
|
|
|
accessDecision(request, user);
|
|
|
} catch (IOException e) {
|
|
|
@@ -382,10 +425,6 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
|
|
|
return SitePreference.NORMAL;
|
|
|
}
|
|
|
|
|
|
- static final String TEL_REGEXP = "^((\\(\\d{3}\\))|(\\d{3}\\-))?(13|15|18)\\d{9}$";
|
|
|
-
|
|
|
- static final String UU_REGEXP = "^\\d{4,}$";
|
|
|
-
|
|
|
/**
|
|
|
* 自动登录
|
|
|
*
|