【发布时间】:2014-07-08 20:00:24
【问题描述】:
我需要创建一个系统,根据日期授予对网站的访问权限。
涉及 2 个角色:管理员和用户
并且有 2 个日期 (date1
这些是要求:
- date1之前根本无法登录
- 只有管理员可以在 date1 之后登录
- date2 之后,每个人都可以访问该页面,无需授权
这是我的 spring-security.xml:
<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.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<http auto-config="true">
<intercept-url pattern="/overview**" access="ROLE_ADMIN" />
<intercept-url pattern="/subscribe**" access="ROLE_ADMIN" />
<form-login
login-page="/login"
default-target-url="/overview"
authentication-failure-url="/login?error"
username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" />
<!-- enable csrf protection -->
<csrf/>
</http>
<authentication-manager>
<authentication-provider ref="customAuthProvider">
</authentication-provider>
</authentication-manager>
</beans:beans>
我的猜测是我需要编写一个自定义元素来替换拦截 URL 标记,但我不知道如何做到这一点。
【问题讨论】:
-
不,你没有。您只需要考虑日期和角色的自定义
UserDetailsChecker。
标签: spring security spring-mvc spring-security