Commit 9347a3c5 by 邓敏

单设备登录

1 parent b1448565
package com.subsidy.common.configure; package com.subsidy.common.configure;
import com.subsidy.common.interceptor.AuthenticationInterceptor; import com.subsidy.common.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
...@@ -59,5 +64,15 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -59,5 +64,15 @@ public class WebConfig implements WebMvcConfigurer {
.addPathPatterns("/**"); .addPathPatterns("/**");
} }
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.setMaxAge(3600L);
config.addAllowedOrigin("*");
config.addAllowedMethod("*");
config.addAllowedHeader("*");
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", config);
return new CorsFilter(configSource);
}
} }
\ No newline at end of file
package com.subsidy.common.interceptor; package com.subsidy.common.interceptor;
import com.alibaba.fastjson.JSON;
import com.auth0.jwt.interfaces.Claim; import com.auth0.jwt.interfaces.Claim;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.subsidy.common.ResponseData; import com.subsidy.common.ResponseData;
...@@ -13,7 +14,9 @@ import com.subsidy.util.JwtUtil; ...@@ -13,7 +14,9 @@ import com.subsidy.util.JwtUtil;
import com.subsidy.util.Localstorage; import com.subsidy.util.Localstorage;
import com.subsidy.util.RedisUtil; import com.subsidy.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
...@@ -43,6 +46,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor { ...@@ -43,6 +46,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Override @Override
@CrossOrigin()
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// 不需要进行拦截 // 不需要进行拦截
if (!(handler instanceof HandlerMethod)) { if (!(handler instanceof HandlerMethod)) {
...@@ -83,6 +87,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor { ...@@ -83,6 +87,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
if(tk.equals(token)) { if(tk.equals(token)) {
return true; return true;
} }
throw new HttpException(1011); throw new HttpException(1011);
} else { } else {
throw new HttpException(1010); throw new HttpException(1010);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!