【发布时间】:2013-11-25 14:24:27
【问题描述】:
在我的项目中,我使用的是 spring security3.1,我附上我的 spring security 文件:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http auto-config="true">
<intercept-url pattern="/login" access="ROLE_ADMIN" />
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
</http>
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="SELECT user_name,user_password,account_status FROM systemuser WHERE user_name=?"
authorities-by-username-query="SELECT user_name,authority FROM systemuser WHERE user_name=?"/>
</authentication-provider>
</authentication-manager>
</beans:beans>
它工作正常。现在我的要求是我想自定义用户的访问权限。例如我有 3 个锚标记如下:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<table>
<tr>
<td><a href="${pageContext.request.contextPath}/manageUsers" id="user_link">Manage Users</a></td>
<td><a href="${pageContext.request.contextPath}/allcontact">Manage Contact</a></td>
<td><a href="<c:url value="/j_spring_security_logout" />" > Logout</a></td>
</tr>
现在,我希望管理员可以访问所有这 3 个选项卡(或链接),将他们带到相应的页面,但 ROLE_USER(普通用户)将无法访问'管理用户" 选项卡。所以我的意思是当具有权限 ROLE_ADMIN 的用户登录时,所有 3 个链接都将可见,但是当具有权限的用户 "ROLE_USER" 登录时只有 2 个链接,即 “管理联系人”和“注销” 将可见。
我该如何实现这个任何人都可以建议我????????
【问题讨论】: