概述
介绍
SecurityMetadataSource是Spring Security的一个概念模型接口。用于表示对受权限保护的"安全对象"的权限设置信息。一个该类对象可以被理解成一个映射表,映射表中的每一项包含如下信息 :
- 安全对象
- 安全对象所需权限信息
围绕该映射表,SecurityMetadataSource 定义了如下方法 :
Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException;
获取某个受保护的安全对象
object的所需要的权限信息,是一组ConfigAttribute对象的集合,如果该安全对象object不被当前SecurityMetadataSource对象支持,则抛出异常IllegalArgumentException。
该方法通常配合boolean supports(Class<?> clazz)一起使用,先使用boolean supports(Class<?> clazz)确保安全对象能被当前SecurityMetadataSource支持,然后再调用该方法。
Collection<ConfigAttribute> getAllConfigAttributes()
获取该
SecurityMetadataSource对象中保存的针对所有安全对象的权限信息的集合。该方法的主要目的是被AbstractSecurityInterceptor用于启动时校验每个ConfigAttribute对象。
boolean supports(Class<?> clazz)
这里
clazz表示安全对象的类型,该方法用于告知调用者当前SecurityMetadataSource是否支持此类安全对象,只有支持的时候,才能对这类安全对象调用getAttributes方法。
继承关系

Spring Security对SecurityMetadataSource提供了两个子接口 :
MethodSecurityMetadataSource由
Spring Security Core定义,用于表示安全对象是方法调用(MethodInvocation)的安全元数据源。FilterInvocationSecurityMetadataSource由
Spring Security Web定义,用于表示安全对象是Web请求(FilterInvocation)的安全元数据源。
源代码
源代码版本 Spring Security Core 5.1.4.RELEASE
package org.springframework.security.access;
import java.util.Collection;
import org.springframework.aop.framework.AopInfrastructureBean;
import org.springframework.security.access.intercept.AbstractSecurityInterceptor;
public interface SecurityMetadataSource extends AopInfrastructureBean {
/**
* Accesses the ConfigAttributes that apply to a given secure object.
*
* @param object the object being secured
*
* @return the attributes that apply to the passed in secured object. Should return an
* empty collection if there are no applicable attributes.
*
* @throws IllegalArgumentException if the passed object is not of a type supported by
* the SecurityMetadataSource implementation
*/
Collection<ConfigAttribute> getAttributes(Object object)
throws IllegalArgumentException;
/**
* If available, returns all of the ConfigAttributes defined by the
* implementing class.
*
* This is used by the AbstractSecurityInterceptor to perform startup time
* validation of each ConfigAttribute configured against it.
*
* @return the ConfigAttributes or null if unsupported
*/
Collection<ConfigAttribute> getAllConfigAttributes();
/**
* Indicates whether the SecurityMetadataSource implementation is able to
* provide ConfigAttributes for the indicated secure object type.
*
* @param clazz the class that is being queried
*
* @return true if the implementation can process the indicated class
*/
boolean supports(Class<?> clazz);
}
博客介绍了Spring Security中一个概念模型接口,用于表示对受权限保护的“安全对象”的权限设置信息,可理解为映射表。围绕该映射表定义了相关方法,还介绍了其两个子接口,同时给出了源代码版本及参考文章。
3091

被折叠的 条评论
为什么被折叠?



