我需要创建一个系统,根据日期授予对网站的访问权限。按日期弹簧安全授权
这里涉及两个角色:管理员和用户
并有2个日期(DATE1 < DATE2)
这些要求:
- DATE1之前,您无法登录根本
- 只有管理员可以在日期后登录1
- 有了date2之后YONE可以访问该页面,则无需申请批准
这是我的弹簧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>
我的猜测是,我需要写一个自定义元素,以取代intercept-网址标签,但我不知道如何做到这一点。
不,你不会。你只需要一个自定义的['UserDetailsChecker'](http://docs.spring.io/spring-security/site/docs/current/apidocs/org/springframework/security/core/userdetails/UserDetailsChecker.html)记录日期和角色。 –