我在我的MVC应用程序的JSP中有一个主页,它有一些链接。现在我的目标是隐藏或显示我已经在applicationContext-security.xml中定义的某些特定用户的特定链接,如下所示:
<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>
感谢您的帮助!