zoukankan      html  css  js  c++  java
  • springsecurity 源码解读之 AnonymousAuthenticationFilter

    我们知道springsecutity 是通过一系列的 过滤器实现的,我们可以看看这系列的过滤器到底长成什么样子呢?

    一堆过滤器,这个过滤器的设计设计上是 责任链设计模式。

    这里我们可以看到有一个 AnonymousAuthenticationFilter 过滤器。

    顾名思义我们知道这个是一个叫 匿名登录人过滤器,他的作用是什么呢?

    我们看看代码 ,他做了什么?

    if (applyAnonymousForThisRequest((HttpServletRequest) req)) {
                if (SecurityContextHolder.getContext().getAuthentication() == null) {
                    SecurityContextHolder.getContext().setAuthentication(createAuthentication((HttpServletRequest) req));
    
                    if (logger.isDebugEnabled()) {
                        logger.debug("Populated SecurityContextHolder with anonymous token: '"
                            + SecurityContextHolder.getContext().getAuthentication() + "'");
                    }
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("SecurityContextHolder not populated with anonymous token, as it already contained: '"
                            + SecurityContextHolder.getContext().getAuthentication() + "'");
                    }
                }
            }

    很简单,当他发现没有登录的时候,手工设置了一个匿名的登录人Authentication。

    我们可以在其后的过滤器中,如果没有登录时,我们可以知道当前访问的是匿名用户。

    我们可以通过如下代码获取当前人是匿名用户。

    Authentication auth= SecurityContextHolder.getContext().getAuthentication();
    if (auth==null || "anonymousUser".equals(auth.getPrincipal().toString())) {
  • 相关阅读:
    62. Unique Paths
    120. Triangle
    EBS预置文件作用收集整理
    ORA-20002: [WF_NO_USER] NAME=<name> ORIG_SYSTEM=NULL ORIG_SYSTEM_ID=NULL
    Oracle定义DES加密解密及MD5加密函数
    EBS获取附件URL
    Oracle EBS标准错误信息如何追踪 (Debug)
    更改EBS APPS 密码流程
    Oracle之物化视图
    Oracle EBS打补丁
  • 原文地址:https://www.cnblogs.com/yg_zhang/p/10652245.html
Copyright © 2011-2022 走看看