亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

403 Forbidden 即使我授予訪問權限

403 Forbidden 即使我授予訪問權限

慕娘9325324 2023-05-24 15:16:51
我使用 spring security 創建了一個項目。在configure(HttpSecurity http)我為用戶設置訪問"/home"權限時,但在我登錄后,它顯示:403禁止訪問我創建了一個Entity class named User implementing UserDetails并且getAuthorities()我只是重新運行Arrays.asList(new SimpleGrantedAuthority("USER"));對于 http 對象,我嘗試使用直接.hasRole('USER')方法而不是.access("hasRole('USER')"),問題是一樣的。@Overrideprotected void configure(HttpSecurity http) throws Exception{    http        .authorizeRequests()         .antMatchers("/home")          .access("hasRole('USER')")          .antMatchers("/","/**").access("permitAll")          .anyRequest().authenticated()          .and()            .formLogin()            .and()        .httpBasic();}
查看完整描述

1 回答

?
繁花不似錦

TA貢獻1851條經驗 獲得超4個贊

您需要使用權限而不是角色。


@Override

protected void configure(HttpSecurity http) throws Exception {

http

    .authorizeRequests()

     .antMatchers("/home").hasAuthority("USER")

      .antMatchers("/","/**").access("permitAll")

      .anyRequest().authenticated()

      .and()

        .formLogin()

        .and()

    .httpBasic();

}


查看完整回答
反對 回復 2023-05-24
  • 1 回答
  • 0 關注
  • 175 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號