<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

    After given a demo to the customer, they wished to modify the specification so that after login, the page always shows the name of the user logged in. Also they would prefer if the navigation was customized to the type of user that has logged in. e.g. standard users with ROLE_USER should not see the link to the admin page on the common navigation.

    The specification has been updated as follows:

    User Story 7: Create common navigation that all secure pages will contain.
    Note: There will be links to home, admin pages and a logout link.
    Note: only admin users should see the admin link on the common navigation.

    User Story 10: A common information bar should exist on all secure pages that displays whether the user is logged in or not.

    The solution

    To customize the common navigation per user role type and display the logged in username, we are going to use spring security’s tag libs, specifically the authorize and authentication tags.

    Add spring security taglibs as dependency

    Add spring-security-taglibs-2.0.4.jar to our WAR projects lib folder.

    The implementation

    The first step is to update our acceptance tests that verify behavior on the common navigation:

    @Test
    public void shouldNotBeAbleToSeeAdminLinkOnCommonNavigationWhenNotLoggedInAsStandardUser() {

    driver.get("http://localhost:8080/springsecuritywebapp/home.htm");
    login(driver);

    // verify
    assertThat(driver.getTitle(),
    is("Home: Spring Security Web Application"));

    try {
    driver.findElement(By.linkText("Admin"));
    fail("should not be able to see a link to admin page when logged in as standard user");
    } catch (final NoSuchElementException e) {
    assertNotNull(e);
    }

    }

    @Test
    public void shouldBeAbleToViewUsernameOfUserOnAdminPageWhenSuccessfullyAuthenticated() {
    loginAsUser(driver, withAdminRole());

    // state verification
    assertThat(driver.getTitle(),
    is("Admin: Spring Security Web Application"));
    assertThat(driver.findElement(By.id("loginstatus")).getText(),
    containsString("Logged in as: admin"));

    }

    @Test
    public void shouldBeAbleToViewUsernameOfUserOnHomePageWhenSuccessfullyAuthenticated() {
    login(driver);

    // state verification
    assertThat(driver.getTitle(),
    is("Home: Spring Security Web Application"));
    assertThat(driver.findElement(By.id("loginstatus")).getText(),
    containsString("Logged in as: username"));

    }

    Next step is to create a userinfobar.jsp file that will be included in each secure page:

    <span id="loginstatus">Logged in as: <security:authentication property="principal.username"/>
    </span>

    <br />

    Things to note:

    1. we are using the authentication tag from spring security’s tag libs (which will be included at top of each jsp that includes this file)

    Next this should be included in the home.jsp and admin.jsp pages. Here is home.jsp:

    <%@ page session="true"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix='security' uri='http://www.springframework.org/security/tags' %>
    <html>

    <head>
    <title>Home: Spring Security Web Application</title>

    </head>

    <body>

    <%@ include file="/WEB-INF/jsp/navigation.jsp" %>
    <%@ include file="/WEB-INF/jsp/userinfobar.jsp"%>

    home page: only logged in users should see this page.

    </body>

    </html>

    Things to note:

    1. The spring security tablib is included at top of page
    2. The userinfobar.jsp file is included so will display username of logged in users.

    Build, deploy and run all acceptance tests.

    Getting the code

    The code for this part is tagged and available for viewing online at: http://code.google.com/p/spring-security-series/source/browse/#svn/tags/SpringSecuritySeriesWAR-Part8

    SVN Url: https://spring-security-series.googlecode.com/svn/tags/SpringSecuritySeriesWAR-Part8

    posted on 2009-12-24 17:01 seal 閱讀(373) 評論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 免费观看成人久久网免费观看| 久久人午夜亚洲精品无码区| 男女一边桶一边摸一边脱视频免费| 宅男666在线永久免费观看 | 国产在线观看免费完整版中文版| 亚洲日韩国产一区二区三区在线| 真实乱视频国产免费观看| 亚洲国产精品99久久久久久| 免费国产在线观看老王影院 | a级片在线免费看| 亚洲AV无码码潮喷在线观看| 少妇太爽了在线观看免费视频 | 国产精品无码一区二区三区免费| 色五月五月丁香亚洲综合网| 国产成人精品久久亚洲高清不卡 | 国产自国产自愉自愉免费24区| 亚洲爱情岛论坛永久| 真人做人试看60分钟免费视频| 亚洲13又紧又嫩又水多| 日韩在线a视频免费播放| 一级人做人a爰免费视频 | 三年片在线观看免费观看高清电影 | 全部免费国产潢色一级| av网站免费线看| 久久精品国产亚洲av麻豆小说 | 亚洲美女视频一区| 免费被黄网站在观看| 久久九九免费高清视频| 亚洲高清无在码在线无弹窗| 操美女视频免费网站| 久久久受www免费人成| 亚洲国产高清美女在线观看| 在线免费观看韩国a视频| 中文字幕不卡免费高清视频| 亚洲人成伊人成综合网久久| 国产免费爽爽视频免费可以看| 好紧我太爽了视频免费国产 | 亚洲精品美女网站| 亚洲片一区二区三区| 国产人成免费视频网站| 九一在线完整视频免费观看|