Commit 9347a3c5 by 邓敏

单设备登录

1 parent b1448565
package com.subsidy.common.configure;
import com.subsidy.common.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
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.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
......@@ -59,5 +64,15 @@ public class WebConfig implements WebMvcConfigurer {
.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;
import com.alibaba.fastjson.JSON;
import com.auth0.jwt.interfaces.Claim;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.subsidy.common.ResponseData;
......@@ -13,7 +14,9 @@ import com.subsidy.util.JwtUtil;
import com.subsidy.util.Localstorage;
import com.subsidy.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
......@@ -43,6 +46,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
private RedisUtil redisUtil;
@Override
@CrossOrigin()
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// 不需要进行拦截
if (!(handler instanceof HandlerMethod)) {
......@@ -83,6 +87,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
if(tk.equals(token)) {
return true;
}
throw new HttpException(1011);
} else {
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!