首页>代码>SpringBoot整合Security极简入门实例>/springboot-security-demo/src/main/java/com/simon/springbootsecuritydemo/config/SecurityConfig.java
package com.simon.springbootsecuritydemo.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; /** * @author Simon */ @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserDetailsService userDetailsService; //授权 @Override protected void configure(HttpSecurity http) throws Exception { /** 从数据库设置用户权限测试 */ http.authorizeRequests() .antMatchers("/").permitAll() .antMatchers("/druid/**").permitAll() .antMatchers("/level1/**").hasAuthority("1") .antMatchers("/level2/**").hasAuthority("2") .antMatchers("/level3/**").hasAuthority("3"); http.formLogin().loginPage("/toLogin") .usernameParameter("username").passwordParameter("password") .loginProcessingUrl("/login"); http.logout().logoutSuccessUrl("/"); http.rememberMe().rememberMeParameter("remember"); http.csrf().disable(); } //认证 @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder()); } }

f22m1a2b2 LV17
1月23日
adr666
1月8日
暂无贡献等级
Hachi6 LV13
2023年9月8日
2131234536546 LV7
2023年9月8日
励志12345 LV3
2023年8月29日
另类清晨 LV8
2023年8月19日
www2222 LV2
2023年8月9日
lipanlong LV10
2023年7月6日
Weishenghui LV7
2023年6月10日
微信网友_6508798513811456 LV5
2023年6月8日