我认为目前这不可能以简单的方式(相关的 JIRA 问题)。但是,您可以使用jboss-as-maven-plugin作为解决方法:
<profiles>
<profile>
<id>deploy-security-domain</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<executions>
<execution>
<id>add-security-domain</id>
<phase>install</phase>
<goals>
<!-- This should work in both "standalone" and "domain" mode -->
<goal>execute-commands</goal>
</goals>
<configuration>
<execute-commands>
<batch>true</batch>
<commands>
<command>/subsystem=security/security-domain=MyDomain:add(cache-type=default)</command>
<command>/subsystem=security/security-domain=MyDomain/authentication=classic:add(login-modules=[{"code"=>"Database","flag"=>"required","module-options"=>[("dsJndiName"=>"java:jboss/datasources/UserDB"),("principalsQuery"=>"select password from users where user_name=?"),("rolesQuery"=>"select role, 'Roles' from user_roles where user_name=?"),("hashAlgorithm"=>"SHA-256"),("hashEncoding"=>"base64")]}]</command>
</commands>
</execute-commands>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
执行:
mvn install -P deploy-security-domain
另一种选择是CLI脚本,它或多或少做同样的事情。查看此快速入门项目以获取示例。