fix: remove cors by security but use corsConfig
This commit is contained in:
@@ -14,9 +14,6 @@ public class SecurityConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
http
|
http
|
||||||
// 启用跨域配置
|
|
||||||
.cors(cors -> cors.configurationSource(
|
|
||||||
request -> new org.springframework.web.cors.CorsConfiguration().applyPermitDefaultValues()))
|
|
||||||
// 禁用默认的登录表单和HTTP基本认证
|
// 禁用默认的登录表单和HTTP基本认证
|
||||||
.formLogin(form -> form.disable())
|
.formLogin(form -> form.disable())
|
||||||
.httpBasic(basic -> basic.disable())
|
.httpBasic(basic -> basic.disable())
|
||||||
@@ -26,7 +23,8 @@ public class SecurityConfig {
|
|||||||
// 禁用CSRF保护
|
// 禁用CSRF保护
|
||||||
.csrf(csrf -> csrf.disable())
|
.csrf(csrf -> csrf.disable())
|
||||||
// 设置会话创建策略为无状态
|
// 设置会话创建策略为无状态
|
||||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
|
.sessionManagement(session -> session
|
||||||
|
.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import jakarta.annotation.Resource;
|
|||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import icu.sunway.ai_spring_example.Service.IExampleEntityService;
|
import icu.sunway.ai_spring_example.Service.IExampleEntityService;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RestController
|
@RestController
|
||||||
@@ -14,4 +17,11 @@ import icu.sunway.ai_spring_example.Service.IExampleEntityService;
|
|||||||
public class EaxmpleEntityController {
|
public class EaxmpleEntityController {
|
||||||
@Resource
|
@Resource
|
||||||
private IExampleEntityService exampleEntityService;
|
private IExampleEntityService exampleEntityService;
|
||||||
|
|
||||||
|
@PutMapping("test/{id}")
|
||||||
|
public String putMethodName(@PathVariable String id, @RequestBody String entity) {
|
||||||
|
// TODO: process PUT request
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user