Spring Security : 概念模型 SecurityMetadataSource

概述

介绍

SecurityMetadataSourceSpring 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方法。

继承关系

SecurityMetadataSource
Spring SecuritySecurityMetadataSource提供了两个子接口 :

  • 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);
}

参考文章

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值