关于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");
}
}
spring 保护授权
最新推荐文章于 2021-09-18 02:49:57 发布