美文网首页
Security Interceptor

Security Interceptor

作者: 18ea3d01d97b | 来源:发表于2017-11-08 21:24 被阅读0次

    DelegatingFilterProxy:

    它将过滤器的方法委派到从applicationContext中获取到的benn上,这个bean必须实现javax.servlet.Filter接口,而且该filter的name必须和filtername元素中的一样。

    核心过滤器:

    FilterSecurityInterceptor:该过滤器负责处理HTTP资源的安全,它需要持有AuthenticationManager和AccessDecisionManager的引用,也可以配置不同的 HTTP URL 的资源。

    <bean id="filterSecurityInterceptor"
    class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
    <property name="authenticationManager" ref="authenticationManager"/>
    <property name="accessDecisionManager" ref="accessDecisionManager"/>
    <property name="securityMetadataSource">
    <security:filter-security-metadata-source>
    <security:intercept-url pattern="/secure/super/**" access="ROLE_WE_DONT_HAVE"/>
    <security:intercept-url pattern="/secure/**" access="ROLE_SUPERVISOR,ROLE_TELLER"/>
    </security:filter-security-metadata-source>
    </property>
    </bean>
    

    ExceptionTranslationFilter
    springsecurity中最核心的组件之一就是Interceptor,主要是 AbstractSecurityInterceptor和两个具体的实现FilterSecurityInterceptor,MethodSecurityInterceptor。拦截器的作用主要是决定一个请求是否被允许访问一个受保护的资源。FilterSecurityInterceptor主要处理web url的请求,而MethodSecurityInterceptor主要处理方法的请求。
    Interceptor 工作原理:
    Interceptor 主要有一个前置处理和一个后置处理过程,在前置处理阶段,它会看看要访问的资源是不是被保护的,如果不是的话,请求就可以继续。如果是的话,拦截器就会从SecurityContext里面获取Authentication对象,如果用户是被认证通过, AccessDecisionManager将会被调用来决定这个被认证的对象能不能访问资源。
    当这个用户权限不够时(不能访问资源),就会抛出AccessDeniedException异常。当能够访问时, Authentication对象将会被传递给RunAsManager(该对象配置了)。下面是一个简单的时序图:


    学习.png

    相关文章

      网友评论

          本文标题:Security Interceptor

          本文链接:https://www.haomeiwen.com/subject/hbqumxtx.html