1. 程式人生 > >Spring Security 4.0 CAS實現單點登入

Spring Security 4.0 CAS實現單點登入

1、各framework版本資訊 
     JDK 8 
     Tomcat 7 
     SpringMVC-4.2.0.RELEASE 
     Spring Security 4.2.0.RELEASE 
     CAS-Client 3.3.3 
     CAS-Server 4.0.0 

2、MAVEN的pom.xml 
    Java程式碼  收藏程式碼
  1. <!--Spring -->  
  2.     <dependency>  
  3.         <groupId>org.springframework</groupId>  
  4.         <artifactId>spring-core</artifactId>  
  5.         <version>${spring.version}</version>  
  6.     </dependency>  
  7.     <dependency>  
  8.         <groupId>org.springframework</groupId>  
  9.         <artifactId>spring-beans</artifactId>  
  10.         <version>${spring.version}</version>  
  11.     </dependency>  
  12.     <dependency>  
  13.         <groupId>org.springframework</groupId>  
  14.         <artifactId>spring-context</artifactId>  
  15.         <version>${spring.version}</version>  
  16.     </dependency>  
  17.     <dependency>  
  18.         <groupId>org.springframework</groupId>  
  19.         <artifactId>spring-context-support</artifactId>  
  20.         <version>${spring.version}</version>  
  21.     </dependency>  
  22.     <dependency>  
  23.         <groupId>org.springframework</groupId>  
  24.         <artifactId>spring-aop</artifactId>  
  25.         <version>${spring.version}</version>  
  26.     </dependency>  
  27.     <dependency>  
  28.         <groupId>org.springframework</groupId>  
  29.         <artifactId>spring-aspects</artifactId>  
  30.         <version>${spring.version}</version>  
  31.     </dependency>  
  32.     <dependency>  
  33.         <groupId>org.springframework</groupId>  
  34.         <artifactId>spring-tx</artifactId>  
  35.         <version>${spring.version}</version>  
  36.     </dependency>  
  37.     <dependency>  
  38.         <groupId>org.springframework</groupId>  
  39.         <artifactId>spring-orm</artifactId>  
  40.         <version>${spring.version}</version>  
  41.     </dependency>  
  42.     <dependency>  
  43.         <groupId>org.springframework</groupId>  
  44.         <artifactId>spring-expression</artifactId>  
  45.         <version>${spring.version}</version>  
  46.     </dependency>  
  47.     <dependency>  
  48.         <groupId>org.springframework</groupId>  
  49.         <artifactId>spring-instrument</artifactId>  
  50.         <version>${spring.version}</version>  
  51.     </dependency>  
  52.     <dependency>  
  53.         <groupId>org.springframework</groupId>  
  54.         <artifactId>spring-instrument-tomcat</artifactId>  
  55.         <version>${spring.version}</version>  
  56.     </dependency>  
  57.     <dependency>  
  58.         <groupId>org.springframework</groupId>  
  59.         <artifactId>spring-jdbc</artifactId>  
  60.         <version>${spring.version}</version>  
  61.     </dependency>  
  62.     <dependency>  
  63.         <groupId>org.springframework</groupId>  
  64.         <artifactId>spring-web</artifactId>  
  65.         <version>${spring.version}</version>  
  66.     </dependency>  
  67.     <dependency>  
  68.         <groupId>org.springframework</groupId>  
  69.         <artifactId>spring-webmvc</artifactId>  
  70.         <version>${spring.version}</version>  
  71.     </dependency>  
  72.     <dependency>  
  73.         <groupId>org.springframework</groupId>  
  74.         <artifactId>spring-webmvc-portlet</artifactId>  
  75.         <version>${spring.version}</version>  
  76.     </dependency>  
  77.     <dependency>  
  78.         <groupId>org.springframework.security</groupId>  
  79.         <artifactId>spring-security-web</artifactId>  
  80.         <version>${spring.security.version}</version>  
  81.     </dependency>  
  82.     <dependency>  
  83.         <groupId>org.springframework.security</groupId>  
  84.         <artifactId>spring-security-config</artifactId>  
  85.         <version>${spring.security.version}</version>  
  86.     </dependency>  
  87.     <dependency>  
  88.         <groupId>org.springframework.security</groupId>  
  89.         <artifactId>spring-security-cas</artifactId>  
  90.         <version>${spring.security.version}</version>  
  91.     </dependency>  
  92.     <dependency>  
  93.         <groupId>org.jasig.cas.client</groupId>  
  94.         <artifactId>cas-client-core</artifactId>  
  95.         <version>3.3.3</version>  
  96.         <!-- 排除log4j包衝突 -->  
  97.         <exclusions>  
  98.             <exclusion>  
  99.                 <groupId>org.slf4j</groupId>  
  100.                 <artifactId>log4j-over-slf4j</artifactId>  
  101.             </exclusion>  
  102.         </exclusions>  
  103.     </dependency>  

影音先鋒電影http://www.iskdy.com/ 
3、配置CAS-Server 
     1)、下載CAS-Server的Zip包[http://developer.jasig.org/cas/] 
              解壓後將modules資料夾中的[cas-server-webapp-4.0.0.war]放到tomcat的webapps資料夾中、重新命名為cas.war。 
              啟動tomcat、解壓war包、瀏覽器中輸入[http://localhost:8080/cas/] 
              開啟CAS-Server的登入畫面、輸入預設使用者名稱/密碼:[casuser/Mellon]、提示[login success]即登入成功。 
     2)、修改CAS-Server配置檔案、支援資料庫登入校驗 
              開啟[../tomcat/webapps/cas/WEB-INF/deployerConfigContext.xml]檔案 
     完成的配置檔案 
     Java程式碼  收藏程式碼
  1.      <?xml version="1.0" encoding="UTF-8"?>  
  2. <!--  
  3.     Licensed to Jasig under one or more contributor license  
  4.     agreements. See the NOTICE file distributed with this work  
  5.     for additional information regarding copyright ownership.  
  6.     Jasig licenses this file to you under the Apache License,  
  7.     Version 2.0 (the "License"); you may not use this file  
  8.     except in compliance with the License.  You may obtain a  
  9.     copy of the License at the following location:  
  10.       http://www.apache.org/licenses/LICENSE-2.0  
  11.     Unless required by applicable law or agreed to in writing,  
  12.     software distributed under the License is distributed on an  
  13.     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY  
  14.     KIND, either express or implied.  See the License for the  
  15.     specific language governing permissions and limitations  
  16.     under the License.  
  17. -->  
  18. <!--  
  19. | deployerConfigContext.xml centralizes into one file some of the declarative configuration that  
  20. | all CAS deployers will need to modify.  
  21. |  
  22. | This file declares some of the Spring-managed JavaBeans that make up a CAS deployment.    
  23. | The beans declared in this file are instantiated at context initialization time by the Spring   
  24. | ContextLoaderListener declared in web.xml.  It finds this file because this  
  25. | file is among those declared in the context parameter "contextConfigLocation".  
  26. |  
  27. | By far the most common change you will need to make in this file is to change the last bean  
  28. | declaration to replace the default authentication handler with  
  29. | one implementing your approach for authenticating usernames and passwords.  
  30. +-->  
  31. <beans xmlns="http://www.springframework.org/schema/beans"  
  32.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  33.        xmlns:p="http://www.springframework.org/schema/p"  
  34.        xmlns:c="http://www.springframework.org/schema/c"  
  35.        xmlns:tx="http://www.springframework.org/schema/tx"  
  36.        xmlns:util="http://www.springframework.org/schema/util"  
  37.        xmlns:sec="http://www.springframework.org/schema/security"  
  38.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  
  39.        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd  
  40.        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd  
  41.        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">  
  42.     <!--  
  43.        | The authentication manager defines security policy for authentication by specifying at a minimum  
  44.        | the authentication handlers that will be used to authenticate credential. While the AuthenticationManager  
  45.        | interface supports plugging in another implementation, the default PolicyBasedAuthenticationManager should  
  46.        | be sufficient in most cases.  
  47.        +-->  
  48.     <bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager">  
  49.         <constructor-arg>  
  50.             <map>  
  51.                 <!--  
  52.                    | IMPORTANT  
  53.                    | Every handler requires a unique name.  
  54.                    | If more than one instance of the same handler class is configured, you must explicitly  
  55.                    | set its name to something other than its default name (typically the simple class name).  
  56.                    -->  
  57.                 <entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />  
  58.                 <!-- <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />-->  
  59.                 <entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver"/>  
  60.             </map>  
  61.         </constructor-arg>  
  62.         <!-- Uncomment the metadata populator to allow clearpass to capture and cache the password  
  63.              This switch effectively will turn on clearpass.  
  64.         <property name="authenticationMetaDataPopulators">  
  65.            <util:list>  
  66.               <bean class="org.jasig.cas.extension.clearpass.CacheCredentialsMetaDataPopulator"  
  67.                     c:credentialCache-ref="encryptedMap" />  
  68.            </util:list>  
  69.         </property>  
  70.         -->  
  71.         <!--  
  72.            | Defines the security policy around authentication. Some alternative policies that ship with CAS:  
  73.            |  
  74.            | * NotPreventedAuthenticationPolicy - all credential must either pass or fail authentication  
  75.            | * AllAuthenticationPolicy - all presented credential must be authenticated successfully  
  76.            | * RequiredHandlerAuthenticationPolicy - specifies a handler that must authenticate its credential to pass  
  77.            -->  
  78.         <property name="authenticationPolicy">  
  79.             <bean class="org.jasig.cas.authentication.AnyAuthenticationPolicy" />  
  80. 相關推薦

    Spring Security 4.0 CAS實現登入

    1、各framework版本資訊       JDK 8       Tomcat 7       SpringMVC-4.2.0.RELEASE       Spring Security 4.2.0.RELEASE       CAS-Client 3.3.3       CAS-Serv

    Spring Security原始碼分析十二:Spring Security OAuth2基於JWT實現登入

    單點登入(英語:Single sign-on,縮寫為 SSO),又譯為單一簽入,一種對於許多相互關連,但是又是各自獨立的軟體系統,提供訪問控制的屬性。當擁有這項屬性時,當用戶登入時,就可以獲取所有

    spring security整合cas實現登入

    spring security整合cas 0.配置本地ssl連線 操作記錄如下: =====================1.建立證書檔案thekeystore ,並匯出為thekeystore.crt cd C:\Users\23570\keystore C:\Users\23570\keystore&

    CAS實現登入(SSO)

    什麼是單點登入 單點登入(Single Sign On),簡稱為 SSO,是目前比較流行的企業業務整合的解決方案之一。SSO的定義是在多個應用系統中,使用者只需要登入一次就可以訪問所有相互信任的應用系統。 我們目前的系統存在諸多子系統,而這些子系統是分別部署在不

    CAS實現登入SSO執行原理探究(終於明白了)

    一、不落俗套的開始 1、背景介紹 單點登入:Single Sign On,簡稱SSO,SSO使得在多個應用系統中,使用者只需要登入一次就可以訪問所有相互信任的應用系統。 CAS框架:CAS(Central Authentication Service)是實現S

    CAS實現登入(sso)搭建流程 伺服器端搭建

    一、簡介 1、cas是有耶魯大學研發的單點登入伺服器 2、所用環境 ·        Linux系統 ·        To

    cas實現登入-應用場景和完整配置

    Cas 簡介 1、什麼是CAS CAS是一個單點登入(SSO)的框架。單點登入是目前比較流行的服務於企業業務整合的解決方案之一,SSO使得在多個應用系統中,使用者只需要登入一次就可以訪問所有相互信任的應用系統。 2、CAS的主要結構 CAS包括兩部分:

    CAS 實現登入oos(2)

      前面已經介紹了CAS伺服器的搭建,詳情見:搭建CAS單點登入伺服器。然而前面只是簡單地介紹了伺服器的搭建,其驗證方式是原始的配置檔案的方式,這顯然不能滿足日常的需求。下面介紹下通過mysql資料庫認證的方式。   一、CAS認證之mysql資料庫認證   1、在mysql中新建一個cas資料庫並建立us

    Spring Session+Redis零侵入實現登入

    Spring Session 實現單點登入 此種方式相對於上節所說使用原生(Jedis+Jackson+Cookie+Filter)的方式實現起來更加簡便,同時對業務程式碼的侵入性也十分之小,其原理與原生方式類似,並通過對HttpServletRequest和HttpSer

    基於CAS實現登入(SSO):CAS+LDAP實現登入認證

    [一]、概述 CAS是N個系統的中心認證入口,而貫穿多個系統的使用者資訊是共用的,應該被單獨維護,而這些資訊可能屬於不用的系統,不用的組織,不用的國家,從而形成了樹形結構,而使用關係型資料庫維護樹形結構資訊是它的弱點,這就是本文CAS和LDAP整合的初衷。 本來主要

    Shiro & CAS 實現登入

    概覽 單點登入主要用於多系統整合,即在多個系統中,使用者只需要到一箇中央伺服器登入一次即可訪問這些系統中的任何一個,無須多次登入。 部署伺服器 Tomcat預設沒有開啟HTTPS協議,所以這裡直接用了HTTP協議訪問。為了能使客戶端在HTTP協議下單點登入成

    CAS實現登入的時序圖

    CAS單點登入時序圖: PS:該圖為自己根據CAS驗證過程及真例項子總結出來的時序圖,其中步驟8和步驟9未證實,如果有不對的地方歡迎指正。 猜想: 一直用HttpWatch觀察後臺html請求狀態,所以步驟8和9只能看到一次從cas server的重定向,始終找不到步驟8

    CAS實現登入(二):自定義的使用者驗證登入

    上一篇演示單點登入服務端認證機制採用的是cas server預設的使用者名稱和密碼(admin/admin)。今天介紹正常專案中如何通過驗證DB中的使用者資料,來驗證使用者的密碼的合法性 自定義驗證登入有兩種方式: 採用cas-server預設的資料庫查詢

    使用Spring Security OAuth2進行簡單的登入

    1.概述 在本教程中,我們將討論如何使用Spring Security OAuth和Spring Boot實現SSO - 單點登入。 我們將使用三個單獨的應用程式: 授權伺服器 - 這是中央身份驗證機制 兩個客戶端應用程式:使用SSO的應用程式 非常簡單地說,當用戶試圖訪問客戶端應用程式中的安全頁面時,他

    Spring Security基於Oauth2的SSO登入怎樣做?一個註解搞定

    ![mark](https://img2018.cnblogs.com/blog/1769816/202003/1769816-20200302103628233-400360122.png) ## 一、說明 單點登入顧名思義就是在多個應用系統中,只需要登入一次,就可以訪問其他相互信任的應用系統,免除多次登入

    spring boot 1.5.4 整合shiro+cas實現登入和許可權控制

    1.安裝cas-server-3.5.2 官網:https://github.com/apereo/cas/releases/tag/v3.5.2 注意: 輸入 <tomcat_key> 的金鑰口令 (如果和金鑰庫口令相同, 按回車) ,這裡直接回車,也採用keystore密碼changei

    spring boot中spring security實現登入,傳統模式(一)

    單點登入是什麼? 一個系統中可能會引用別的很多系統。單點登入就是解決,一次登入,就可以訪問所有的系統。 每次瀏覽器向一個域名傳送http請求,會去查詢域名的cookie資訊拼接到http的header中傳送到伺服器。 cookie不能跨域。這個域是瀏覽器請求的域名,哪怕他們都是訪問一

    cas+tomcat+shiro實現登入-4-Apache Shiro 整合Cas作為cas client端實現

    目錄 4.Apache Shiro 整合Cas作為cas client端實現 Apache Shiro 整合Cas作為cas client端實現 第一步、新增maven依賴      <!-- shiro依賴包 -->

    cas shiro spring實現登入

    這裡貼出傳送門,來自幕課網大神。講了cas配置和cas的基本原理。 CAS deployerConfigContext.xml配置檔案 預設通過配置檔案管理授權登入賬戶 <bean id="primaryAuthentication

    基於spring-security-oauth2實現登入(持續更新)

    ##基於spring-security-實現資料庫版## 文章程式碼地址:[連結描述][1]可以下載直接執行,基於springb