Skip to content

Instantly share code, notes, and snippets.

@dilnei
Last active April 1, 2020 21:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dilnei/3dc1ea84268f7f1d40d5 to your computer and use it in GitHub Desktop.
Save dilnei/3dc1ea84268f7f1d40d5 to your computer and use it in GitHub Desktop.
Config JAAS + Wildfly
jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/app-web</context-root>
<security-domain>java:/jaas/app-jaas-realm</security-domain>
</jboss-web>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>app-web</display-name>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>app-jaas-realm</realm-name>
<form-login-config>
<form-login-page>/auth.jsp</form-login-page>
<form-error-page>/auth.jsp?error=true</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>protected pages</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>LOGGED</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>LOGGED</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>allow resources</web-resource-name>
<url-pattern>/resources/*</url-pattern>
<url-pattern>/assets/*</url-pattern>
</web-resource-collection>
</security-constraint>
<session-config>
<session-timeout>1000</session-timeout>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<!-- SESSION -->
<listener>
<listener-class>br.com.app.web.listener.SessionListener</listener-class>
</listener>
<!-- TILES -->
<listener>
<listener-class>br.com.app.web.listener.TilesListener</listener-class>
</listener>
<servlet>
<servlet-name>Tiles Dispatch Servlet</servlet-name>
<servlet-class>org.apache.tiles.web.util.TilesDispatchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Tiles Dispatch Servlet</servlet-name>
<url-pattern>*.tiles</url-pattern>
</servlet-mapping>
<!-- VRAPTOR -->
<filter>
<filter-name>vraptor</filter-name>
<filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
</filter>
<filter-mapping>
<filter-name>vraptor</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.locale</param-name>
<param-value>pt_BR</param-value>
</context-param>
<error-page>
<error-code>404</error-code>
<location>/error404.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error500.jsp</location>
</error-page>
</web-app>
standalone.xml
<security-domain name="app-jaas-realm" cache-type="default">
<authentication>
<login-module code="Database" flag="required">
<module-option name="dsJndiName" value="java:jboss/datasources/appDS"/>
<module-option name="principalsQuery" value="select password from AUTHUSER where USER_NAME = ?"/>
<module-option name="rolesQuery" value="select roles AS role, 'Roles' from authuser u inner join authgroup g on g.id = u.authgroup_id inner join authgroup_roles r on r.authgroup_id = g.id where u.USER_NAME = ?"/>
<module-option name="hashAlgorithm" value="MD5"/>
<module-option name="hashEncoding" value="base64"/>
<module-option name="unauthenticatedIdentity" value="guest"/>
</login-module>
</authentication>
</security-domain>
@emersonlugo
Copy link

Excelente material, vai facilitar a vida de muita gente!
Obrigado por compartilhar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment