首页 > 其他分享 >spring security 4.1两个不错功能介绍

spring security 4.1两个不错功能介绍

时间:2022-12-08 12:31:20浏览次数:65  
标签:... code 4.1 spring userId checkUserId security CSP


一转眼, spring security 已经发布4.1 了,查看
了下新特性,有两个比较值得关注:


1) 可以在pathvariable形式的URL中进行保护了
  比如有个方法:


[code="java"]

public class WebSecurity {

public boolean checkUserId(Authentication authentication, int id) {

...

}

}

[/code]



则可以用这个配置进行防护

<http>

<intercept-url pattern="/user/{userId}/**"

access="@webSecurity.checkUserId(authentication,#userId)"/>

...

</http>




  这样,凡是/user/{userId}/**这样rest形式的url,都可以调用方法进行保护了
2) 支持Content Security Policy (CSP)
   什么是CSP?W3C的Content Security Policy,简称CSP。顾名思义,这个规范与内容安全有关,主要是用来定义页面可以加载哪些资源,减少XSS的发生。


   具体参考文章:https://www.ongod.org/1149.html
​​​ http://www.html5rocks.com/en/tutorials/security/content-security-policy/ ​​​

http://open.chrome.360.cn/extension_dev/contentSecurityPolicy.html

标签:...,code,4.1,spring,userId,checkUserId,security,CSP
From: https://blog.51cto.com/u_14230175/5920946

相关文章