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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

页面获取Spring Security登录用户

發布時間:2023/12/4 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 页面获取Spring Security登录用户 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

1.在session中取得spring security的登錄用戶名如下:
${session.SPRING_SECURITY_CONTEXT.authentication.principal.username}
spring security 把SPRING_SECURITY_CONTEXT 放入了session 沒有直接把username 放進去。下面一段代碼主要描述的是session中的存的變量,

存跳轉時候的URLsession
{SPRING_SECURITY_SAVED_REQUEST_KEY=SavedRequest[http://localhost:8080/AVerPortal/resourceAction/resourceIndex.action]}
存的是登錄成功時候session中存的信息:

session {SPRING_SECURITY_CONTEXT=org.springframework.security.context.SecurityContextImpl@87b16984: Authentication: org.springframework.security.providers.cas.CasAuthenticationToken@87b16984: Principal: com.avi.casExtends.UserInfo@ff631d80: Username: test; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Password: [PROTECTED]; Authenticated: true; Details: org.springframework.security.ui.WebAuthenticationDetails@12afc: RemoteIpAddress: 127.0.0.1; SessionId: AE56E8925195DFF4C50ABD384574CCEA; Granted Authorities: ROLE_ADMIN Assertion: org.jasig.cas.client.validation.AssertionImpl@661a11 Credentials (Service/Proxy Ticket): ST-3-1lX3acgZ6HNgmhvjXuxB-cas, userId=2, userName=test}

2.在頁面端用tag獲取:
<%@ taglib prefix='security' uri='http://www.springframework.org/security/tags'%>
<security:authentication property="principal.username"></security:authentication>
或者
<security:authorize ifAllGranted="ROLE_ADMIN">
<security:authentication property="principal.username"></security:authentication>
</security:authorize>
或者取session中的值:

${session.SPRING_SECURITY_CONTEXT.authentication.principal.username}
3.在后臺獲取

UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext()
.getAuthentication()
.getPrincipal();

userDetails.getUsername()

?

如果想要獲取更多的信息:得擴展userDetails的默認實現類user類和UserDetailsService接口

由于springsecurity是把整個user信息放入session中的即:session.SPRING_SECURITY_CONTEXT.authentication.principal。這個就是代表著user對象。

http://blog.csdn.net/zmx729618/article/details/51914836

?

6.1 th:text屬性
可對表達式或變量求值,并將結果顯示在其被包含的 html 標簽體內替換原有html文本
文本連接:用“+”符號,若是變量表達式也可以用“|”符號
6.2 th:utext屬性
e.g.
若home.welcome=Welcome to our <b>fantastic</b> grocery store!
用<p th:text="#{home.welcome}"></p>解析結果為:
<p>Welcome to our <b>fantastic</b> grocery store!</p>
解決方案
<p th:utext="#{home.welcome}"></p>即可。
等效于<p>Welcome to our <b>fantastic</b> grocery store!</p>

<div> <ol> <li>文本: <ol> <li>'xxxx':Now you are looking at a <span th:text="'working web application'">template file</span>.</li> <li>不能有空格、逗號:Now you are looking at a <span th:text="workingwebapplication">template file</span>.</li> </ol> </li> <li>數字: <ol> <li>The year is <span th:text="2014">1492</span>.</li> <li>In two years, it will be <span th:text="2014 + 2">1494</span>.</li> </ol> </li> <li>布爾值(true/false): <ol> <li>獲取對象屬性:<span th:if="${user.isAdmin} == false"> ...</span></li> <li>獲取對象的方法(public):<span th:if="${user.isAdmin()} == false"> ...</span></li> </ol> </li> <li>null:<span th:if="${user.isAdmin()} == null"> ...</span></li> <li>連接: <ol> <li>連接符+:<span th:text="'The name of the user is ' + ${user.userName}"></span></li> <li>連接符|:<span th:text="|Welcome to our application, ${user.userName}!|"></span></li> <li><span th:text="'Welcome to our application, ' + ${user.userName} + '!'"></span></li> <li><span th:text="${onevar} + ' ' + |${twovar}, ${threevar}|"></span></li> <li><span th:utext="#{home.welcome}">Welcome to our grocery store!</span></li> </ol> </li> <li>th:utext: <ol> <li>th:text:<span th:text="${textWelcome}">textWelcome!</span></li> <li>th:utext:<span th:utext="${textWelcome}">textWelcome!</span></li> </ol> </li> </ol> </div>

http://blog.csdn.net/sun_jy2011/article/details/40215101

?

總結

以上是生活随笔為你收集整理的页面获取Spring Security登录用户的全部內容,希望文章能夠幫你解決所遇到的問題。

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