2012-03-04 76 views
1

我有我的MVC應用程序的JSP頁面有一些鏈接。現在我的目標是要顯示或隱藏特定的鏈接,這些我已經在自己的applicationContext-security.xml文件,如下定義某些某些特定的用戶:根據特定用戶在JSP上隱藏或顯示鏈接?

<authentication-provider> 
     <user-service id="userDetailsService"> 
      <user name="admin" password="admin" authorities="ROLE_TEST, ROLE_USER, ROLE_SUPERVISOR, ROLE_ADMIN" /> 
      <user name="tom" password="kite" authorities="ROLE_SUPERVISOR, ROLE_TEST, ROLE_USER" /> 
      <user name="user" password="pass" authorities="ROLE_USER, ROLE_TEST" /> 
      <user name="test" password="test" authorities="ROLE_TEST" /> 
     </user-service> 
    </authentication-provider> 

當用戶登錄到我的網站,他只能看到鏈接他有權看到。你有沒有或知道我在哪裏可以找到這樣的例子?

我的hello.jsp(應用程序主頁)

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

<html> 
    <head> 
    <link rel="stylesheet" type="text/css" href="css/mystyle.css" /> 
    <title><fmt:message key="title"/></title> 
    </head> 
    <body> 
    <h1><fmt:message key="heading"/></h1> 
    <p><fmt:message key="greeting"/> <c:out value="${model.now}"/></p> 
    <h3>Products</h3> 
    <table border="2" align="center"> 
<tr> 
<td align="center" width="50"><b><span style="color:red">Id</span></b></td> 

<td align="center" width="150"><b><span style="color:red">Product Name</span></b></td> 

<td align="center" width="150"><b><span style="color:red">Product Price</span></b></td> 

<td align="center" colspan="2" width="70"><b><span style="color:red">Actions</span></b></td> 

</tr> 
    <c:forEach items="${model.products}" var="prod"> 
     <tr> 
    <td align="center"><c:out value="${prod.id}"/></td> 
    <td align="center"><c:out value="${prod.description}"/></td> 
    <td align="center"><i>$<c:out value="${prod.price}"/></i></td> 
    <td align="center" width="70"> <a href="<c:url value="/editpage.htm?id="/>${prod.id}&prodname=${prod.description}&prodprice=${prod.price}">Edit</a></td> 
    <td align="center" width="70"><a href="<c:url value="/deleteprod.htm?id="/>${prod.id}&prodname=${prod.description}&prodprice=${prod.price}">Delete</a></td> 
    </tr> 
    </c:forEach> 
    </table> 
    <br> 
    <ul><li><a href="<c:url value="/addprod.htm"/>">Add New Products</a></li></ul> 
    <ul><li><a href="<c:url value="/priceincrease.htm"/>">Increase Prices</a></li></ul></br> 
    <%@ include file="/WEB-INF/jsp/navigation.jsp" %> 
    <%@ include file="/WEB-INF/jsp/userinfobar.jsp"%> 
    <p> 
    </body> 
</html> 

感謝您的幫助!

回答

2

春季安全有一個JSP taglib要做到這一點。

+0

謝謝你真的工作。 – AbdulAziz 2012-03-04 11:43:59