spring security的简单例子分析
发表于:2024-09-29 作者:千家信息网编辑
千家信息网最后更新 2024年09月29日,这篇文章主要讲解了"spring security的简单例子分析",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"spring security的简单例子
千家信息网最后更新 2024年09月29日spring security的简单例子分析Insert title here
这篇文章主要讲解了"spring security的简单例子分析",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"spring security的简单例子分析"吧!
1 pom.的主要文件 我引入的thymeleaf-extras-springsecurity5,springboot2.1.6
org.thymeleaf.extras thymeleaf-extras-springsecurity5 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-security 2 controller[@Controller](https://my.oschina.net/u/1774615) org.springframework.boot spring-boot-starter-test test
public class KungfuController {
private final String PREFIX = "pages/";@RequestMapping("/")public String index() { System.out.println("hello word"); return "welcome";}@RequestMapping("/userlogin")public String loginPage() { return PREFIX+"login1";}@GetMapping("/level1/{path}")public String level1(@PathVariable("path")String path) { return PREFIX+"level1/"+path;}@GetMapping("/level2/{path}")public String level2(@PathVariable("path")String path) { return PREFIX+"level2/"+path;}@GetMapping("/level3/{path}")public String level3(@PathVariable("path")String path) { return PREFIX+"level3/"+path;}
}
//配置下
@EnableWebSecurity public class mySecurity extends WebSecurityConfigurerAdapter {
//为啥引入这个bean ,因为在securety在5.0后使用系统的登录模板,默认把密码给加密啦,这个写的是不让密码加密
@Beanpublic static NoOpPasswordEncoder passwordEncoder() { return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();}protected void configure(HttpSecurity http) throws Exception { //定制请求的授权规则 http.authorizeRequests().antMatchers("/").permitAll() .antMatchers("/level1/**").hasRole("VIP1") .antMatchers("/level2/**").hasRole("VIP2") .antMatchers("/level3/**").hasRole("VIP3"); //开启自动登录的功能 http.formLogin(); //开启自动配置的注销功能 http.logout().logoutSuccessUrl("/"); }public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser("mao").password("123").roles("VIP1","VIP2") .and().withUser("zhang").password("123").roles("VIP1","VIP3").and() .withUser("li").password("123").roles("VIP2","VIP3"); }
} //该模板都是尚学堂的
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
欢迎光临武林秘籍管理系统
游客您好,如果想查看武林秘籍 请登录
,您好,您的角色有:
感谢各位的阅读,以上就是"spring security的简单例子分析"的内容了,经过本文的学习后,相信大家对spring security的简单例子分析这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
例子
分析
学习
登录
您好
内容
功能
密码
模板
武林
秘籍
系统
加密
配置
学堂
就是
思路
情况
文件
文章
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
建立数据库对象有哪些
重庆秀山蔬菜软件开发
软件开发行业市场竞争分析
吴江区管理软件开发记录
hp服务器怎么刷固件
大连进销存软件开发公司
材料测试技术数据库
其他软件开发属于什么行业分类
天眼查东莞来思网络技术
eve的服务器是军用的吗
公司网络技术工资多少
法意数据库答题题库
教科版网络技术应用课本
饭店点餐管理系统数据库
企业网络安全方案设计的摘要
计算机网络技术基础搜题答案
日本的云服务器
个体户可以经营软件开发吗
软件开发行业调研
plc 设置服务器
有网络安全大赛吗
嵌入式软件开发写什么软件
whonet软件开发是哪年
构造可持续发展的网络安全空间
互联网科技破产
数据库改密码会影响代码么
软件开发b s
截面数据库
pc清软件用户数据库
嘟嘟传奇引擎版本数据库下载