该应用程序具有四个角色和四个包含页面的匹配文件夹。一个额外的文件夹包含由多个角色共享的页面。目前,没有限制。一位测试人员发现,可以通过复制一个角色使用书签来直接访问页面,并在登录不同的角色时将其粘贴。
使用弹簧安全性最小。数据库中的角色和匹配表有一个枚举。用户可以有多个角色,在登录时选择一个角色。
我看到了这样的示例,它将进入spring-security.xml文件。
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/events/" access="hasRole('ROLE_ADMIN')"/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
</http>
我想这样编码:
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/administrator/**" access="hasRole('ROLE_ADMINISTRATOR')"/>
<intercept-url pattern="/client/**" access="hasRole('ROLE_CLIENT')"/>
</http>
包含用户登录作用的代码定义为:
public class LMSSession extends WebSession
是否有一种使用检票口(7.9)的方法?
如果您使用弹簧安全性,通常有一个用于弹簧安全配置的类
在这里,一个示例的链接使用https://spring.io/blog/2013/07/03/spring-security-java-config-previg-previg-preview-web-security/
和检查部分CustomWebsecurityConfigurerAdapter和方法
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeUrls()
.antMatchers("/signup","/about").permitAll() // #4
.antMatchers("/admin/**").hasRole("ADMIN") // #6
.anyRequest().authenticated() // 7
.and()
.formLogin() // #8
.loginUrl("/login") // #9
.permitAll(); // #5
}
您可以使用Spring Security的httpsecurity(或其XML等效)或Wicket的Iauthorizationstrategy来实现这一目标。
它可以按照用户角色作为/client/page1
和/client/page2
安装页面,然后您的问题中的弹簧安全片段应该这样做(我更喜欢Java配置样式,所以我不是100%确定XML已完成!)。
但是,如果您不想揭露URL中的角色,那么使用Wicket-auth-auth Roles的@AuthorizeInstantiation
也很容易做到这一点。检票员的演示很好!