Wildfly 自定义身份验证方法

Wildfly Custom auth-method

如何在 Wildfly 中添加自定义验证器?我曾经在 JBoss 4.2:

中这样做过

<JBoss>\jboss-as\server\production\deploy\jboss-web.deployer\META-INF\jboss-service.xml中添加以下内容:

 <java:property>
      <java:key>MY-CUSTOM-AUTH</java:key>
      <java:value>com.test.MyCustomAuthenticator</java:value>
 </java:property>

<JBoss>\jboss-as\server\production\deploy\jboss-portal-ha.sar\portal-server.war\WEB-INF\web.xml中修改:

...
 <login-config>
      <auth-method>MY-CUSTOM-AUTH</auth-method>
...

Wildfly 没有 jboss-service.xml了。

在 WildFly 中,您必须为此使用安全领域:

我找到了答案。我们需要在 META-INF/services 中创建一个 Undertow ServletExtension (io.undertow.servlet.ServletExtension) 来注册认证机制。我的扩展 class 看起来像这样:

public class NtlmServletExtension implements ServletExtension {
    @Override
    public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
        deploymentInfo.addAuthenticationMechanism("NTLM", new NtlmAuthenticationMechanism.Factory());
    }
}

查看更多详细信息:http://undertow.io/documentation/servlet/security.html

这是一个示例: https://github.com/dstraub/spnego-wildfly

您现在可以在 web.xml 中引用此内容:

...
 <login-config>
      <auth-method>NTLM</auth-method>
...