This demo uses WildFly ModelControllerClient to show, how to work with an Elytron-enabled WildFly client.
The demo application (SimpleClient.java) connects to a WildFly server and calls :whoami operation twice:
- with default AuthenticationContext (from
wildfly-config.xml) - with programmatically created
AuthenticationContext
The default context is loaded by a discovery mechanism (wildfly-client-config GitHub project) and can be customized by a wildfly.config.url system property.
The Elytron part of wildfly-config.xml client configuration is described in Elytron XSD (e.g. version 1.1.0.Beta17).
Entrypoint for the programmatic Elytron client configuration is the class AuthenticationContext.
The AuthenticationContext instance created in this demo contains following rules:
- client connecting to
localhosthostname is handled asadministrator - any client is handled as
monitor
bin/add-user.sh -u monitor -p password1! -s
bin/add-user.sh -u administrator -p password1! -sbin/jboss-cli.sh --file=enable-elytron.clibin/standalone.shThe default WildFly host to which this client connects is 127.0.0.1
mvn package exec:javaThe first demo should print $local username:
"identity" => {"username" => "$local"},
Default configuration doesn't contain any user/password specification.
The second demo should print monitor username:
"identity" => {"username" => "monitor"},
As the default host is 127.0.0.1 and not the localhost, we see here the monitor identity.
By setting system property hostname you can set to which host the controller client will connect:
mvn package exec:java -Dhostname=localhostThe first part of the demo should still report $localuser, but the second part should print administrator user:
"identity" => {"username" => "administrator"},
By setting system property wildfly.config.url you can control from which location is the default AuthenticationContext configuration loaded.
mvn package exec:java -Dwildfly.config.url=custom-config.xmlThe first part of the demo should now report the same user as the second one:
"identity" => {"username" => "monitor"},
For instance, you can try to use AuthenticationContext.captureCurrent() instead of AuthenticationContext.EMPTY, which should take current context as a base instead of
building one from scratch.