cas-server源代码学习(一)

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

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

     我从cas-server的web.xml着手开始,以前使用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>

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

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

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

    然后看到了一个 

  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地址。

  学习。

转载于:https://my.oschina.net/u/2461727/blog/686874

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值