Friday, April 27, 2018

Wildfly FORM based authentication with DB realm

https://dzone.com/articles/jdbc-realm-and-form-based-0

https://github.com/myfear/SimpleJDBCRealmWildFly


CREATE TABLE Users(username VARCHAR(255) PRIMARY KEY, passwd VARCHAR(255));

CREATE TABLE UserRoles(username VARCHAR(255), role VARCHAR(32));

the jar file is in:
D:\apps\wildfly12\modules\system\layers\base\org\picketbox\main\picketbox-5.0.2.Final.jar


java -classpath modules/system/layers/base/org/picketbox/main/picketbox-5.0.2.Final.jar org.jboss.security.Base64Encoder admin SHA-256
[jGl25bVBBBW96Qi9Te4V37Fnqchz/Eu4qB9vKrRIqRg=]

INSERT INTO users (username, passwd) VALUES ('myfear', 'jGl25bVBBBW96Qi9Te4V37Fnqchz/Eu4qB9vKrRIqRg=');
INSERT INTO userroles (username, role) VALUES ('myfear', 'ADMIN');

<security-domain name="secureDomain" cache-type="default">
                    <authentication>
                        <login-module code="Database" flag="required">
                            <module-option name="dsJndiName" value="java:jboss/datasources/UserDS"/>
                            <module-option name="principalsQuery" value="select passwd from Users where username=?"/>
                            <module-option name="rolesQuery" value="select role, 'Roles' from UserRoles where username=?"/>
                            <module-option name="hashAlgorithm" value="SHA-256"/>
                            <module-option name="hashEncoding" value="base64"/>
                        </login-module>
                    </authentication>
                </security-domain>





Monday, April 23, 2018

Wildfly: deploy an application as a root context

http://www.mastertheboss.com/jboss-web/jbosswebserver/how-to-deploy-a-web-application-on-the-root-context-on-jboss-as-7


Schemas for the standalone.xml can be found in D:\apps\wildfly12\docs\schema

For the undertow (former web) subsystem, use wildfly-undertow_5_0.xsd



and the virtual-server is defined in jboss-as-web_2_2.xsd (which is JBoss AS, not Wildfly)


This CLI:
/subsystem=undertow:write-attribute(name=default-virtual-host, value=default-host)
adds default-virtual-host="default-host" to the line subsystem xmlns="urn:jboss:domain:undertow:5.0" in config.xml

subsystem xmlns="urn:jboss:domain:undertow:5.0"




Very helpful: https://docs.jboss.org/author/display/WFLY10/CLI+Recipes


By default, Wildfly 12 comes with this Undertow configuration

<subsystem xmlns="urn:jboss:domain:undertow:5.0">
 <buffer-cache name="default"/>
 <server name="default-server">
  <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
  <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
  <host name="default-host" alias="localhost">
   <location name="/" handler="welcome-content"/>
   <filter-ref name="server-header"/>
   <filter-ref name="x-powered-by-header"/>
   <http-invoker security-realm="ApplicationRealm"/>
  </host>
 </server>
 <servlet-container name="default">
  <jsp-config/>
  <websockets/>
 </servlet-container>
 <handlers>
  <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
 </handlers>
 <filters>
  <response-header name="server-header" header-name="Server" header-value="WildFly/11"/>
  <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
 </filters>
</subsystem>


According to the book "WildFly Configuration, Deployment, and Administration - Second Edition" , page 118, if you want to deploy a webapp to handle the / root context, you first have to run this CLI:


/subsystem=undertow/server=default-server/host=default-host/location=\/:remove()

After which the entry <location name="/" handler="welcome-content"/> will disappear from the standalone.xml

To build such CLI command, it's very useful to open the Administration console, then bottom right you have "Tools" "Management Model" , then you navigate in the tree matching the structure you can read in the XML.
Unfortunately CLI can't be generated directly from the console (as it was the case in WLST and WebLogic! One huge point in favor of WebLogic!)

<jboss-web>
<context-root>/</context-root>
</jboss-web>

git clone https://github.com/vernetto/primefaces-test.git
cd primefaces-test
mvn clean package

(in the CLI) deploy c:\pierre\gitclones\primefaces-test\target\primefaces-test-1.0-SNAPSHOT.war


enter localhost:8080 and your webapp is there instead of the ROOT.war application !

Enter http://localhost:9990/console/App.html#standalone-deployments;backButton=/deployments-details and you see the









Sunday, April 22, 2018

wildfly configuration, deployment and administration - second edition


This is an excellent book, hands on and very practical. Good for the beginner just getting started with Wildfly.