<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hi,<br>
      <br>
      how exactly looks "Own code which authenticates the user in DB" ?
      I guess you are accessing USER_ENTITY table somehow with your own
      EntityManager/JDBC code? You should either:<br>
      - use just model api and not use Keycloak tables directly from
      your own EntityManager<br>
      - switch to different database than default H2<br>
      <br>
      Marek<br>
      <br>
      On 20/08/15 20:47, Bhanu Kiran wrote:<br>
    </div>
    <blockquote
cite="mid:CAJT7oPEMZUX8g1WpBkvkNg_oO5V04DFFAd9EY4uHsM3mMY6=Lw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>Hi team,</div>
        <div><br>
        </div>
        <div>I am implementing own user federation. </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>As part of this implementing my class is
          UserFederationProvider.</div>
        <div><br>
        </div>
        <div>1. In method <span class="" style="white-space:pre">        </span>public
          UserModel getUserByUsername(RealmModel realm, String username)
          {</div>
        <div><br>
        </div>
        <div>//Own code which authenticates the user in DB</div>
        <div><br>
        </div>
        <div>Returning  user model </div>
        <div><br>
        </div>
        <div><span class="" style="white-space:pre">        </span>UserModel
          userModel = session.userStorage().addUser(realm, username);</div>
        <div><span class="" style="white-space:pre">                </span>userModel.setEnabled(true);</div>
        <div>        userModel.setFederationLink(model.getId());</div>
        <div>    <span class="" style="white-space:pre">        </span>return
          userModel</div>
        <div>}</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>2. Below exception is generated after UserModel in
          returned.</div>
        <div><br>
        </div>
        <div>Please let me know if i missed anything.</div>
        <div><br>
        </div>
        <div>============================================================================</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>11:22:01,438 WARN
           [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default
          task-10) SQL Error: 50200, SQLState: HYT00</div>
        <div>11:22:01,439 ERROR
          [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default
          task-10) Timeout trying to lock table "USER_ENTITY"; SQL
          statement:</div>
        <div>select userentity0_.ID as ID1_47_,
          userentity0_.CREATED_TIMESTAMP as CREATED_2_47_,
          userentity0_.EMAIL as EMAIL3_47_,
          userentity0_.EMAIL_CONSTRAINT as EMAIL_CO4_47_,
          userentity0_.EMAIL_VERIFIED as EMAIL_VE5_47_,
          userentity0_.ENABLED as ENABLED6_47_,
          userentity0_.federation_link as federati7_47_,
          userentity0_.FIRST_NAME as FIRST_NA8_47_,
          userentity0_.LAST_NAME as LAST_NAM9_47_, userentity0_.REALM_ID
          as REALM_I10_47_, userentity0_.SERVICE_ACCOUNT_CLIENT_LINK as
          SERVICE11_47_, userentity0_.TOTP as TOTP12_47_,
          userentity0_.USERNAME as USERNAM13_47_ from USER_ENTITY
          userentity0_ where userentity0_.ID=? and
          userentity0_.REALM_ID=? [50200-173]</div>
        <div>11:22:01,442 ERROR
          [org.keycloak.authentication.AuthenticationProcessor] (default
          task-10) failed authentication:
          javax.persistence.PessimisticLockException: could not extract
          ResultSet</div>
        <div>        at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.wrapLockException(AbstractEntityManagerImpl.java:1831)</div>
        <div>        at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1720)</div>
        <div>        at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)</div>
        <div>        at
          org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)</div>
        <div>        at
org.keycloak.models.jpa.JpaUserProvider.getUserById(JpaUserProvider.java:228)</div>
        <div>        at
org.keycloak.models.cache.DefaultCacheUserProvider.getUserById(DefaultCacheUserProvider.java:132)</div>
        <div>        at
org.keycloak.models.UserFederationManager.deleteInvalidUser(UserFederationManager.java:111)</div>
        <div>        at
org.keycloak.models.UserFederationManager.validateAndProxyUser(UserFederationManager.java:134)</div>
        <div>        at
org.keycloak.models.UserFederationManager.getUserById(UserFederationManager.java:162)</div>
        <div>        at
org.keycloak.models.sessions.mem.ClientSessionAdapter.getAuthenticatedUser(ClientSessionAdapter.java:192)</div>
        <div>        at
org.keycloak.authentication.AuthenticationProcessor$Result.getUser(AuthenticationProcessor.java:301)</div>
        <div>        at
org.keycloak.authentication.authenticators.browser.AbstractFormAuthenticator.validatePassword(AbstractFormAuthenticator.java:176)</div>
        <div>        at
org.keycloak.authentication.authenticators.browser.UsernamePasswordForm.validateForm(UsernamePasswordForm.java:46)</div>
        <div>        at
org.keycloak.authentication.authenticators.browser.UsernamePasswordForm.action(UsernamePasswordForm.java:39)</div>
        <div>        at
org.keycloak.authentication.DefaultAuthenticationFlow.processAction(DefaultAuthenticationFlow.java:59)</div>
        <div>        at
org.keycloak.authentication.DefaultAuthenticationFlow.processAction(DefaultAuthenticationFlow.java:54)</div>
        <div>        at
org.keycloak.authentication.AuthenticationProcessor.authenticationAction(AuthenticationProcessor.java:533)</div>
        <div>        at
org.keycloak.services.resources.LoginActionsService.processFlow(LoginActionsService.java:306)</div>
        <div>        at
org.keycloak.services.resources.LoginActionsService.processAuthentication(LoginActionsService.java:287)</div>
        <div>        at
org.keycloak.services.resources.LoginActionsService.authenticateForm(LoginActionsService.java:333)</div>
        <div>        at
          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</div>
        <div>        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)</div>
        <div>        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</div>
        <div>        at java.lang.reflect.Method.invoke(Method.java:497)</div>
        <div>        at
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)</div>
        <div>        at
org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)</div>
        <div>        at
org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)</div>
        <div>        at
org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:140)</div>
        <div>        at
org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:103)</div>
        <div>        at
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)</div>
        <div>        at
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)</div>
        <div>        at
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)</div>
        <div>        at
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)</div>
        <div>        at
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)</div>
        <div>        at
          javax.servlet.http.HttpServlet.service(HttpServlet.java:790)</div>
        <div>        at
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)</div>
        <div>        at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)</div>
        <div>        at
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:59)</div>
        <div>        at
          io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)</div>
        <div>        at
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)</div>
        <div>        at
io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)</div>
        <div>        at
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)</div>
        <div>        at
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)</div>
        <div>        at
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)</div>
        <div>        at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div>
        <div>        at
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)</div>
        <div>        at
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)</div>
        <div>        at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div>
        <div>        at
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)</div>
        <div>        at
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)</div>
        <div>        at
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)</div>
        <div>        at
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)</div>
        <div>        at
io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)</div>
        <div>        at
io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)</div>
        <div>        at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div>
        <div>        at
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)</div>
        <div>        at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div>
        <div>        at
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div>
        <div>        at
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)</div>
        <div>        at
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)</div>
        <div>        at
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)</div>
        <div>        at
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)</div>
        <div>        at
          io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)</div>
        <div>        at
          io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)</div>
        <div>        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)</div>
        <div>        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)</div>
        <div>        at java.lang.Thread.run(Thread.java:745)</div>
        <div>Caused by: org.hibernate.PessimisticLockException: could
          not extract ResultSet</div>
        <div>        at
          org.hibernate.dialect.H2Dialect$2.convert(H2Dialect.java:342)</div>
        <div>        at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)</div>
        <div>        at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)</div>
        <div>        at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)</div>
        <div>        at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)</div>
        <div>        at
          org.hibernate.loader.Loader.getResultSet(Loader.java:2066)</div>
        <div>        at
          org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863)</div>
        <div>        at
          org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)</div>
        <div>        at
          org.hibernate.loader.Loader.doQuery(Loader.java:910)</div>
        <div>        at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)</div>
        <div>        at
          org.hibernate.loader.Loader.doList(Loader.java:2554)</div>
        <div>        at
          org.hibernate.loader.Loader.doList(Loader.java:2540)</div>
        <div>        at
          org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)</div>
        <div>        at
          org.hibernate.loader.Loader.list(Loader.java:2365)</div>
        <div>        at
          org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)</div>
        <div>        at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)</div>
        <div>        at
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)</div>
        <div>        at
          org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)</div>
        <div>        at
          org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)</div>
        <div>        at
          org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)</div>
        <div>        at
          org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)</div>
        <div>        ... 63 more</div>
        <div>Caused by: org.h2.jdbc.JdbcSQLException: Timeout trying to
          lock table "USER_ENTITY"; SQL statement:</div>
        <div>select userentity0_.ID as ID1_47_,
          userentity0_.CREATED_TIMESTAMP as CREATED_2_47_,
          userentity0_.EMAIL as EMAIL3_47_,
          userentity0_.EMAIL_CONSTRAINT as EMAIL_CO4_47_,
          userentity0_.EMAIL_VERIFIED as EMAIL_VE5_47_,
          userentity0_.ENABLED as ENABLED6_47_,
          userentity0_.federation_link as federati7_47_,
          userentity0_.FIRST_NAME as FIRST_NA8_47_,
          userentity0_.LAST_NAME as LAST_NAM9_47_, userentity0_.REALM_ID
          as REALM_I10_47_, userentity0_.SERVICE_ACCOUNT_CLIENT_LINK as
          SERVICE11_47_, userentity0_.TOTP as TOTP12_47_,
          userentity0_.USERNAME as USERNAM13_47_ from USER_ENTITY
          userentity0_ where userentity0_.ID=? and
          userentity0_.REALM_ID=? [50200-173]</div>
        <div>        at
          org.h2.message.DbException.getJdbcSQLException(DbException.java:331)</div>
        <div>        at
          org.h2.message.DbException.get(DbException.java:171)</div>
        <div>        at
          org.h2.message.DbException.get(DbException.java:148)</div>
        <div>        at
          org.h2.table.RegularTable.doLock(RegularTable.java:521)</div>
        <div>        at
          org.h2.table.RegularTable.lock(RegularTable.java:455)</div>
        <div>        at
          org.h2.table.TableFilter.lock(TableFilter.java:145)</div>
        <div>        at
          org.h2.command.dml.Select.queryWithoutCache(Select.java:611)</div>
        <div>        at org.h2.command.dml.Query.query(Query.java:314)</div>
        <div>        at org.h2.command.dml.Query.query(Query.java:284)</div>
        <div>        at org.h2.command.dml.Query.query(Query.java:36)</div>
        <div>        at
          org.h2.command.CommandContainer.query(CommandContainer.java:91)</div>
        <div>        at
          org.h2.command.Command.executeQuery(Command.java:195)</div>
        <div>        at
org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:106)</div>
        <div>        at
org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)</div>
        <div>        at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)</div>
        <div>        ... 79 more</div>
        <div><span class="" style="white-space:pre">                </span>==========================================================================================</div>
        <div><br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
keycloak-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br>
  </body>
</html>