Commit ec75ecf6 by zzrdark

springsecurity跨域问题

parent 7435e5f3
...@@ -26,7 +26,7 @@ public class OAuth2ResourceServer extends ResourceServerConfigurerAdapter { ...@@ -26,7 +26,7 @@ public class OAuth2ResourceServer extends ResourceServerConfigurerAdapter {
// 开启认证 // 开启认证
.anyRequest() .anyRequest()
.authenticated() .authenticated()
.and(); .and().cors().and().csrf().disable();
} }
......
...@@ -30,7 +30,7 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -30,7 +30,7 @@ public class WebConfig implements WebMvcConfigurer {
public void addCorsMappings(CorsRegistry registry) { public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") registry.addMapping("/**")
.allowedOrigins("*") .allowedOrigins("*")
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS","AUTHORIZATION") .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
.allowCredentials(true) .allowCredentials(true)
.maxAge(3600) .maxAge(3600)
.allowedHeaders("*"); .allowedHeaders("*");
......
...@@ -34,9 +34,8 @@ public class CrossFilter implements Filter { ...@@ -34,9 +34,8 @@ public class CrossFilter implements Filter {
httpResponse.setHeader("Access-Control-Allow-Methods", "*"); httpResponse.setHeader("Access-Control-Allow-Methods", "*");
httpResponse.setHeader("Access-Control-Max-Age", "3600"); httpResponse.setHeader("Access-Control-Max-Age", "3600");
httpResponse.setHeader("Access-Control-Allow-Headers", httpResponse.setHeader("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie, Authorization"); "Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie, Authorization,Access-Control-Allow-Origin");
httpResponse.setHeader("Access-Control-Allow-Credentials", "true"); httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
// httpResponse.setHeader("Content-type", "application/json");
httpResponse.setHeader("Cache-Control", "no-cache, must-revalidate"); httpResponse.setHeader("Cache-Control", "no-cache, must-revalidate");
filterChain.doFilter(request, httpResponse); filterChain.doFilter(request, httpResponse);
} }
......
...@@ -4,12 +4,14 @@ import com.mx.cneeds.common.result.R; ...@@ -4,12 +4,14 @@ import com.mx.cneeds.common.result.R;
import com.mx.cneeds.common.vo.UserInfoVo; import com.mx.cneeds.common.vo.UserInfoVo;
import com.mx.cneeds.server.datashow.client.AuthorizationClient; import com.mx.cneeds.server.datashow.client.AuthorizationClient;
import com.mx.cneeds.common.dto.JwtToken; import com.mx.cneeds.common.dto.JwtToken;
import com.netflix.client.http.HttpResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
...@@ -42,7 +44,7 @@ public class UserController { ...@@ -42,7 +44,7 @@ public class UserController {
} }
@RequestMapping("/info") @RequestMapping("/info")
public R getInfo(){ public R getInfo(HttpServletResponse response){
UserInfoVo userInfoVo = new UserInfoVo(); UserInfoVo userInfoVo = new UserInfoVo();
log.info("getInfo"); log.info("getInfo");
userInfoVo.setName("admin"); userInfoVo.setName("admin");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment