spring-security(五)
摘自《pro spring security》基于spring security 4.2.2.RELEASE
ConfigAttribute
org.springframework.security.access.ConfigAttribute
接口封装了可访问的受保护资源中的元数据(metadata),如ROLE_ADMIN
就是一个ConfigAttribute,如一些ConfigAttribute的实现:
当方法上使用@Secured("ROLE_ADMIN")
注解或者通过形如<security:intercept-url pattern="/hello" access="ROLE_SIMPSON_MEMBER" />
拦截URL,那么spring security就开始工作了。当使用标签<security:intercept-url pattern="/x" access="ROLE_XX" />
时,spring security
使用FilterInvocationSecurityMetadataSourceParser
去解析XML,在解析的过程中,调用private
方法parseInterceptUrlsForFilterInvocationRequestMap
,这个方法将标签中pattern
对应的URL映射成了Ant
风格的请求路径,如/*
,这里的ROLE_XX
就是ConfigAttribute
,这个map初始化在FilterSecurityInterceptor内部的org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSourc
实例中,当请求过来时,通过map中key去匹配请求的URL,找出对应的ConfigAttribute
去校验这个请求认证对象(Authentication Object
)的权限。解析流程:
如果要在方法上使用,则需要在security上下文中加上:
<global-method-security secured-annotations = "enabled"/>