cas-server源代码学习(一)

      最近有点闲的慌,有好几个月没有写代码了。有时候实现业务的方式都是一根筋,根据本身想要实现的方式来写,也不知道外面的世界有多精彩,从此单位可能会用到sso功能,因此找来了一个sso的源代码来看看。nginx

     下载了cas-server和cas-client的代码,来学习学习。web

     我从cas-server的web.xml着手开始,之前使用spring的时候确实不在乎不少细节,今天看了看源码,感觉仍是很深!spring

     其中一个细节:安全

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
负载均衡

    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
学习

    之前都没有这么用过,看了下源代码:this

       protected Filter initDelegate(WebApplicationContext wac) throws ServletException {
        Filter delegate = wac.getBean(getTargetBeanName(), Filter.class);
        if (isTargetFilterLifecycle()) {
            delegate.init(getFilterConfig());
        }
        return delegate;
    }
   
spa

    这个逻辑实际上就是根据servlet-name来从spring-bean中去查找对应的filter,这里是包含了字符串和安全过滤器。这个挺有意思,不过比较基础,没什么好讲的。server

    而后看到了一个 xml

  ClientInfoThreadLocalFilter

   

try {
            final ClientInfo clientInfo;

            if (otherHeader == null || otherHeader.isEmpty()) {
                clientInfo = new ClientInfo((HttpServletRequest) request);
            } else {
                clientInfo = new ClientInfo((HttpServletRequest) request, this.otherHeader);
            }
            ClientInfoHolder.setClientInfo(clientInfo);
            filterChain.doFilter(request, response);
        } finally {
            ClientInfoHolder.clear();
        }

  这个东西主要封装了一下客户端和服务端IP信息,其中有个 alternateLocation 是能够配置在作nginx负载均衡的时候,丢失IP地址的问题,在转发的时候只要在nginx转发头中设置进去,而后在这里配置这个参数,便可获取客户端真正的IP地址。

  学习。

相关文章
相关标签/搜索