日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

学习框架一

發布時間:2024/4/17 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 学习框架一 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這個系統后臺管理頁面我Ui是用FreeMarKer的宏對html標簽、表單進行了封裝,現在只需要引用就行

?

Spring Security入門篇——標簽sec:authorize的使用 (權限的分配)

Security框架可以精確控制頁面的一個按鈕、鏈接,它在頁面上權限的控制實際上是通過它提供的標簽來做到的

Security共有三類標簽authorize? authentication?? accesscontrollist? ,第三個標簽不在這里研究

前 提:項目需要引用spring-security-taglibs-3.05,jstl1.2的jar包,頁面加入:<%@ taglib prefix=”sec” uri=”http://www.springframework.org/security/tags” %>

本文配置

一、authorize

對應的類: org.springframework.security.taglibs.authz.AuthorizeTag

attribute: access url method? ifNotGranted? ifAllGranted? ifAnyGranted

使用方式:見SimpleDemo的index.jsp

<p>

<sec:authorize ifAllGranted="ROLE_ADMIN">#這里可以用逗號分隔,加入多個角色

你 擁有管理員權限,你可以查看 該頁面<a href="http://blog.163.com/sir_876/blog/admin.jsp"> 管理員進入</a> </sec:authorize> </p> <p> <sec:authorize url='/profile.jsp'>你登陸成功了可以看到 <a href="http://blog.163.com/sir_876/blog/profile.jsp"> 這個頁面</a></sec:authorize>

</p>

頁面標簽的使用與權限配置相對應

<intercept-url?? ??? ??? ?pattern="/admin.jsp"?? ??? ??? ?access="hasRole('ROLE_ADMIN')" />?? ??? ?<intercept-url?? ??? ??? ?pattern="/profile.jsp"?? ??? ??? ?access="isAuthenticated()" />?? ??? ?<intercept-url?? ??? ??? ?pattern="/**"?? ??? ??? ?access="permitAll" />

對比可以看到只有ROLE_ADMIN角色的用戶才能訪問admin.jsp,通過認證的用戶都可以訪問profile.jsp

從 標簽源碼可以知道,authorize標簽判斷順序是: access->url->ifNotGranted->ifAllGranted->ifAnyGranted 但他們的關系是“與”: 即只要其中任何一個屬性不滿足則該標簽中間的內容將不會顯示給用戶,舉個例子:

<sec:authorize? ifAllGranted=”ROLE_ADMIN,ROLE_MEMBER” ifNotGranted=”ROLE_SUPER”>滿足才會顯示給用戶 </sec:authorize>

標簽中間的內容只有在當前用戶擁有ADMIN,MEMBER角色,但不擁有SUPER權限時才會顯示

access屬性是基于角色判斷,url屬性是基于訪問路徑判斷,與security.xml配置對應

對于ifAllGranted ,ifNotGranted,ifAnyGranted屬性的理解可以與集合api類比

Collection grantedAuths? :當前用戶擁有的權限
Collection requiredAuths : 當前要求的權限,即ifAllGranted ,ifNotGranted,ifAnyGranted 屬性的值

滿足ifAllGranted: 只需要grantedAuths.containsAll(requiredAuths);返回true即可
滿足ifAnyGranted: 只需要grantedAuths.retainAll(requiredAuths);有內容即可(兩集合有交集)
滿足ifNotGranted:與Any相反,如果沒有交集即可

二、authentication

對應的類: org.springframework.security.taglibs.authz.AuthenticationTag

attribute: property(required) var? htmlEscape? scope

使用方式:

<sec:authentication property=’name’ />
<sec:authentication property=’principal.username’ />
<sec:authentication property=’principal.enabled’ />
<sec:authentication property=’principal.accountNonLocked’ />

主要用來顯示authentication屬性,

var scope: 將property的值以var設置到scope域中

htmlEscape: 將特殊字符轉義 > –> “&gt”

轉載于:https://www.cnblogs.com/zzyrunning/p/4580122.html

總結

以上是生活随笔為你收集整理的学习框架一的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。