title: WSO2 Identity Server - Tenant Admin Login failure - Error occurred while getting tenant user realm for tenant id
body: <p>I have started facing problem with tenant admin login to the WSO2 Administrative console at random intervals. I am using the WSO2 Identity Server 5.1.0. </p>
  
  <pre><code>    TID: [46] [] [2016-09-04 19:09:10,344] @tenant1.edu [46] [IS]ERROR {org.wso2.carbon.core.util.AnonymousSessionUtil} -  Error occurred while getting tenant user realm for tenant id : 46
  org.wso2.carbon.registry.core.exceptions.RegistryException: Error occurred while getting tenant user realm for tenant id : 46
          at org.wso2.carbon.registry.core.jdbc.EmbeddedRegistryService.getUserRealm(EmbeddedRegistryService.java:441)
          at org.wso2.carbon.core.util.AnonymousSessionUtil.getRealmByTenantDomain(AnonymousSessionUtil.java:133)
          at org.wso2.carbon.core.services.authentication.AuthenticationAdmin.login(AuthenticationAdmin.java:92)
          at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
  
  Caused by: org.wso2.carbon.user.core.UserStoreException: Error occurred while getting tenant user realm for tenant id : 46
          at org.wso2.carbon.user.core.common.DefaultRealmService.getTenantUserRealmInternal(DefaultRealmService.java:193)
          at org.wso2.carbon.user.core.common.DefaultRealmService.access$000(DefaultRealmService.java:60)
          at org.wso2.carbon.user.core.common.DefaultRealmService$1.run(DefaultRealmService.java:153)
          at org.wso2.carbon.user.core.common.DefaultRealmService$1.run(DefaultRealmService.java:150)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.wso2.carbon.user.core.common.DefaultRealmService.getTenantUserRealm(DefaultRealmService.java:150)
          at org.wso2.carbon.registry.core.jdbc.EmbeddedRegistryService.getUserRealm(EmbeddedRegistryService.java:436)
          ... 67 more
  Caused by: org.wso2.carbon.user.core.UserStoreException: Error while reading realm configuration from file
          at org.wso2.carbon.user.core.config.RealmConfigXMLProcessor.buildTenantRealmConfiguration(RealmConfigXMLProcessor.java:230)
          at org.wso2.carbon.user.core.tenant.JDBCTenantManager.getTenant(JDBCTenantManager.java:323)
          at org.wso2.carbon.user.core.tenant.JDBCTenantManager.getTenant(JDBCTenantManager.java:53)
          at org.wso2.carbon.user.core.common.DefaultRealmService.getTenantUserRealmInternal(DefaultRealmService.java:172)
          ... 73 more
  Caused by: org.wso2.carbon.CarbonException: Error in building Document
          at org.wso2.carbon.utils.CarbonUtils.replaceSystemVariablesInXml(CarbonUtils.java:1082)
          at org.wso2.carbon.user.core.config.RealmConfigXMLProcessor.preProcessRealmConfig(RealmConfigXMLProcessor.java:241)
          at org.wso2.carbon.user.core.config.RealmConfigXMLProcessor.buildTenantRealmConfiguration(RealmConfigXMLProcessor.java:211)
          ... 76 more
  Caused by: java.lang.NullPointerException
          at org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(DocumentBuilderFactoryImpl.java:93)
          at org.wso2.carbon.utils.CarbonUtils.replaceSystemVariablesInXml(CarbonUtils.java:1078)
          ... 78 more
  TID: [46] [] [2016-09-04 19:09:10,345] @tenant1.edu [46] [IS]ERROR {org.wso2.carbon.core.services.authentication.AuthenticationAdmin} -  System error while Authenticating/Authorizing User : Error occurred while getting tenant user realm for tenant id : 46
  TID: [-1234] [] [2016-09-04 19:09:10,895] ERROR {org.apache.catalina.core.ApplicationDispatcher} -  Servlet.service() for servlet bridgeservlet threw exception
  java.lang.NullPointerException
  
  TID: [-1234] [] [2016-09-04 19:09:10,896] ERROR {org.apache.tiles.servlet.context.ServletTilesRequestContext} -  Servlet Exception while including path
  org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to compile class for JSP
          at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
          at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:378)
          at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
          at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
          at org.wso2.carbon.ui.JspServlet.service(JspServlet.java:155)
          at org.wso2.carbon.ui.TilesJspServlet.service(TilesJspServlet.java:80)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
  </code></pre>
  
  <p>During this time I can login to the WSO2 Administrative console using the super admin account. However, all the tenant admin logins are failing. The issue goes away once the identity server is restarted.</p>
  
  <p>Any help in this regard is appreciated.</p>