之前是使用配置類的方式來資源URL進行權限的限制,現在可以使用注解的方式來限定。
1.@Secured:限定某個方法只有是指定的角色才能訪問,如下:
只有是sale或者manager角色才能訪問該方法。
記住,前提是得開啟security注解才行,如下:
@EnableGlobalMethodSecurity(securedEnabled = true,prePostEnabled = true) public class SpringsecurityDemoApplication {
如果使用@Secured,那么securedEnabled = true才行
2.@PreAuthorize:方法執行之前的權限校驗,具體校驗的內容看注解屬性,如下:
前提也是得如下:
@EnableGlobalMethodSecurity(securedEnabled = true,prePostEnabled = true) public class SpringsecurityDemoApplication {
使用方法前后校驗的注解,prePostEnabled = true才行
3.@PostAuthorize:方法之后的權限校驗。如果校驗失敗,那方法中 return 這行是無效的
4.@PreFilter:是對傳入過來的參數進行過濾
5.@PostFilter:對方法的返回值進行過濾