天天看點

基于shibboleth的分布式認證之SP配置1:安裝apache 版本為2.2.X2:安裝Tomcat,本文中安裝的版本是apache-tomcat-6.0.33.zip3:配置apache代理tomcat:4:配置ssl5:配置apache的https代理6:安裝SP7:配置apache使用shibboleth SP子產品8:配置SP 發現服務(discovery service DS)9:配置SP信任IDP:10:SP接受IDP屬性配置11:java 程式如何同sp進行對接

本文為shibboleth SP配置文檔。其中涉及到apache整合反向代理tomcat的配置,SSL配置以及通路控制等。這不是本文的重點,是以,本文隻是表述了配置方式,如果要更改相應的配置或者進行其他個性化配置,參考相應的配置文檔。

對應的SP的配置,以及如何同DS,IDP建立shibboleth聯盟,則需要參照對應的SP和IDP,DS說明文檔。本文也是給出的最基本的配置。

1:安裝apache 版本為2.2.X

本文中使用的是httpd-2.2.21-win32-x86-openssl-0.9.8r.msi。提供預設的openSSL支援。

在位址欄中鍵入:http://localhost出現It works!字眼說明apache安裝成功。

2:安裝Tomcat,本文中安裝的版本是apache-tomcat-6.0.33.zip

不細表了。

3:配置apache代理tomcat:

在apache中的conf目錄中httpd.conf檔案中加入下面内容:

打開“proxy”相關子產品

ServerName 127.0.0.1

NameVirtualHost  *:80

Foundation/Apache2.2/htdocs/examples" 

<VirtualHost *:80>

ServerName sp1.dsideal.com:80

       <Directory"D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/examples"  >

              #AuthTypeBasic

              #AuthNamefirstPW

              #AuthUserFile"D:/Program Files/Apache Software Foundation/Apache2.2/bin/pwtest"

              #AllowOverride  None

              Requirevalid-user

              Orderdeny,allow

              allowfrom all

       </Directory>

       ProxyPass/examples/ ajp://127.0.0.1:8009/examples/

       ProxyPassReverse/examples/ ajp://127.0.0.1:8009/examples/

</VirtualHost>

注意打開tomcat相應端口.

Proxy 代理的路徑應該是放置在tomcat中工程的路徑。

具體代理配置參見《apache cookbook中文版》

浏覽器鍵入http://localhost/examples正常顯示(examples)為tomcat工程。

4:配置ssl

步驟一:安裝apache,使其支援SSL,并安裝php

    1.安裝配有SSL子產品的apache,apache_2.2.8-win32-x86-openssl-0.9.8g

    2.配置apache以支援SSL:打開apache的配置檔案conf/httpd.conf

        1)LoadModule ssl_modulemodules/mod_ssl.so

          Includeconf/extra/httpd-ssl.conf

          去掉兩行前面的#

       2)注意修改httpd-ssl.conf 檔案裡的兩個字段:

           SSLCertificateFile"C:/Apache2.2/conf/server.crt"

          SSLCertificateKeyFile "C:/Apache2.2/conf/server.key"s

步驟二:為網站伺服器生成證書及私鑰檔案

     1. 生成伺服器的私鑰

         進入指令行:

        D:\local\apache2\bin\openssl genrsa -out server.key 1024

         在目前目錄下生成了一個server.key生成簽署申請

     2. 生成簽署申請

        D:\local\apache2\bin>openssl req -new –out server.csr -key server.key-config ..\conf\openssl.cnf

         此時生成簽署檔案server.csr.

步驟三:通過CA為網站伺服器簽署證書    

      1.生成CA私鑰

        D:\local\apache2\bin\openssl genrsa  -out ca.key 1024

         多出ca.key檔案

       2.利用CA的私鑰産生CA的自簽署證書

        D:\local\apache2\bin\openssl req  -new -x509 -days 365 -key ca.key -outca.crt  -config ..\conf\openssl.cnf

         此時需要輸入一些資訊,注意Common Name為伺服器域名,如果在本機,為本機IP。

      3.CA為網站伺服器簽署證書

 D:\local\apache2\bin\openssl ca -in server.csr -outserver.crt -cert ca.crt -keyfile ca.key -config ..\conf\openssl.cnf

但,此時會報錯:

         于是在在目前目錄建立demoCA,裡面建立以下檔案,index.txt,内容為空,建立 serial檔案内容為01,其他為空,以及檔案夾newcerts.再執行一遍,即可生成server.crt檔案

步驟四:然後将  server.crt,server.key複制到apache的conf檔案夾下,重新開機apache

步驟五:通路https://localhost 出現正常的通路頁面,即支援https

不過由于,我們的CA不是由第三方機構頒發的,而是我們自己頒發的,是以,IE通路的時候,會顯示,這個證書不是由Trused CA Authenticator頒發,告訴我們可能有安全隐患

5:配置apache的https代理

在上一步的配置中,apache可以處理https請求。但是對應的請求無法轉發到tomcat中進行處理。

這需要在conf\extra 中的httpd-ssl.conf檔案中的<VirtualHost*:443>配置中加入ProxyPass /examples/ ajp://localhost:8080/examples

或者ProxyPass /examples/  ajp://localhost:9009/examples/

這樣通過https協定亦可以通路apache代理的tomcat的内容。

6:安裝SP

輕按兩下shibboleth-sp-2.5.1-win64.msi 這裡選擇安裝到G:/shibbolethTest/shibboleth-sp目錄下。

7:配置apache使用shibboleth SP子產品

在apache安裝目錄下/conf 編輯httd.conf檔案。在檔案的最後加入以下内容:

IncludeG:/shibbolethTest/shibboleth-sp/etc/shibboleth/apache22.config

這裡需要注意的是,在64位作業系統下,G:/shibbolethTest/shibboleth-sp/etc/shibboleth/apache22.config目錄下的檔案會加載相應的SP子產品。但是,在加載的過程中會出現問題。

這裡需要将該檔案中的以下内容進行更改:

LoadModule mod_shib D:/shibboleth/shibboleth-sp/lib/shibboleth/mod_shib_22.so

紅色标注的地方需要将由lib64更改為lib

8:配置SP 發現服務(discovery service DS)

假設SP安裝目錄是:D:\opt\shibboleth-sp\。修改該目錄下etc\shibboleth\下的shibboleth2.xml 檔案

如果該SP存在多個信任的IDP,則需要在該檔案中配置DS配置

<SSO discoveryProtocol="SAMLDS" sdiscoveryURL="http://ds.jiaoyuju.com/DS/WAYF">

               SAML2 SAML1

</SSO>

其中discoveryProtocal填寫的是DS協定。discoveryURL填寫的是DS位址。(詳細配置參見DS配置文檔)節點中間的SAML2,SAML1是配置同DS通訊的協定。在SP2以及以上版本中,普遍支援SAML2.是以按照SAML2,SAML1的順序進行配置。

如果SP隻信任一個IDP,則不需要發現服務。則隻配置

<SessionInitiator type="Chaining"Location="/Login" isDefault="true"id="Login"                      entityID="https://idp.example.org/shibboleth">

               <SessionInitiator type="SAML2"template="bindingTemplate.html"/>

               <SessionInitiator type="Shib1"/>

</SessionInitiator>

編輯shibboleth2.xml檔案。将identityID編輯成sp應用所在位址。

   <ApplicationDefaults entityID="http://10.10.8.28/shibboleth"

                         REMOTE_USER="eppnpersistent-id targeted-id">

9:配置SP信任IDP:

在shibboleth2.xml中配置

<MetadataProvider type="XML"uri="https://idp.dsideal.com/idp/shibboleth"backingFilePath="dsideal-idp-metadata.xml"reloadInterval="180000"/>

其中type為加載的資料類型,uri為idpmetadata位址。BackingFilePath為備份檔案存儲路徑;reloadInterval為重新加載配置檔案間隔。

重新開機shibboleth 和apache服務。如果在

G:\shibbolethTest\shibboleth-sp\var\cache\shibboleth目錄下看到相應的IDP metadata相關的xml檔案。則說明加載信任IDP中繼資料檔案沒有問題。

SP配置完畢

10:SP接受IDP屬性配置

通常,SP可以對IDP的屬性進行過濾的。該特性主要是通過shibboleth-sp\etc\shibboleth\attribute-policy.xml進行配置的。

這裡我們為了簡單起見,将所有的idp傳遞的屬性都設定成sp不過濾的模式。配置如下:

<afp:AttributeFilterPolicy>

        <!-- This policy is in effect in allcases. -->

        <afp:PolicyRequirementRulexsi:type="ANY"/>

        <afp:AttributeRuleattributeID="*">

            <afp:PermitValueRulexsi:type="ANY"/>

        </afp:AttributeRule>

    </afp:AttributeFilterPolicy>

</afp:AttributeFilterPolicyGroup>

配置了允許接受的屬性之後,就配置SP的屬性對IDP屬性的對應關系即可了。該特性在shibboleth-sp\etc\shibboleth\attribute-map.xml檔案中進行配置的。

<Attributename="urn:oid:2.5.4.43d" id="loginName" />

<Attributename="urn:oid:2.5.4.44" id="realName" />

這裡的name 屬性和idp中的屬性name是一緻的。Id就是可以通過特定接口獲得的屬性的名稱了。

11:java 程式如何同sp進行對接

Java程式對sp對接有多種方式,一種是在http的頭部加入參數,一種是在EnvironmentVariables中獲得使用者屬性,還有一種是通過remote_user獲得使用者屬性。

目前,官方推薦使用EnvironmentVariables ,因為其他的兩種方式都存在硬傷。使用http頭部主要是存在安全問題,在http頭部封裝使用者資訊想來都覺得夠可怕。

Remote_user 主要是不支援iis。這對于我們這樣一個要求全面支援相容性的機關,對于我們這樣一個追求完美的産品來說,也是不能忍的。是以,我們就直接使用官方推薦配置了。

String name3=request.getAttribute("loginName")+"";

String name4 =request.getAttribute("realName")+"";

這樣就可以擷取到使用者資訊了