第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在MockMvc測試期間如何使用正確的Spring Security配置

在MockMvc測試期間如何使用正確的Spring Security配置

溫溫醬 2021-04-28 05:45:26
我正在嘗試測試其中一項的訪問,該訪問@RestController由定制的Spring Security配置保護。我的用例如下:HTTP GETto/someEndpoint通過身份驗證得到保護,但是POST對同一終結(jié)點的HTTP請求卻不被保護。當我啟動應用程序并用我的前端或郵遞員對其進行測試時,它工作正?!,F(xiàn)在,我正在嘗試MockMvc使用安全性配置編寫測試。我已經(jīng)在StackOverflow上通過很多答案獲得了成功,但是沒有任何幫助。我的測試設置如下所示:@RunWith(SpringRunner.class)@WebMvcTest(controllers = MyController.class)@WebAppConfiguration@ContextConfigurationpublic class AssessmentControllerTest {    private MockMvc mockMvc;    @Autowired    private WebApplicationContext webApplicationContext;    @Before    public void init() throws Exception {        this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)                .alwaysDo(print())                .apply(SecurityMockMvcConfigurers.springSecurity())                .build();    }    // some test methods}通過此設置,我所有的端點都得到了保護,甚至HTTPPOST都返回401而不是201。我還啟用了調(diào)試日志以提高安全性,并且在調(diào)試日志中指出測試使用,default configure(HttpSecurity)但在日志中找不到我的任何AntMatchers:2018-07-04 19:20:02.829 DEBUG 2237 --- [           main] s.s.c.a.w.c.WebSecurityConfigurerAdapter : Using default configure(HttpSecurity). If subclassed this will potentially override subclass configure(HttpSecurity).2018-07-04 19:20:03.097 DEBUG 2237 --- [           main] edFilterInvocationSecurityMetadataSource : Adding web access control expression 'authenticated', for org.springframework.security.web.util.matcher.AnyRequestMatcher@12018-07-04 19:20:03.127 DEBUG 2237 --- [           main] o.s.s.w.a.i.FilterSecurityInterceptor    : Validated configuration attributes2018-07-04 19:20:03.130 DEBUG 2237 --- [           main] o.s.s.w.a.i.FilterSecurityInterceptor    : Validated configuration attributes2018-07-04 19:20:03.161  INFO 2237 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: 通??梢栽贛ockMvc測試期間使用我的具體Spring Security配置,還是必須在測試期間使用引導整個Spring上下文@SpringBootTest?我正在使用(帶有Java 1.8的Spring Boot 2.0.3.RELEASE)
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 439 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號