最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring Security中successHandler無效問題及解決

 更新時(shí)間:2024年08月01日 15:31:02   作者:一支萬寶路  
這篇文章主要介紹了Spring Security中successHandler無效問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Spring Security中successHandler無效

原先代碼

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().authenticated()
                // 自定義登錄頁面
                .and()
                .formLogin()
                .loginPage("/login.html")
                .successHandler((req, resp, auth) -> {
                    Object principal = auth.getPrincipal();
                    resp.setContentType("application/json;charset=utf-8");
                    PrintWriter out = resp.getWriter();
                    out.write(new ObjectMapper().writeValueAsString(principal));
                    out.flush();
                    out.close();
                })
                .permitAll()
                // 關(guān)閉 csrf
                .and()
                .csrf().disable();
    }

以上代碼運(yùn)行之后

無論怎么測試,successHandler都無效,只會(huì)返回原來的登錄頁面,

但是,加入自定義登錄接口url之后,successHandler又生效:

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().authenticated()
                // 自定義登錄頁面
                .and()
                .formLogin()
                .loginPage("/login.html")
                // 自定義登錄接口
                .loginProcessingUrl("/doLogin")
                .successHandler((req, resp, auth) -> {
                    Object principal = auth.getPrincipal();
                    resp.setContentType("application/json;charset=utf-8");
                    PrintWriter out = resp.getWriter();
                    out.write(new ObjectMapper().writeValueAsString(principal));
                    out.flush();
                    out.close();
                })
                .permitAll()
                // 關(guān)閉 csrf
                .and()
                .csrf().disable();
    }

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

砀山县| 香港 | 扬中市| 固安县| 金平| 涞源县| 措美县| 沁源县| 塘沽区| 无极县| 昭觉县| 广东省| 桐梓县| 华坪县| 威信县| 汤阴县| 吉安县| 乡城县| 阿坝县| 揭阳市| 长治市| 金塔县| 堆龙德庆县| 临江市| 年辖:市辖区| 马边| 吉水县| 谢通门县| 罗城| 五指山市| 樟树市| 天全县| 乡宁县| 奉节县| 沁阳市| 磐安县| 佛坪县| 德江县| 威信县| 蓬溪县| 福清市|