Wildfly 8 安全域适用于简单的应用程序,但不适用于更复杂的应用程序

Wildfly 8 security domain works for a simple app but not for a more complex one

我正在更改现有的 Java EE 7 Web 应用程序以使用标准 Java EE 安全域机制来针对 Active Directory 进行身份验证。我首先创建一个简单的概念验证 Web 应用程序来测试一切并使 Wildfly 配置正常工作,然后我将更改应用到主应用程序。我现在处于测试应用程序工作但主应用程序不工作的情况。

如何让主应用程序正确使用安全域?我如何诊断这个问题?什么会干扰安全过程?

这是我在 standalone.xml 中的领域和域配置:

<security-realms>
    <!-- Default realms omitted -->
    <security-realm name="ActiveDirectoryRealm">
        <authentication>
            <ldap connection="MyAD" base-dn="OU=Test Users,OU=AU,DC=company,DC=int">
                <username-filter attribute="sAMAccountName"/>
            </ldap>
        </authentication>
    </security-realm>
</security-realms>
<outbound-connections>
    <ldap name="MyAD" url="ldap://company.int" search-dn="CN=Wildfly AS,OU=Service Accounts,OU=AU,DC=company,DC=int" search-credential="xxx"/>
</outbound-connections>

<!-- Skip many lines -->

<security-domain name="active-directory" cache-type="default">
    <authentication>
        <login-module code="Remoting" flag="optional">
            <module-option name="password-stacking" value="useFirstPass"/>
        </login-module>
        <login-module code="RealmDirect" flag="sufficient">
            <module-option name="password-stacking" value="useFirstPass"/>
            <module-option name="realm" value="ActiveDirectoryRealm"/>
        </login-module>
    </authentication>
</security-domain>

这是我的 jboss-web.xml 文件(在两个应用程序中相同):

<jboss-web>
    <security-domain>active-directory</security-domain>
</jboss-web>

最后 web.xml 的安全位(除了 URL 模式受限外,两个应用程序都相同):

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Unauthenticated Resources</web-resource-name>
        <url-pattern>/css/*</url-pattern>
        <url-pattern>/font/*</url-pattern>
        <url-pattern>/images/*</url-pattern>
        <url-pattern>/js/*</url-pattern>
        <url-pattern>/lib/*</url-pattern>
        <url-pattern>/partials/*</url-pattern>
    </web-resource-collection>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>All Resources</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>My Realm</realm-name>
    <form-login-config>
        <form-login-page>/Login.html</form-login-page>
        <form-error-page>/NoAccess.html</form-error-page>
    </form-login-config>
</login-config>

<security-role>
    <role-name>*</role-name>
</security-role>

关于应用程序的一些事实:

测试应用程序完美运行,但主应用程序始终无法登录(我被重定向到表单错误页面)。我为 org.jboss.security 打开了 TRACE 登录,但是当我尝试登录时我得到的是:

2015-07-22 13:36:54,903 TRACE [org.jboss.security] (default task-1) PBOX000354: Setting security roles ThreadLocal: null

对于额外的奇怪点,我可以将 jboss-web.xml 中的安全域值设置为 active-directoryjava:/jaas/active-directory 并且两者都有效,但是使用前缀在主应用程序中导致它无法启动。我知道 the prefix is no longer supported in Wildfly 8 但不确定为什么这两个应用程序之间的行为不同。

在此先感谢您的任何帮助和建议,非常感谢!

好吧,这很尴尬...原来问题出在我的登录表单上。我认为它们在两个应用程序之间是相同的,但主应用程序在输入字段的名称中有前导 space。