16.8. 为 Web 应用程序配置 Kerberos 或 Microsoft Active Directory 桌面单点登录

简介

要使用机构现有的基于 Kerberos 的验证和授权体系(如 Microsoft Active Directory)来验证你的 Web 或 EJB 应用程序,你可以使用 JBoss EAP 6 里内嵌的 JBoss Negotation 功能。如果你正确配置了你的 web 应用程序,成功的桌面或网络登录就足够透明地验证你的 we 应用程序,而不需要额外的登录提示。

与之前版本的不同之处

JBoss EAP 6 和之前的版本有着一些值得注意的区别:

  • 对于受管域的每个配置集或每个独立服务器来说,安全域都是集中配置的。它们不是部署本身的一部分。部署应该使用的安全域是在部署的 jboss-web.xmljboss-ejb3.xml 文件里命名的。
  • 安全属性是作为安全域也是中央配置的一部分配置的。它们不是部署的一部分。
  • 你无法再覆盖作为部署一部分的验证。然而,你可以添加一个 NegotiationAuthenticator 阀到 jboss-web.xml 描述符以实现相同的效果。这个值仍然要求在 web.xml 里定义 <security-constraint><login-config> 元素。它们用于确定哪些资源是安全的。然而,所选的 auth-method 将被 jboss-web.xml 里的 NegotiationAuthenticator 阀所替代。
  • 安全域里的 CODE 属性现在使用一个简单的名称而不是全限定类名。下表展示了对 JBoss Negotiation 的类的映射。

表 16.2. 登录模块代码和类名

简单名称 类名 目的
Kerberos com.sun.security.auth.module.Krb5LoginModule Kerberos 登录模块
SPNEGO org.jboss.security.negotiation.spnego.SPNEGOLoginModule 启用 web 应用程序向 Kerberos 验证服务器验证的机制。
AdvancedLdap org.jboss.security.negotiation.AdvancedLdapLoginModule 和 LDAP 服务器而不是 Microsoft Active Directory 一起使用。
AdvancedAdLdap org.jboss.security.negotiation.AdvancedADLoginModule 和 Microsoft Active Directory LDAP 服务器一起使用。
Jboss Negotiation Toolkit

The JBoss Negotiation Toolkit is a debugging tool which is available for download from https://community.jboss.org/servlet/JiveServlet/download/16876-2-34629/jboss-negotiation-toolkit.war. It is provided as an extra tool to help you to debug and test the authentication mechanisms before introducing your application into production. It is an unsupported tool, but is considered to be very helpful, as SPNEGO can be difficult to configure for web applications.

过程 16.1. 设置 Web 或 EJB 应用程序的 SSO 验证

  1. 配置一个安全域来代表服务器的身份。如果需要则设置系统属性。

    第一个安全域向目录服务验证容器自身。它需要使用一个接受某种静态登录机制的登录模块,因为这没有涉及真正的用户。这个例子使用了一个静态 principal 并引用了一个包含凭证的 Keytab 文件。
    下面通过 XML 片段进行阐述,但你应该使用管理控制台或 CLI 来配置你的安全域。
    <security-domain name="host" cache-type="default">
       <authentication>
          <login-module code="Kerberos" flag="required">
             <module-option name="storeKey" value="true"/>
             <module-option name="useKeyTab" value="true"/>
             <module-option name="principal" value="host/testserver@MY_REALM"/>
             <module-option name="keyTab" value="/home/username/service.keytab"/>
             <module-option name="doNotPrompt" value="true"/>
             <module-option name="debug" value="false"/>
          </login-module>
       </authentication>
    </security-domain>		
    		
    
    
  2. 配置第二个安全域来保护 web 或 EJB 应用程序。如果有必要请设置系统属性。

    第二个安全域用来向 Kerberos 或 SPNEGO 验证服务器验证单独的用户。你需要至少一个登录模块来验证用户,另外一个则搜索适用于用户的角色。下面的 XML 片段展示了一个 SPNEGO 安全域示例。它包含了一个授权模块来映射角色和单独的用户。你也可以使用一个搜索验证服务器自己的角色的模块。
    <security-domain name="SPNEGO" cache-type="default">
       <authentication>
          <!-- Check the username and password -->
          <login-module code="SPNEGO"  flag="requisite">
             <module-option name="password-stacking" value="useFirstPass"/>
             <module-option name="serverSecurityDomain" value="host"/>
          </login-module>
          <!-- Search for roles -->
          <login-module code="UsersRoles" flag="required">
             <module-option name="password-stacking" value="useFirstPass" />
             <module-option name="usersProperties" value="spnego-users.properties" />
             <module-option name="rolesProperties" value="spnego-roles.properties" />
          </login-module> 
       </authentication>
    </security-domain>		
    		
    
    
  3. web.xml 里指定 security-constraint 和 login-config。

    web.xml 描述符包含了安全约束和登录配置的信息。下面是两者的示例。
    <security-constraint>
       <display-name>Security Constraint on Conversation</display-name>
       <web-resource-collection>
          <web-resource-name>examplesWebApp</web-resource-name>
          <url-pattern>/*</url-pattern>
       </web-resource-collection>
       <auth-constraint>
       <role-name>RequiredRole</role-name>
       </auth-constraint>
    </security-constraint>
    
    <login-config>
       <auth-method>SPNEGO</auth-method>
       <realm-name>SPNEGO</realm-name>
    </login-config>
     
    <security-role>
       <description> role required to log in to the Application</description>
       <role-name>RequiredRole</role-name>
    </security-role>		
    		
    
    
  4. jboss-web.xml 描述符里指定安全域和其他设置。

    在部署的 jboss-web.xml 描述符里指定客户端安全域(这个例子里的第二个)的名称,指引你的应用程序来使用这个安全域。
    你无法再直接覆盖验证。相反,如果需要的话你可以在 jboss-web.xml 里添加 NegotiationAuthenticator 为阀。<jacc-star-role-allow> 允许你使用星号(*)来匹配多个角色名,它是可选的。
    <jboss-web>
       <security-domain>java:/jaas/SPNEGO</security-domain>
       <valve>
          <class-name>org.jboss.security.negotiation.NegotiationAuthenticator</class-name>
       </valve>
       <jacc-star-role-allow>true</jacc-star-role-allow>
    </jboss-web>		
    		
    
    
  5. 添加一个依赖关系到应用程序的 MANIFEST.MF 以定位 Negotiation 类。

    Web 应用程序需要在部署的 META-INF/MANIFEST.MF manifest 里添加一个 org.jboss.security.negotiation 类的依赖关系,从而定义 JBoss Negotiation 类。下面是一个具有正确格式的条目。
    Manifest-Version: 1.0
    Build-Jdk: 1.6.0_24
    Dependencies: org.jboss.security.negotiation
    
结果

你的 Web 应用程序通过 Kerberos、Microsoft Active Directory 或其他兼容 SPNEGO 的目录服务接受和验证凭证。如果用户在一个已经登录至目录服务的系统里运行这个应用程序,而要求的角色已经应用到用户,那么这个 Web 应用程序将不会再提示进行验证,从而实现了 SSO 功能。