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

  學習。

相關文章
相關標籤/搜索