JBoss Wildfly - 针对 LDAP 的 Web 应用程序身份验证

JBoss Wildfly - Authentication of Web App against LDAP

我在 jboss-web.xml 中定义了一个安全域,如下所示

<jboss-web>
    <security-domain>java:/jaas/my_ldap_security_domain</security-domain>
    <disable-audit>true</disable-audit>
</jboss-web>

我也在我的里面定义了standalone.xml

<subsystem xmlns="urn:jboss:domain:security:1.2">
    <security-domains>
        <security-domain name="my_ldap_security_domain" cache-type="default">
            <authentication>
                <login-module code="LdapExtended" flag="sufficient">
                    <module-option name="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory"/>
                    <module-option name="java.naming.provider.url" value="ldaps://xxx.xxx.xxx.xxx:yyyy"/>
                    <module-option name="java.naming.security.authentication" value="simple"/>
                    <module-option name="bindDN" value="temp@my.domain"/>
                    <module-option name="bindCredential" value="mypass"/>
                    <module-option name="baseCtxDN" value="DC=my,DC=domain"/>
                    <module-option name="baseFilter" value="(uid={0})"/>
                    <module-option name="rolesCtxDN" value="DC=my,DC=domain"/>
                    <module-option name="roleFilter" value="(uniquemember={1})"/>
                    <module-option name="roleAttributeID" value="cn"/>
                    <module-option name="searchScope" value="SUBTREE_SCOPE"/>
                    <module-option name="roleRecursion" value="0"/>
                    <module-option name="allowEmptyPasswords" value="true"/>
                </login-module>
            </authentication>
        </security-domain>
    </security-domains>
</subsystem>

我的 standalone.xml 上唯一的领域是

<security-realms>
    <security-realm name="ManagementRealm">
        <authentication>
            <local default-user="$local" skip-group-loading="true"/>
            <properties path="mgmt-users.properties" relative-to="jboss.server.config.dir"/>
        </authentication>
        <authorization map-groups-to-roles="false">
            <properties path="mgmt-groups.properties" relative-to="jboss.server.config.dir"/>
        </authorization>
    </security-realm>
    <security-realm name="ApplicationRealm">
        <authentication>
            <local default-user="$local" allowed-users="*" skip-group-loading="true"/>
            <properties path="application-users.properties" relative-to="jboss.server.config.dir"/>
        </authentication>
        <authorization>
            <properties path="application-roles.properties" relative-to="jboss.server.config.dir"/>
        </authorization>
    </security-realm>
</security-realms>

我之前没有提到它,因为我认为这个安全领域是为了验证应用程序服务器控制台访问。抱歉。

我的疑问是如何创建一个 jsf2 登录页面来根据上面定义的内容进行身份验证。我阅读了很多关于但仍然在同一个地方的文章,因为大多数文章都使用虚假身份验证作为示例(与静态字符串比较,而不是展示如何咨询 LDAP 服务器)。

谁能帮帮我?

i presumed that this security realms were meant to authenticate the application server console access

你说对了一部分。 name="ManagementRealm" 确实指定了用于访问管理功能的领域配置。 name="ApplicationRealm" 将是为保护 Web 应用程序指定的属性

您当前的领域配置缺少 LDAP 身份验证所需的一些内容。我想您已经熟悉 web.xml 中的登录表单配置。您的领域配置应如下所示,摘自 Wildfly 8 Realm Configuration Manual:

<management>
  <security-realms>
    <security-realm name="ApplicationRealm">
      <authentication>
        <ldap connection="EC2" base-dn="CN=Users,DC=darranl,DC=jboss,DC=org">
          <username-filter attribute="sAMAccountName" />
        </ldap>
      </authentication>
    </security-realm>
 
  </security-realms>
</management>

其中 <ldap> 标记指定您的查找是针对 LDAP 服务器的。除此之外,您只需遵循 JavaEE 应用程序的标准身份验证方法。

由此得出的结论是,JavaEE 中的 Web 应用程序安全性通常采用与

相同的方法
  1. 设置领域(特定于应用程序服务器)
  2. 在 web.xml 中设置安全约束(在所有 JavaEE 应用程序中统一)
  3. 实施登录方法(配置或编程)

相关

  • Java EE 6 Programmatic security, glassfish and JDBC realm
  • How to properly logout of a Java EE 6 Web Application after logging in
  • Performing user authentication in Java EE / JSF using j_security_check