Automatic deployment of security-domain in WildFly 8.x

835 views Asked by At

I seek a method of application autosetup with security domain and module named Database.

Please someone advise me, how to add a section in standalone.xml or domain.xml at the deployment (maven) or setup (runtime) phase for purpose of initial setup simplifying?

1

There are 1 answers

2
Federico Sierra On BEST ANSWER

You can use a WildFly Maven Plugin (wildfly-maven-plugin). The wildfly-maven-plugin is used to deploy, redeploy, undeploy or run your application. You can also deploy or undeploy artifacts, such as JDBC drivers, and add or remove resources. There is also the ability to execute CLI commands.

Eg. (execute commands from a CLI script)

<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.2.Final</version>
                <configuration>
                    <execute-commands>
                        <scripts>
                            <script>config.cli</script>
                        </scripts>
                    </execute-commands>
                </configuration>
            </plugin>
            ...
        </plugins>
        ...
    </build>
...
</project>

config.cli add a security domain:

batch
# Configure the security domain
/subsystem=security/security-domain=my-security/:add(cache-type=default)
/subsystem=security/security-domain=my-security/authentication=classic:add(login-modules=[{"code"=>"Database", "flag"=>"required", "module-options"=>[("dsJndiName"=>"java:jboss/datasources/myDS"),("principalsQuery"=>"SELECT PASSWORD FROM USERS WHERE USERNAME = ?"), ("rolesQuery"=>"SELECT R.NAME, 'Roles' FROM USERS_ROLES UR INNER JOIN ROLES R ON R.ID = UR.ROLE_ID INNER JOIN USERS U ON U.ID = UR.USER_ID WHERE U.USERNAME = ?")]}])
# Run the batch commands
run-batch
# Reload the server configuration
:reload

I hope this help.