單點登錄可以做到在不記錄用戶密碼的情況下,實現不同系統之間的資源共享,自動登錄不安全,單點登錄,一處登錄,處處都可用,不用做多餘的登錄操作。它是目前比較流行的企業業務整合的解決方案之一
環境描述:
Hyper-V6.3
操作系統:Centos6.5-x64
每臺虛機一塊公網網卡
IDP Server:192.168.2.230
SP Client:192.168.2.227
軟件包:
jdk-6u27-linux-x64.bin
apache-tomcat-6.0.32.tar.gz
ApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628.tar
tomcat6-dta-ssl-1.0.0.jar
shibboleth-identityprovider-2.4.2-bin
apacheds-1.5.7-x86_64.bin
Xmanager-5.0
軟件提供打包下載
http://pan.baidu.com/s/1o6MHxUE
本次實施過程參考文章(注:此文章僅參考,請不要完全按照這篇英文文章搭建,有幾個錯誤):
http://csrdu.org/blog/2011/07/04/shibboleth-idp-sp-installation-configuration/
注意:安裝配置過程中會添加修改很多的配置文件,複製黏貼本文內容時請注意格式問題,特別是shibboleth文件,推薦用vim編輯,便於區分各種變量、註釋。
具體實施
默認禁用掉selinux、iptables 規則清空保存重啓。操作系統安裝選擇Desktop 方便後面LDAP建立用戶,以及測試。
IDP Server端
1、 安裝jdk
[root@IDP2 tmp]# mkdir /usr/local/java
[root@IDP2 tmp]# mv/tmp/jdk-6u27-linux-x64.bin /usr/local/java/
[root@IDP2 tmp]# cd /usr/local/java/
[root@IDP2 java]# ll
total 83420
-rw-r--r-- 1 root root 85418489 Apr 2211:45 jdk-6u27-linux-x64.bin
[root@IDP2 java]# chmod +xjdk-6u27-linux-x64.bin
[root@IDP2 java]# ./jdk-6u27-linux-x64.bin
編輯 /etc/profile 設置相關的環境變量包括java tomcat idp-home 提前設置好在文件末尾加入以下:
exportJAVA_HOME=/usr/local/java/jdk1.6.0_27
exportJRE_HOME=/usr/local/java/jdk1.6.0_27/jre
exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
export CATALINA_HOME=/usr/local/tomcat6
export CATALINA_BASE=/usr/local/tomcat6
export IDP_HOME=/opt/shibboleth-idp
2、 安裝apache-tomcat-6.0.32.tar.gz
[root@IDP2 tmp]# tar -zxfapache-tomcat-6.0.32.tar.gz -C /usr/local/
[root@IDP2 tmp]# cd /usr/local/
[root@IDP2 local]# mv apache-tomcat-6.0.32/tomcat6/
[root@IDP2 local]# vim/usr/local/tomcat6/bin/catalina.sh
在文件JAVA_OPTS 處加入以下內容注意不要加在註釋裏面
JAVA_OPTS="-Djava.awt.headless=true-Xmx512M -XX:MaxPermSize=128M -Dcom.sun.security.enableCRLDP=true"
[root@IDP2 local]# vim/usr/local/tomcat6/conf/server.xml
找到這個webapps幾個屬性修改成以下值
<Host appBase="webapps" unpackWARs="true" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
[root@IDP2local]# /usr/local/tomcat6/bin/catalina.sh start
3、 安裝shibboleth IDP端
[root@IDP2 local]# cd /tmp/
[root@IDP2 tmp]# unzipshibboleth-identityprovider-2.4.2-bin.zip
[root@IDP2 tmp]# cdshibboleth-identityprovider-2.4.2
[root@IDP2 shibboleth-identityprovider-2.4.2]#chmod +x install.sh
[root@IDP2 shibboleth-identityprovider-2.4.2]#cp -r endorsed/ /usr/local/tomcat6
[root@IDP2 shibboleth-identityprovider-2.4.2]#export JAVA_ENDORSED_DIRS=/usr/local/tomcat6/endorsed
[root@IDP2 shibboleth-identityprovider-2.4.2]#vi ~/.bash_profile
文件末尾加入以下內容
IDP_HOME=/opt/shibboleth-idp
export IDP_HOME
[root@IDP2 shibboleth-identityprovider-2.4.2]#source /etc/profile
[root@IDP2 shibboleth-identityprovider-2.4.2]#./install.sh
安裝過程會提示安裝路徑默認即可
主機名輸入idp.csrdu.org,密碼123456,記住這個主機名和密碼,我們後面會用到。
[[email protected]]# ln -s /opt/shibboleth-idp/conf/etc/shibboleth
[[email protected]]# ln -s /opt/shibboleth-idp/logs/var/log/shibboleth
[root@IDP2~]# cd /tmp/
[root@IDP2tmp]# cp tomcat6-dta-ssl-1.0.0.jar /usr/local/tomcat6/lib/
[root@IDP2tmp]# vim /usr/local/tomcat6/conf/server.xml
加入以下內容不要加在註釋裏
<Connectorport="8443"
protocol="org.apache.coyote.http11.Http11Protocol"
SSLImplementation="edu.internet2.middleware.security.tomcat7.DelegateToApplicationJSSEImplementation"
scheme="https" SSLEnabled="true"clientAuth="true"
keystoreFile="/opt/shibboleth-idp/credentials/idp.jks"
keystorePass="123456"/>
此處密碼即是安裝時輸入的密碼
[root@IDP2 tmp]# vi/usr/local/tomcat6/conf/Catalina/localhost/idp.xml
創建並新建此路徑的idp.xml文件加入以下內容
<ContextdocBase="/opt/shibboleth-idp/war/idp.war"
privileged="true"antiResourceLocking="false"
antiJARLocking="false"unpackWAR="false"
swallowOutput="true"/>
# [root@IDP2 tmp]# vi /etc/hosts
127.0.0.1 idp.csrdu.org idp
[root@IDP2tmp]# /usr/local/tomcat6/bin/catalina.sh stop
[root@IDP2tmp]# /usr/local/tomcat6/bin/catalina.sh start
[root@IDP2tmp]# firefox http://idp.csrdu.org:8080/idp/profile/Status &
http://idp.csrdu.org:8080/idp/profile/Status顯示ok頁面則爲正常,若其他顯示包括404則需查看日誌。
4、創建證書文件
[root@IDP2 ~]# mkdir idpcerts/
[root@IDP2 ~]# keytool -genkey -aliastomcat -keyalg RSA -keystore ~/idpcerts/idpself.keystore
Enter keystore password:
Re-enter new password:
輸入密碼 123456 記住這個密碼其他選項請按照此設置。
[root@IDP2 ~]# vim/usr/local/tomcat6/conf/server.xml
加入以下內容不要加在註釋裏
<Connector port="443"protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150"scheme="https" secure="true" clientAuth="false"
sslProtocol="TLS"
keystoreFile="/root/idpcerts/idpself.keystore"
keystorePass="123456" />
密碼爲生成證書是輸入的密碼
[root@IDP2 ~]#/usr/local/tomcat6/bin/catalina.sh stop
[root@IDP2 ~]#/usr/local/tomcat6/bin/catalina.sh start
[root@IDP2 idpcerts]# firefoxhttps://idp.csrdu.org/idp/profile/Status &
顯示ok頁面則爲正常,若其他顯示包括404則需查看日誌。
[root@IDP2 idpcerts]# vim/opt/shibboleth-idp/conf/handler.xml
註釋掉以下內容
<!-- Login Handlers -->
<!--
<ph:LoginHandler xsi:type="ph:RemoteUser">
<ph:AuthenticationMethod>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified
</ph:AuthenticationMethod>
</ph:LoginHandler>
-->
對於這部分內容去掉註釋
<!-- Username/password login handler -->
<ph:LoginHandler xsi:type="ph:UsernamePassword"
jaasConfigurationLocation="file:///opt/shibboleth-idp/conf/login.config">
<ph:AuthenticationMethod>urn:oasis:names:tc:SAML:2.0:ac:classes:
PasswordProtectedTransport</ph:AuthenticationMethod>
</ph:LoginHandler>
6、安裝ApacheDirectoryStudio 這是ldap鏈接工具圖形化界面
[root@IDP2 tmp]# tar -zxfApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628.tar.gz
[root@IDP2 tmp]# cdApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628
[root@IDP2 tmp]# mvApacheDirectoryStudio-linux-x86_64-2.0.0.v20130628 /opt/apachedir
7、安裝Apacheds-1.5.7(注:參考文章這裏安裝的是1.5.2,這個版本有問題,在最後測試的時候即使輸入正確密碼也會出現crenditial is not recongised,驗證通不過)
[root@IDP2 tmp]# chmod +x apacheds-1.5.7-x86_64.bin
[root@IDP2 tmp]# ./apacheds-1.5.7-x86_64.
幾個選項默認回車即可
8、建立ldap賬戶
[root@IDP2 tmp]# /etc/init.d/apacheds-1.5.2-defaultstart
[root@IDP2 tmp]# cd /opt/apachedir/
[root@IDP2 apachedir]#./ApacheDirectoryStudio &
開始打開ldap管理平臺建立賬戶
a
b
c
d
選完直接FINISH即可
e
F
G
H
I
J
K
L
M
9、編輯login_config,shibboleth訪問ldap文件
[root@IDP2 apachedir]# vim/opt/shibboleth-idp/conf/login.config
去掉註釋編輯以下內容
ShibUserPassAuth {
edu.vt.middleware.ldap.jaas.LdapLoginModulerequired
host="ldap://localhost:10389"base="ou=users,ou=system"
ssl="false"userField="uid";
};
10、編輯attribute-resolver.xml
[root@IDP2 apachedir]# vim/opt/shibboleth-idp/conf/attribute-resolver.xml
添加以下內容,注意嵌套的標籤,不要複製錯位置
<resolver:AttributeDefinitionxsi:type="ad:Simple"xmlns="urn:mace:shibboleth:2.0:resolver:ad" id="commonName"sourceAttributeID="cn">
<resolver:Dependencyref="myLDAP" />
<resolver:AttributeEncoderxsi:type="enc:SAML1String"xmlns="urn:mace:shibboleth:2.0:attribute:encoder"name="urn:mace:dir:attribute-def:cn" />
<resolver:AttributeEncoderxsi:type="enc:SAML2String" xmlns="urn:mace:shibboleth:2.0:attribute:encoder"name="urn:oid:2.5.4.3" friendlyName="cn" />
</resolver:AttributeDefinition>
<resolver:AttributeDefinitionxsi:type="ad:Simple"xmlns="urn:mace:shibboleth:2.0:resolver:ad" id="surname"sourceAttributeID="sn">
<resolver:Dependencyref="myLDAP" />
<resolver:AttributeEncoderxsi:type="enc:SAML1String"
xmlns="urn:mace:shibboleth:2.0:attribute:encoder"name="urn:mace:dir:attribute-def:sn" />
<resolver:AttributeEncoderxsi:type="enc:SAML2String"
xmlns="urn:mace:shibboleth:2.0:attribute:encoder"name="urn:oid:2.5.4.4"
friendlyName="sn" />
</resolver:AttributeDefinition>
文件的末尾位置找到以下內容去掉註釋並編輯
<resolver:DataConnectorxsi:type="dc:LDAPDirectory" id="myLDAP"
ldapURL="ldap://localhost:10389"
baseDN="ou=users,ou=system" principal="uid=admin,ou=system"
principalCredential="secret">
<dc:FilterTemplate>
<![CDATA[(uid=$requestContext.principalName) ]]>
</dc:FilterTemplate>
</resolver:DataConnector>
11、編輯 attribute-filter.xml 文件
添加以下內容,注意嵌套的標籤,不要複製錯位置
<afp:AttributeRule attributeID="commonName">
<afp:PermitValueRulexsi:type="basic:ANY" />
</afp:AttributeRule>
<afp:AttributeRuleattributeID="surname">
<afp:PermitValueRulexsi:type="basic:ANY" />
</afp:AttributeRule>
IDP端暫時0k
記得把IDP的hosts文件拷給sp,使用scp命令或者sftp都可以
SP端:
1、編輯Centos-Base.repo添加以下內容:
[security_shibboleth]
name=Shibboleth (CentOS_6)
type=rpm-md
baseurl=http://download.opensuse.org/repositories/security:/shibboleth/CentOS_CentOS-6/
gpgcheck=1
gpgkey=http://download.opensuse.org/repositories/security:/shibboleth/CentOS_CentOS-6/repodata/repomd.xml.key
enabled=1
[root@SPclient yum.repos.d]# yum installshibboleth mod_ssl openssl -y
[root@SPclient yum.repos.d]# vim/etc/httpd/conf/httpd.conf
修改Servername 爲sp.csrdu.org UseCanonicalName改爲on
[root@SPclient yum.repos.d]# service httpdstart
[root@SPclient yum.repos.d]#/etc/init.d/shibd start
[root@SPclient yum.repos.d]# openssl genrsa-out ca.key 1024
[root@SPclient yum.repos.d]# openssl genrsa-out ca.key 1024
[root@SPclient yum.repos.d]# openssl req-new -x509 -days 3650 -key ca.key -out ca.crt
[root@SPclient yum.repos.d]# cp ca.crt/etc/pki/tls/certs/
[root@SPclient yum.repos.d]# cp ca.key/etc/pki/tls/private/
[root@SPclient yum.repos.d]# vi/etc/httpd/conf.d/ssl.conf
編輯SSLCertificateFile 和 SSLCertificateKeyFile文件位置爲新的文件
IDP需要SP 端sp-metadata.xml作爲認證識別文件,同樣sp端需要IDP端idp-metadata.xml作爲認證識別文件,這裏我們用作者提供的sp-metadata.xml傳送給IDP端;同時,把IDP端的idp-metadata.xml拷給SP端,這裏需要編輯sp-metadata.xml文件,將SP端/etc/shibboleth/下的sp-cert.pem密鑰內容替換掉sp-metadata.xml同時還需修改以下幾個地方,
IDP端的sp-metadata.xml位置
SP端的idp-metadata.xml位置
編輯IDP端
[root@IDP2 apachedir]# vim/etc/shibboleth/relying-party.xml
在如下位置添加以下內容
<!-- Load the SP's metadata. -->
<metadata:MetadataProviderxsi:type="FilesystemMetadataProvider"xmlns="urn:mace:shibboleth:2.0:metadata" id="SPMETADATA"metadataFile="/opt/shibboleth-idp/metadata/sp-metadata.xml" />
編輯SP端
[root@SPclient yum.repos.d]# vim/etc/shibboleth/shibboleth2.xml
在如下位置添加修改以下內容,注意不要複製到註釋裏
<RequestMapper type="Native">
<RequestMapapplicationId="default">
<Hostname="sp.csrdu.org">
<Pathname="secure" authType="shibboleth"requireSession="true"/>
</Host>
</RequestMap>
</RequestMapper>
Vim 看行數用:set nu 儘量不要換行
[root@SPclient yum.repos.d]# vim/etc/shibboleth/attribute-map.xml
在如下位置去掉註釋
[root@SPclientsecure]# vim /etc/httpd/conf.d/shib.conf
在文件末尾刪掉默認的<Location /secure></Location>
添加以下內容
<Location/secure>
AuthTypeshibboleth
ShibRequireSessionOn
requirevalid-user
</Location>
<Location/unsecure>
AuthTypeshibboleth
ShibRequireSessionOff
require shibboleth
</Location>
重啓一下相關服務
[root@SPclient yum.repos.d]# /etc/init.d/shibd stop
[[email protected]]# service httpd stop
[[email protected]]# service httpd start
[[email protected]]# /etc/init.d/shibd start
測試
建立保護目錄及保護文件、忽略保護目錄及文件
[[email protected]]# mkdir /var/www/html/secure
[[email protected]]#vim /var/www/html/secure/222.html
[[email protected]]# mkdir /var/www/html/unsecure
[[email protected]]#vim /var/www/html/unsecure/111.html
我們在SP端訪問保護目錄
[root@SPclientshibboleth]# firefox https://sp.csrdu.org/secure &
頁面直接跳轉到IDP服務器
輸入我們建立的zhaoliu 及密碼 123456就可以訪問了
關掉瀏覽器再測試忽略保護目錄
Ok 我們可以不用輸入用戶名密碼直接訪問到。
注:兩臺服務器時間需要同步,手動改或ntpstat都可以