天天看点

基于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")+"";

这样就可以获取到用户信息了