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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Spring Security 的 permitAll Unauthorized

Spring Security 的 permitAll Unauthorized

慕碼人8056858 2021-10-28 09:44:46
我想忽略所有帶有HttpMethod.GET的 URL,帶有 Post、Delete、Put 的 URL 需要進(jìn)行身份驗(yàn)證。我的網(wǎng)址是"/api/manga","/api/grupos","/api/autor","/genero","/api/pagina","/api/capitulo"PermitAll 不適用于 JWTFilter,如果刪除過濾器,則工作正常。如何忽略或允許所有網(wǎng)址HttpMethod.GET?需要?jiǎng)?chuàng)建單獨(dú)的 api 進(jìn)行身份驗(yàn)證?網(wǎng)絡(luò)安全配置@Configuration@EnableWebSecurity@EnableGlobalMethodSecurity(prePostEnabled = true)public class WebSecurityConfig extends WebSecurityConfigurerAdapter {    @Override    protected void configure(HttpSecurity http) throws Exception {        http.authorizeRequests()                .antMatchers(HttpMethod.GET, "/api/manga", "/api/grupos", "/api/autor", "/genero", "/api/pagina",                        "/api/capitulo")                .permitAll().anyRequest().fullyAuthenticated().and()                .addFilterBefore(new JWTAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class).httpBasic()                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().csrf()                .disable();    }    @Override    public void configure(WebSecurity web) throws Exception {        web.ignoring().antMatchers("/favicon.ico", "/", "/index.html", "/registrar", "/autenticar", "/app/**");    }}JWT認(rèn)證過濾器public class JWTAuthenticationFilter extends GenericFilterBean {    private static final String AUTHORIZATION_HEADER = "Authorization";    private static final String AUTHORITIES_KEY = "roles";    @Override    public void doFilter(final ServletRequest req, final ServletResponse res,final FilterChain filterChain)            throws IOException, ServletException {              final HttpServletRequest request = (HttpServletRequest) req;               String authReader = request.getHeader(AUTHORIZATION_HEADER);        if (authReader == null || !authReader.startsWith("Bearer ")) {            ((HttpServletResponse) res).sendError(HttpServletResponse.SC_UNAUTHORIZED, "invalido autorization");        } 
查看完整描述

2 回答

?
繁星淼淼

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊

解決方案是 ignore HttpMethod.GET,因此所有帶有 get 方法的 url 都將被忽略。


    @Override

    public void configure(WebSecurity web) throws Exception {

        web.ignoring()

        .antMatchers(HttpMethod.GET)

        .antMatchers("/favicon.ico", "/", "/index.html", "/registrar",

                "/autenticar", "/app/**");

    }


查看完整回答
反對(duì) 回復(fù) 2021-10-28
  • 2 回答
  • 0 關(guān)注
  • 383 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)