主题
企业架构
使用 WebLogic Server9.2 中的 SAML 配置单点登录
页面: 1, 2, 3, 4, 5
在开始SAML配置之前,前几个步骤将创建并设置示例应用程序 appA和 appB的服务器环境。
本指南中的示例应用程序位于本地主机上的两个不同的域;因此,第一个步骤是创建运行于特定端口的域和服务器,如表1所示。
| 主机 | 应用服务器 | 应用程序名称 | 端口 | SSL端口 | |
|---|---|---|---|---|---|
| SAML源站点域:domainA | localhost | AdminServer | appA | 7001 | 7002 |
| SAML目标站点域 D:domainB | localhost | AdminServer | appB | 7003 | 7004 |
表 1. 示例应用程序域及应用服务器
使用Domain Configuration Wizard创建表1中所示的域;并使用WebLogic Server 9.2 Administration Console更新相应的侦听端口。
为了简便起见,本指南使用各域中的默认安全域,并以同样的默认域名进行命名,即 myrealm。在每个域的 myrealm域中分别创建一个用户 ssouser。此外,也可在集中化的外部LDAP存储中创建该用户,并将这两个域配置为使用这个共同的存储进行身份验证。
此处创建的用户 ssouser将验证 domainA中的应用程序 appA;然后,使用SSO便可直接访问位于 domainB中的应用程序 appB。
| 域 | 用户名/密码 | |
|---|---|---|
| SAML源站点域:domainA | myrealm | ssouser/demosaml |
| SAML目标站点域:domainB | myrealm | ssouser/demosaml |
表 2. 参与单点登录的用户
如表2所示,在这两个域中名为 myrealm的安全域内创建用户 ssouser。
appA的示例应用程序源代码可以在下载区进行下载。将现有的Web应用程序导入到WebLogic WorkShop Studio或者诸如Eclipse的其他任何IDE。
应用程序 appA配置为使用基于FORM的身份验证。该应用程序部署在SAML源站点域(即 domainA)。admin文件夹下名为auth.jsp的 appA JSP页面要求已通过身份验证的用户拥有admin角色,才能进行访问。在weblogic.xml中,admin角色映射到名为ssouser的主体。图2显示了web.xml中的安全配置。
<display-name>Saml Source Site Application</display-name>
<security-constraint>
<web-resource-collection>
<web-resource-name>SecurePages</web-resource-name>
<description>These pages are only accessible by authorized users.</description>
<url-pattern>/admin/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<description>These are the roles who have access.</description>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
<description>This is how the user data must be transmitted.</description>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>myrealm</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/fail_login.htm</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>These are the roles who have access</description>
<role-name>admin</role-name>
</security-role>
例 1. 应用程序 appA - web.xml代码片断
当用户试图访问/admin/auth.jsp页面时,将显示配置好的login.jsp登录页面,要求用户提供身份验证凭据。在提交详细资料后,该容器将对用户ssouser进行身份验证。如果验证成功,将显示auth.jsp页面。在进一步访问auth.jsp页面之前,我们将在目标站点域(即 domainB)创建应用程序 appB。
appB示例应用程序源代码可在(下载专区)进行下载。应用程序 appB配置为使用CLIENT-CERT,因此它将使用身份断言来进行验证。该应用程序应部署在SAML目标站点域(即 domainB)。位于/admin文件夹中名为services.jsp的 appB JSP页面要求已成功通过身份验证的用户拥有admin角色,才能进行访问。在weblogic.xml中,admin角色映射到名为ssouser的主体。图3显示了 appB的web.xml配置的摘录:
<display-name>SAML Destination Site Application</display-name>
<!-- ... -->
<security-constraint>
<web-resource-collection>
<web-resource-name>SecurePages</web-resource-name>
<description>These pages are only accessible by authorized users.</description>
<url-pattern>/admin/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<description>These are the roles who have access.</description>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
<description>This is how the user data must be transmitted.</description>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>myrealm</realm-name>
</login-config>
<security-role>
<description>These are the roles who have access.</description>
<role-name>admin</role-name>
</security-role>
例2. 应用程序 appB - web.xml代码片断
编译并构建每个应用程序的WAR文件(如 appA.war、appB.war)。要进行部署,将 appA.war和 appB.war文件分别复制到 domainA和 domainB的 autodeploy文件夹中。重新启动应用服务器,并测试不具备SSO功能的应用程序的行为。
SAML配置完成之后,在 appA(SAML源站点)通过身份验证的用户ssouser就可以直接访问 appB(SAML目标站点)的services.jsp页面,无需再次提供凭据。