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登录用户的更多相关文章

  1. 四:Spring Security 登录使用 JSON 格式数据

    Spring Security 登录使用 JSON 格式数据 1.基本登录方案 1.1 创建 Spring Boot 工程 1.2 添加 Security 配置 2.使用JSON登录 江南一点雨-Sp ...

  2. 三:Spring Security 登录添加验证码

    Spring Security 登录添加验证码 1.准备验证码 2.自定义过滤器 3.配置 1.准备验证码 要有验证码,首先得先准备好验证码,本文采用 Java 自画的验证码,代码如下: /** * ...

  3. Spring Security 登录校验 源码解析

    传统情况下,在过滤器中做权限验证,Spring Secuirty也是在Filter中进行权限验证. 创建并注册过滤器 package com.awizdata.edubank.config; impo ...

  4. 解决:spring security 登录页停留时间过长 跳转至 403页面

    前言:最近的项目中用到了spring security组件,说句显low的话:我刚开始都不知道用了security好不勒,提了bug,在改的过程中,遇到了一些问题,找同事交流,才知道是用的securi ...

  5. spring boot:spring security给用户登录增加自动登录及图形验证码功能(spring boot 2.3.1)

    一,图形验证码的用途? 1,什么是图形验证码? 验证码(CAPTCHA)是"Completely Automated Public Turing test to tell Computers ...

  6. 获取spring security用户相关信息

    在JSP中获得 使用spring security的标签库 在页面中引入标签 <%@ taglib prefix="sec" uri="http://www.spr ...

  7. Spring Boot 整合 Spring Security,用户登录慢

    场景 Spring Boot + Spring Security搭建一个Web项目. 临时用了inMemoryAuthentication. @EnableWebSecurity public cla ...

  8. spring security 判断用户是否登录 只要登录就可以访问资源

    有些情况,只要用户登录就可以访问某些资源,而不需要具体要求用户拥有哪些权限,这时候可以使用IS_AUTHENTICATED_FULLY,配置如下所示: <http auto-config='tr ...

  9. spring security 控制用户信息用户加密 缓存用户信息

    1. MD5加密 任何一个正式的企业应用中,都不会在数据库中使用明文来保存密码的,我们在之前的章节中都是为了方便起见没有对数据库中的用户密码进行加密,这在实际应用中是极为幼稚的做法.可以想象一下,只要 ...

随机推荐

  1. 能量最小化初探,graphcuts能量最小化调用

    1.相对于能量函数来说,能量最小化的办法都有哪些? 梯度下降 模拟退火 图割 2.这个 跟最优化问题的求解,有什么联系跟区别呢? 基本上差不多,其实就是求出来了函数的一个最小值,我们看问题的时候不妨把 ...

  2. 清楚css浮动的三种方法

    第一种:添加新元素,应用clear:both;  <div class="clear"></div> css样式:clear:both; 第二种:在浮动元素 ...

  3. angularjs作用域之transclude

    transclude是一个可选的参数.如果设置了,其值必须为true,它的默认值是false.嵌入有时被认为是一个高级主题,但某些情况下它与我们刚刚学习过的作用域之间会有非常好的配合.使用嵌入也会很好 ...

  4. 模拟IC芯片设计开发的流程

    模拟IC芯片设计开发的流程 IC的设计,模拟和数字, 还有混合IC, 在设计方法, 注意点, 工具等有明显的区别, 我主要以模拟无线接收IC系统设计为例说明. 一个IC芯片的设计开发大致包括如下步骤. ...

  5. 苹果公司揭秘首批列入 Swift 源代码兼容性开源项目清单

    源代码兼容性是 Swift 未来的目标.为了实现这一目标,(苹果公司的 swift 编译器团队)建立了一个源兼容性测试套件,用于根据 Swift 源代码(逐渐增加)语料库对编译器进行回归测试更改. 添 ...

  6. PyQt IDE 环境搭建

    Eric的安装 1.按照目前pyqt5的要求安装了python3的最新版 2 pip3 install PyQt5 3. pip3 install QScintilla 4.download eric ...

  7. pydev 下Django 1.7 undefined variables from import问题的解决

    参考:http://stackoverflow.com/questions/24951029/pydev-django-undefined-variables-from-import 参考上面的帖子认 ...

  8. 与班尼特·胡迪一起攻破浮空城 (HZNU-2264)

    与班尼特·胡迪一起攻破浮空城 AC Time Limit:  1 s      Memory Limit:   256 MB Description 桐人为了拯救被困在浮空城堡最顶层的亚丝娜,决定从第 ...

  9. Java Code Style

    近期困惑于团队成员代码风格迥异,代码质量不可控,作为一名老司机,忧患于后期服务的可维护性,多次一对一的代码Review,耗时耗力不说,效果也不明显.痛定思痛,多次反思之后得出结论:无规矩不成方圆,可靠 ...

  10. tarjan算法讲解。

    tarjan算法讲解.   全网最详细tarjan算法讲解,我不敢说别的.反正其他tarjan算法讲解,我看了半天才看懂.我写的这个,读完一遍,发现原来tarjan这么简单! tarjan算法,一个关 ...