Spring中的安全模块

今天我学习了Spring中的安全模块,包括基于角色的鉴权、表单登录、HTTP Basic鉴权等功能。

@Configuration

@EnableWebSecurity

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

 

    @Autowired

    private UserDetailsService userDetailsService;

 

    @Override

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth.userDetailsService(userDetailsService);

    }

 

    @Override

    protected void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests()

            .antMatchers("/**").hasRole("USER")

            .and()

            .formLogin()

            .and()

            .httpBasic();

    }

}

posted @ 2023-05-22 21:18  ITJAMESKING  阅读(7)  评论(0编辑  收藏  举报