4 Replies Latest reply on Jun 11, 2018 6:11 AM by tbw

    wildfly13 login-module database $local problem

    tbw

      Properties props = new Properties();
         props.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
         props.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
         props.put(Context.URL_PKG_PREFIXES, "org.wildfly.naming.client.WildFlyInitialContextFactory");
         props.put("org.jboss.ejb.client.scoped.context", true);
         props.put("jboss.naming.client.ejb.context", true);
         props.put("remote.connections", "default");
         props.put("remote.connection.default.host", "localhost");
         props.put("remote.connection.default.port", "8080");
         props.put("remote.connection.default.protocol", "http-remoting");
         props.put("remote.connection.default.username", String.valueOf(userId));
         props.put("remote.connection.default.password", "123");
         context = new InitialContext(props);

       

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

                          <authentication>

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

                                  <module-option name="dsJndiName" value="java:jboss/datasources/DS"/>

                                  <module-option name="principalsQuery" value="select key from client where id = cast(? as int)"/>

                                  <module-option name="rolesQuery" value="select role, 'userroles' from userroles where username=?"/>

                                  <module-option name="unauthenticatedIdentity" value="nobody"/>

                              </login-module>

                          </authentication>

                      </security-domain

       

      21:50:07,458 TRACE [org.jboss.security] (default task-2) PBOX00236: Begin initialize method

      21:50:07,458 TRACE [org.jboss.security] (default task-2) PBOX00237: Saw unauthenticated indentity: nobody

      21:50:07,459 TRACE [org.jboss.security] (default task-2) PBOX00262: Module options [dsJndiName: java:jboss/datasources/DS, principalsQuery: select key from client where id = cast(? as int), rolesQuery: select role, 'userroles' from userroles where username=?, suspendResume: true]

      21:50:07,461 TRACE [org.jboss.security] (default task-2) PBOX00240: Begin login method

      21:50:07,467 DEBUG [jboss.jdbc.spy] (default task-2) java:jboss/datasources/DS [DataSource] getConnection()

      21:50:07,469 TRACE [org.jboss.security] (default task-2) PBOX00263: Executing query select key from client where id = cast(? as int) with username $local

      21:50:07,469 DEBUG [jboss.jdbc.spy] (default task-2) java:jboss/datasources/DS [Connection] prepareStatement(select key from client where id = cast(? as int))

      21:50:07,471 DEBUG [jboss.jdbc.spy] (default task-2) java:jboss/datasources/DS [PreparedStatement] setString(1, $local)

      21:50:07,472 DEBUG [jboss.jdbc.spy] (default task-2) java:jboss/datasources/DS [PreparedStatement] executeQuery()

      21:50:07,523 DEBUG [jboss.jdbc.spy] (default task-2) java:jboss/datasources/DS [PreparedStatement] close()

      21:50:07,524 DEBUG [jboss.jdbc.spy] (default task-2) java:jboss/datasources/DS [Connection] isClosed()

      21:50:07,524 DEBUG [jboss.jdbc.spy] (default task-2) java:jboss/datasources/DS [Connection] close()

       

      I think problem is in "$local", but how to fix this?

        • 1. Re: wildfly13 login-module database $local problem
          tbw

          Caused by: org.postgresql.util.PSQLException: ОШИБКА: неверное значение для целого числа: "$local"

          incorrect value for integer

          • 2. Re: wildfly13 login-module database $local problem
            mchoma

            And you are saying it worked in previous version of WF? Apparently you are expecting number in you query. But instead of numeric username you are authenticated as $local.

             

            Either you can disable local authentication. Or specify some default numeric user. Default user is "$local" otherwise.

            • 3. Re: wildfly13 login-module database $local problem
              tbw

              >And you are saying it worked in previous version of WF?

              today i was check 10,11,12 and have similar error. Sorry.

               

              >Apparently you are expecting number in you query. But instead of numeric username you are authenticated as $local.

              yes

               

              >Either you can disable local authentication

              How to do this?

              • 4. Re: wildfly13 login-module database $local problem
                tbw

                This config is work (change pass for datasource to valid):

                 

                props.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory")

                props.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");

                props.put(Context.SECURITY_PRINCIPAL, String.valueOf(userId));
                props.put(Context.SECURITY_CREDENTIALS, "password");

                 

                context = new InitialContext(props);

                ...

                 

                @Stateless
                @RolesAllowed({ "guest" })

                @SecurityDomain("legacy-domain")

                public class Bean implements BeanRemote {...}

                 

                jboss-web.xml:

                <?xml version="1.0" encoding="UTF-8"?>
                <jboss-web>
                  <security-domain>legacy-domain</security-domain>
                </jboss-web>