- spring security和shiro的安全处理
- 依赖
- 视图配置
- 用户认证和授权
- 注销及权限控制
- 记住我及首页地址
视图配置org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-testtest org.springframework.security spring-security-web5.1.4.RELEASE org.springframework.security spring-security-config5.1.4.RELEASE org.thymeleaf thymeleaf-spring53.0.11.RELEASE
@Configuration public class WebMvcConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { // 浏览器访问的地址 // String urlPath = "/auth/to/reg.html"; // 要跳转的视图页面的名称,会加载配置文件中的视图前后缀 // String viewName = "register"; registry.addViewController("/vip1").setViewName("vip1/test1.html"); } // 这是拦截器,如果定制拦截器就是重写这个方法 }用户认证和授权
@EnableWebSecurity public class MySecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/").permitAll() .antMatchers("/a").hasRole("vip1") .antMatchers("/vip1 @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()) .withUser("hjx").password(new BCryptPasswordEncoder().encode("123")).roles("common") .and() .withUser("root").password(new BCryptPasswordEncoder().encode("123")).roles("vip1","vip2","vip3"); } }注销及权限控制 记住我及首页地址
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)