- 在demo02的基础上开发
- 在spring boot整合security的项目中,是不能直接通过控制层跳转到resource目录下的html页面的
- 只有我们在security配置类中指定了403页面或登录页面时,才能跳转到这2个页面
| http.exceptionHandling().accessDeniedPage("/403.html"); |
| http.formLogin().loginPage("/login.html") |
| # 在security配置类中指定该接口需要role_admin角色权限 |
| .antMatchers("/test").hasRole("ADMIN") |
| |
| # 在CustomUserDetailsService中,该用户拥有的权限为admin |
| |
| # 编写css、js文件,放置1张图片 |
| # 将css、js、图片引入403.html |
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <title>test</title> |
| <link rel="stylesheet" href="./css/demo.css" type="text/css"> |
| <script type="text/javascript" src="./js/demo.js"></script> |
| </head> |
| <body> |
| <p class="cc">403!</p> |
| <img src="./imgs/mm01.jpg" style="height: 100px; width: 200px"> |
| <script> |
| fun() |
| </script> |
| </body> |
| </html> |
| |
| # 当访问test接口时,没有权限,就会跳转到403.html页面 |
| # 测试静态资源是否放行成功 |

| |
| .antMatchers("/**/*.css","/**/*.js","/imgs/**").permitAll() |
| # security配置类中添加如下,测试成功 |
| |
| .antMatchers(loadExcludePath()).permitAll() |
| |
| @Override |
| public void configure(WebSecurity web) { |
| web.ignoring().antMatchers(loadExcludePath()); |
| } |
| |
| private String[] loadExcludePath() { |
| return new String[]{ |
| "/**/*.css", |
| "/**/*.js", |
| "/imgs/**" |
| }; |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?