栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

spring security和shiro的安全处理

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

spring security和shiro的安全处理

spring security和shiro的安全处理

文章目录
  • spring security和shiro的安全处理
    • 依赖
    • 视图配置
    • 用户认证和授权
    • 注销及权限控制
    • 记住我及首页地址

依赖
 
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
        
        
            org.springframework.security
            spring-security-web
            5.1.4.RELEASE
        
        
        
            org.springframework.security
            spring-security-config
            5.1.4.RELEASE
        
        
        
            org.thymeleaf
            thymeleaf-spring5
            3.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");
	}

}

注销及权限控制 记住我及首页地址
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/685061.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号