我创建了一个实现FilterInvocationSecurityMetadataSource接口的类。
我是这样实现的:
public List<ConfigAttribute> getAttributes(Object object) {
FilterInvocation fi = (FilterInvocation) object;
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Long companyId = ((ExtenededUser) principal).getCompany().getId();
String url = fi.getRequestUrl();
// String httpMethod = fi.getRequest().getMethod();
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>();
FilterSecurityService service = (FilterSecurityService) SpringBeanFinder.findBean("filterSecurityService");
Collection<Role> roles = service.getRoles(companyId);
for (Role role : roles) {
for (View view : role.getViews()) {
if (view.getUrl().equalsIgnoreCase(url))
attributes.add(new SecurityConfig(role.getName() + "_" + role.getCompany().getName()));
}
}
return attributes;
}
当我调试应用程序时,我看到它达到了这个类,它只到达getAllConfigAttributes方法,如我所说,该方法是空的,并返回空值。之后,它会打印此警告:
无法验证配置属性,因为SecurityMetadataSource没有从GetAllConfigAttributes()返回任何属性。
我的应用上下文-安全如下:
<beans:bean id="filterChainProxy"
class="org.springframework.security.web.FilterChainProxy">
<filter-chain-map path-type="ant">
<filter-chain filters="sif,filterSecurityInterceptor"
pattern="/**" />
</filter-chain-map>
</beans:bean>
<beans:bean id="filterSecurityInterceptor"
class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
<beans:property name="authenticationManager" ref="authenticationManager" />
<beans:property name="accessDecisionManager" ref="accessDecisionManager" />
<beans:property name="securityMetadataSource" ref="filterSecurityMetadataSource" />
</beans:bean>
<beans:bean id="filterSecurityMetadataSource"
class="com.mycompany.filter.FilterSecurityMetadataSource">
</beans:bean>
有什么问题?