首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

《Spring Security3》第三章第部分翻译

2012-10-25 
《Spring Security3》第三章第一部分翻译第三章?? 增强用户体验 ?实现登录的controller??多谢多谢,继续努力3

《Spring Security3》第三章第一部分翻译
第三章?? 增强用户体验


?

实现登录的controller


?


?


多谢多谢,继续努力 3 楼 hoar 2011-07-05   不错,lz辛苦 4 楼 freeboat 2011-09-26   请问 BaseController 第二章已经添加? 为什么没找到呢? 5 楼 lengyun3566 2011-09-26   freeboat 写道请问 BaseController 第二章已经添加? 为什么没找到呢?
多谢您的关注。这个类开始是没有任何方法的,仅仅是一个基类,书上没有写,随着后续章节不断扩展,到第五章结束时的源码为:
package com.packtpub.springsecurity.web.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.ModelAttribute;

public class BaseController {

/**
* Gets the current request's {@link Authentication} information and returns it.

* @return Authentication for current request
*/
protected Authentication getAuthentication() {
return SecurityContextHolder.getContext().getAuthentication();
}

@ModelAttribute("showLoginLink")
public boolean getShowLoginLink() {
for (GrantedAuthority authority : getAuthentication().getAuthorities()) {
if(authority.getAuthority().equals("ROLE_USER")) {
return false;
}
}
return true;
}
} 6 楼 lengyun3566 2011-09-26   freeboat 写道请问 BaseController 第二章已经添加? 为什么没找到呢?
你可以到以下地址http://www.packtpub.com/support?nid=4435下载完整的源代码,因为压缩包比较大,不好直接传上来 7 楼 lijingzhi 2012-01-04   header.jsp源代码有点问题,运行会报500错误
<strong><sec:authentication property="principal.username"/></strong>

需要先判断一下是不是已经认证了,如果认证了才显示已认证的username
<strong>
    <sec:authorize access="isAuthenticated()">
        <sec:authentication property="principal.username"/>
    </sec:authorize>
</strong>

热点排行