SpringSecurity配置文件

@EnableWebSecurity
public class seccurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //首页所有人可以访问,功能也只有对应有权限的人才能访问
        http.authorizeRequests()
                .antMatchers("/").permitAll()
                .antMatchers("/templates下的文件夹/**表示所有文件").hasRole("")
                .antMatchers("/templates下的文件夹/**表示所有文件").hasRole("");
        //没有权限跳到登录页面,需要开启登录的页面
        http.formLogin();
    }

}

官方的

    protected void configure(HttpSecurity http) throws Exception {
     *         http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin()
     *                 .usernameParameter("username") // default is username
     *                 .passwordParameter("password") // default is password
     *                 .loginPage("/authentication/login") // default is /login with an HTTP get
     *                 .failureUrl("/authentication/login?failed") // default is /login?error
     *                 .loginProcessingUrl("/authentication/login/process"); // default is /login
     *                                                                         // with an HTTP
     *                                                                         // post
     *     }
原文地址:https://www.cnblogs.com/HezhenbinGoGo/p/13268614.html