java – Spring安全性不允许加载CSS或JS资源
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Spring安全性不允许加载CSS或JS资源,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1278字,纯文字阅读大概需要2分钟。
内容图文
![java – Spring安全性不允许加载CSS或JS资源](/upload/InfoBanner/zyjiaocheng/710/faba23d564254a8682f235bfd8529eba.jpg)
资源在src / main / resources / static / css或src / main / resources / static / js下,我正在使用spring boot,安全类是:
@Configuration
@EnableWebMvcSecurity
@EnableGlobalAuthentication
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// http.authorizeRequests().antMatchers("/", "/index", "/quizStart")
// .permitAll().anyRequest().authenticated();
// http.formLogin().loginPage("/login").permitAll().and().logout()
// .permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication().withUser("test").password("test")
.roles("USER");
}
}
当我从浏览器访问“/ index”时,它运行良好(可以加载资源),但是,如果我取消注释类中的四行,则无法加载资源,这四行意味着:
http.authorizeRequests().antMatchers("/", "/index", "/quizStart")
.permitAll().anyRequest().authenticated();
http.formLogin().loginPage("/login").permitAll().and().logout()
.permitAll();
任何人都可以帮忙吗?提前致谢.
解决方法:
您可能希望确保将包含这些项目的目录设置为permitAll.
这是我的spring安全上下文文件的摘录.在资源目录下,我有js,css和images文件夹,这些文件夹由此行授予权限.
<security:intercept-url pattern="/resources/**" access="permitAll" />
内容总结
以上是互联网集市为您收集整理的java – Spring安全性不允许加载CSS或JS资源全部内容,希望文章能够帮你解决java – Spring安全性不允许加载CSS或JS资源所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。