2 Replies Latest reply on Mar 21, 2018 9:54 AM by bartkrul

    Wildfly 11.0.0.Final JAAS Security

    bartkrul

      Hi,

      I'm having trouble with authentication using JAAS.

      I added the following to my standalone.xml

      <security-domain name="SecureDomain" cache-type="default">

         <authentication>

           <login-module code="Database" flag="required">

            <module-option name="dsJndiName" value="java:/KwetterDB"/>

             <module-option name="principalsQuery" value="select password from kwetter_db.profile where email=?"/>

             <module-option name="rolesQuery" value="SELECT role_name FROM kwetter_db.profile_role WHERE profile_id = (SELECT profile_id FROM kwetter_db.profile WHERE email =?)"/>

           </login-module>

         </authentication>

      </security-domain>

       

      My query when executed in mySQL gives the following result (basically it returns ADMIN when executing the query with email2@example.com):


      my webxml:

      <?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>Kwetter REST</display-name>

        <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>SecuredRealm</realm-name>
        </login-config>

         <!--
        <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>SecuredRealm</realm-name>
        <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/loginerror.xhtml</form-error-page>
        </form-login-config>
        </login-config>
        -->

         <security-role>
        <role-name>ADMIN</role-name>
        </security-role>

        <security-constraint>
        <web-resource-collection>
        <web-resource-name>Secure Admin Page</web-resource-name>
        <url-pattern>/admin/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
        <role-name>ADMIN</role-name>
        </auth-constraint>
        <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
        </security-constraint>

        <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
        </context-param>
        <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>
        <session-config>
        <session-timeout>
         30
         </session-timeout>
        </session-config>
        <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
        </welcome-file-list>

      </web-app>




        • 1. Re: Wildfly 11.0.0.Final JAAS Security
          bartkrul

          Ugh I accedently pressed enter and cannot edit my post! Sorry!

          My problem is that the BASIC login prompt keeps popping up when I visit the protected page, which is good.
          However when I enter my credentials (email and password), it just pops again indicating wrong credentials.
          Is anything wrong with my settings?

          My database connection should work since I already persisted entities in it.





          • 2. Re: Wildfly 11.0.0.Final JAAS Security
            bartkrul

            I found out what I did wrong, for some reason this always happens when I post my question.

            I forgot to add a column called ''Roles".

            I'm not sure what the use of this is though? Can someone explain maybe?