spring 保护授权

关于spring 中授权的使用,记录下,以便后期使用。
 


import javax.sql.DataSource;
import java.beans.Encoder;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    DataSource dataSource;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/", "/home").hasRole("USER")
                .and().formLogin();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        auth
                .inMemoryAuthentication()
                .passwordEncoder(new BCryptPasswordEncoder())
                .withUser("jxm")
                .password(new BCryptPasswordEncoder().encode("1"))
                .roles("USER");

    }

}


版权声明:本文为jixiaomeng821原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。