簡體   English   中英

Wildfly自定義登錄模塊永遠不會執行?

[英]Wildfly custom login module never gets executed?

我為在Wildfly 8.0中運行的Web應用程序創建了自定義登錄模塊。 這是模塊:

package bmacs.auth;

import java.security.acl.Group;
import javax.security.auth.login.LoginException;
import org.jboss.security.SimpleGroup;
import org.jboss.security.SimplePrincipal;
import org.jboss.security.auth.spi.UsernamePasswordLoginModule;

public class BasicLoginModule extends UsernamePasswordLoginModule
{
    @Override
    protected String getUsersPassword() throws LoginException
    {
        System.out.println("custom getUsersPassword");
        System.out.format("MyLoginModule: authenticating user '%s'\n",
                getUsername());
        String password = super.getUsername();
        password = password.toUpperCase();
        return password;
    }

    @Override
    protected boolean validatePassword(String inputPassword,
            String expectedPassword)
    {
        System.out.println("custom validatePassword");
        String encryptedInputPassword = (inputPassword == null) ? null
                : inputPassword.toUpperCase();
        System.out.format(
                "Validating that (encrypted) input psw '%s' equals to (encrypted) '%s'\n"
                , encryptedInputPassword, expectedPassword);
        return true;
    }

    @Override
    protected Group[] getRoleSets() throws LoginException
    {
        System.out.println("custom getRoleSets");
        SimpleGroup group = new SimpleGroup("Roles");
        try {
            System.out.println("Search here group for user: "+super.getUsername());
            group.addMember(new SimplePrincipal("RoleReportEnrollmentViewer"));

        } catch (Exception e) {
            throw new LoginException("Failed to create group member for " + group);
        }
        return new Group[] { group };
    }
}

這是我添加到standalone.xml中的新安全域

<security-domain name="simple-auth" cache-type="default">
                    <authentication>
                        <login-module code="bmacs.auth.BasicLoginModule" flag="required" module="login"/>
                    </authentication>
                </security-domain>

這是我的Web應用程序的jboss-web.xml,它引用了安全域。

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <security-domain flushOnSessionInvalidation="true">simple-auth</security-domain>
</jboss-web>

當我嘗試登錄時(通過表單身份驗證J_SECURITY_CHECK),它什么都不做。 日志中唯一顯示的是這兩行,對您的幫助不大

16:55:09,622 TRACE [org.jboss.security] (default task-9) PBOX000200: Begin isValid, principal: org.wildfly.extension.undertow.security.AccountImpl$AccountPrincipal@c9c352bc, cache entry: null
16:55:09,625 TRACE [org.jboss.security] (default task-9) PBOX000354: Setting security roles ThreadLocal: null

我想念什么? 自定義登錄中的System.out.println語句從不打印任何內容/不執行任何操作。

再次檢查jboss-web.xml。 我認為您必須在xml中設置安全角色。 我給你一個URL可能會有所幫助

https://stackoverflow.com/questions/29726261/form-b​​ased-authentication-in-wildfly-with-jsf

告訴我一些對你有用的東西。

問候。

最近我也遇到了類似的問題。 查看我創建的此WildFly錯誤,您可以在其中找到解決方法: WFLY-4761 閱讀鏈接后,如果需要更多幫助,請與我聯系。

編輯:作為對Newd評論的回應,我將添加更多描述。 WildFly 8.2.0中存在一個錯誤,該錯誤會吞噬登錄模塊中未經檢查的異常。 解決方法是通過修改后的類org.jboss.security.authentication.JBossCachedAuthenticationManager修補picketbox-infinispan-4.0.21.Final.jar,在該類中,DefaultLogin方法實現的第二部分中的運行時錯誤將被LoginException捕獲並重新拋出。 最初的問題與WildFly 8.0有關,您必須在舊版本的Picketbox-infinispan-4.0.20.Final.jar中執行相同的操作。 請注意,該問題也可能是由不滿足的模塊依賴關系引起的(WildFly模塊必須明確聲明其依賴關系)。

修補庫后,模塊中的錯誤開始出現在WildFly日志文件中。

您必須使用新的身份驗證機制:

Wildfly自定義身份驗證方法

您必須創建一個新的類來實現wildfly接口,並在web.xml中登錄配置使用您的新配置...您還可以從wildfly中檢查導入的源類:FormAuthenticationMecanism解釋了wildfly 9,但在wildfly 8中是相同的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM