wso2 / product-is

Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
748 stars 729 forks source link

Cannot load the console application because of missing tables in the H2 database #19770

Open amanda-ariyaratne opened 9 months ago

amanda-ariyaratne commented 9 months ago

Describe the issue:

When loading the console application getting the error "Cannot find an application associated with the given consumer key." Previously, was able to log into the console application without any issue.

The following stack trace was found in the terminal. However, it is not logged each time the console is loaded.

[2024-02-21 19:26:53,624] [7952ee14-995b-4592-ad97-c559e903fcf4] ERROR {org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint} - Error occurred while validating requested scopes. org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception: Error while retrieving internal scopes for tenant domain : carbon.super
    at org.wso2.carbon.identity.oauth2.util.AuthzUtil.getInternalScopes(AuthzUtil.java:487)
    at org.wso2.carbon.identity.oauth2.validators.DefaultOAuth2ScopeValidator.getAuthorizedScopes(DefaultOAuth2ScopeValidator.java:184)
    at org.wso2.carbon.identity.oauth2.validators.DefaultOAuth2ScopeValidator.validateScope(DefaultOAuth2ScopeValidator.java:103)
    at org.wso2.carbon.identity.oauth2.authz.AuthorizationHandlerManager.getAuthorizedScopes(AuthorizationHandlerManager.java:395)
    at org.wso2.carbon.identity.oauth2.authz.AuthorizationHandlerManager.validateRequestedScopes(AuthorizationHandlerManager.java:303)
    at org.wso2.carbon.identity.oauth2.authz.AuthorizationHandlerManager.validateScopesBeforeConsent(AuthorizationHandlerManager.java:223)
    at org.wso2.carbon.identity.oauth2.OAuth2Service.validateScopesBeforeConsent(OAuth2Service.java:192)
    at org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.validateScopesBeforeConsent(OAuth2AuthzEndpoint.java:2934)
    at org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.doUserAuthorization(OAuth2AuthzEndpoint.java:2850)
    at org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.handleSuccessfulAuthentication(OAuth2AuthzEndpoint.java:1232)
    at org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.handleAuthenticationResponse(OAuth2AuthzEndpoint.java:1180)
    at org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.authorize(OAuth2AuthzEndpoint.java:365)
    at org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.handleAuthFlowThroughFramework(OAuth2AuthzEndpoint.java:3845)
    at org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.handleInitialAuthorizationRequest(OAuth2AuthzEndpoint.java:1401)
    at org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.authorize(OAuth2AuthzEndpoint.java:363)
    at jdk.internal.reflect.GeneratedMethodAccessor244.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    ...
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtServerException: Error while getting scopes.
    at org.wso2.carbon.identity.api.resource.mgt.util.APIResourceManagementUtil.handleServerException(APIResourceManagementUtil.java:81)
    at org.wso2.carbon.identity.api.resource.mgt.dao.impl.APIResourceManagementDAOImpl.getScopesByTenantId(APIResourceManagementDAOImpl.java:444)
    at org.wso2.carbon.identity.api.resource.mgt.dao.impl.CacheBackedAPIResourceMgtDAO.getScopesByTenantId(CacheBackedAPIResourceMgtDAO.java:260)
    at org.wso2.carbon.identity.api.resource.mgt.APIResourceManagerImpl.getScopesByTenantDomain(APIResourceManagerImpl.java:191)
    at org.wso2.carbon.identity.oauth2.util.AuthzUtil.getInternalScopes(AuthzUtil.java:484)
    ... 79 more
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "SCOPE" not found; SQL statement:
SELECT ID, NAME, DISPLAY_NAME, DESCRIPTION, API_ID, TENANT_ID FROM SCOPE WHERE NAME LIKE ? AND  (TENANT_ID = ? OR TENANT_ID IS NULL) [42102-224]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
    at org.h2.message.DbException.get(DbException.java:223)
    at org.h2.message.DbException.get(DbException.java:199)
    at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8064)
    at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8035)
    at org.h2.command.Parser.readTableOrView(Parser.java:8024)
    at org.h2.command.Parser.readTablePrimary(Parser.java:1788)
    at org.h2.command.Parser.readTableReference(Parser.java:2268)
    at org.h2.command.Parser.parseSelectFromPart(Parser.java:2718)
    at org.h2.command.Parser.parseSelect(Parser.java:2824)
    at org.h2.command.Parser.parseQueryPrimary(Parser.java:2708)
    at org.h2.command.Parser.parseQueryTerm(Parser.java:2564)
    at org.h2.command.Parser.parseQueryExpressionBody(Parser.java:2543)
    at org.h2.command.Parser.parseQueryExpressionBodyAndEndOfQuery(Parser.java:2536)
    at org.h2.command.Parser.parseQueryExpression(Parser.java:2529)
    at org.h2.command.Parser.parseQuery(Parser.java:2498)
    at org.h2.command.Parser.parsePrepared(Parser.java:627)
    at org.h2.command.Parser.parse(Parser.java:592)
    at org.h2.command.Parser.parse(Parser.java:564)
    at org.h2.command.Parser.prepareCommand(Parser.java:483)
    at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:639)
    at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:559)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1166)
    at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:93)
    at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:316)
    at jdk.internal.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:131)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
    at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:75)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
    at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:75)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
    at org.apache.tomcat.jdbc.pool.interceptor.ConnectionState.invoke(ConnectionState.java:158)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
    at org.apache.tomcat.jdbc.pool.TrapException.invoke(TrapException.java:39)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
    at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:75)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
    at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
    at com.sun.proxy.$Proxy51.prepareStatement(Unknown Source)
    at org.wso2.carbon.identity.api.resource.mgt.dao.impl.APIResourceManagementDAOImpl.getScopesByTenantId(APIResourceManagementDAOImpl.java:419)
    ... 82 more

EDIT: Tried to restart the server and getting the following error on startup.

[2024-02-21 19:55:44,770] [] ERROR {org.wso2.carbon.identity.api.resource.mgt.util.APIResourceManagementUtil} - Error while registering system API resources in the server. org.wso2.carbon.identity.api.resource.mgt.APIResourceMgtServerException: 65001
    at org.wso2.carbon.identity.api.resource.mgt.dao.impl.APIResourceManagementDAOImpl.getAPIResourcesCount(APIResourceManagementDAOImpl.java:119)
    at org.wso2.carbon.identity.api.resource.mgt.dao.impl.CacheBackedAPIResourceMgtDAO.getAPIResourcesCount(CacheBackedAPIResourceMgtDAO.java:78)
    at org.wso2.carbon.identity.api.resource.mgt.APIResourceManagerImpl.getAPIResources(APIResourceManagerImpl.java:71)
    at org.wso2.carbon.identity.api.resource.mgt.util.APIResourceManagementUtil.isSystemAPIExist(APIResourceManagementUtil.java:199)
    at org.wso2.carbon.identity.api.resource.mgt.util.APIResourceManagementUtil.addSystemAPIs(APIResourceManagementUtil.java:95)
    at org.wso2.carbon.identity.api.resource.mgt.internal.APIResourceManagementServiceComponent.activate(APIResourceManagementServiceComponent.java:55)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "API_RESOURCE" not found; SQL statement:
SELECT COUNT(DISTINCT(ID)) FROM API_RESOURCE WHERE TYPE = ? AND  (TENANT_ID = ? OR TENANT_ID IS NULL) [42102-224]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
    at org.h2.message.DbException.get(DbException.java:223)
    at org.h2.message.DbException.get(DbException.java:199)
    at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8064)
    at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8035)
    at org.h2.command.Parser.readTableOrView(Parser.java:8024)
...
[2024-02-21 19:55:46,910] [] ERROR {org.wso2.identity.apps.common.internal.AppsCommonServiceComponent} - Failed to activate identity apps common service component. org.wso2.carbon.identity.application.common.IdentityApplicationManagementException: Failed to share system application.
    at org.wso2.identity.apps.common.util.AppPortalUtils.shareApplication(AppPortalUtils.java:408)
    at org.wso2.identity.apps.common.util.AppPortalUtils.createApplication(AppPortalUtils.java:244)
    at org.wso2.identity.apps.common.util.AppPortalUtils.initiatePortals(AppPortalUtils.java:317)
    at org.wso2.identity.apps.common.util.AppPortalUtils.initiatePortals(AppPortalUtils.java:267)
    at org.wso2.identity.apps.common.internal.AppsCommonServiceComponent.activate(AppsCommonServiceComponent.java:88)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:235)
    at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
    at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
...
Caused by: org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementServerException: Unable to retrieve the application.
    at org.wso2.carbon.identity.organization.management.service.util.Utils.handleServerException(Utils.java:112)
    at org.wso2.carbon.identity.organization.management.application.OrgApplicationManagerImpl.getOrgApplication(OrgApplicationManagerImpl.java:491)
    at org.wso2.carbon.identity.organization.management.application.OrgApplicationManagerImpl.shareOrganizationApplication(OrgApplicationManagerImpl.java:164)
    at org.wso2.identity.apps.common.util.AppPortalUtils.shareApplication(AppPortalUtils.java:402)
    ... 231 more
Caused by: org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException: Error while retrieving application with resourceId: aa62a613-f8ef-4641-8522-c5c01c8be473 in tenantDomain: carbon.super
    at org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl.getApplicationByResourceId(ApplicationDAOImpl.java:5451)
    at org.wso2.carbon.identity.application.mgt.dao.impl.CacheBackedApplicationDAO.getApplicationByResourceId(CacheBackedApplicationDAO.java:435)
    at org.wso2.carbon.identity.application.mgt.ApplicationManagementServiceImpl.getApplicationByResourceId(ApplicationManagementServiceImpl.java:2640)
    at org.wso2.carbon.identity.organization.management.application.OrgApplicationManagerImpl.getOrgApplication(OrgApplicationManagerImpl.java:488)
    ... 233 more
Caused by: org.wso2.carbon.identity.application.common.IdentityApplicationManagementException: Error while retrieving associated roles for application ID: aa62a613-f8ef-4641-8522-c5c01c8be473
    at org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl.getAssociatedRoles(ApplicationDAOImpl.java:2257)
    at org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl.getApplication(ApplicationDAOImpl.java:2220)
    at org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl.getApplicationByResourceId(ApplicationDAOImpl.java:5441)
    ... 236 more
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "APP_ROLE_ASSOCIATION" not found; SQL statement:
SELECT ROLE_ID FROM APP_ROLE_ASSOCIATION WHERE APP_ID= ?  [42102-224]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
    at org.h2.message.DbException.get(DbException.java:223)
    at org.h2.message.DbException.get(DbException.java:199)
    at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8064)
    at org.h2.command.Parser.getTableOrViewNotFoundDbException(Parser.java:8035)
    at org.h2.command.Parser.readTableOrView(Parser.java:8024)
    at org.h2.command.Parser.readTablePrimary(Parser.java:1788)
    at org.h2.command.Parser.readTableReference(Parser.java:2268)
...
[2024-02-21 19:55:47,949] []  INFO {org.wso2.carbon.user.core.common.UserStoreDeploymentManager} - Realm configuration of tenant:-1234  modified with /Users/amanda/Downloads/wso2is-7.0.0/repository/deployment/server/userstores/ROLDAP.xml
[2024-02-21 19:55:47,961] [] ERROR {org.wso2.carbon.user.core.common.AbstractUserStoreManager} - Cannot create org.wso2.carbon.user.core.ldap.UniqueIDReadOnlyLDAPUserStoreManager java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.wso2.carbon.user.core.common.AbstractUserStoreManager.createSecondaryUserStoreManager(AbstractUserStoreManager.java:10245)
    at org.wso2.carbon.user.core.common.AbstractUserStoreManager.addSecondaryUserStoreManager(AbstractUserStoreManager.java:10317)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.wso2.carbon.user.core.common.AbstractUserStoreManager$2.run(AbstractUserStoreManager.java:245)
...
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:234)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:345)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
    at org.wso2.carbon.user.core.ldap.LDAPConnectionContext.<init>(LDAPConnectionContext.java:122)
    at org.wso2.carbon.user.core.ldap.ReadOnlyLDAPUserStoreManager.<init>(ReadOnlyLDAPUserStoreManager.java:246)
    at org.wso2.carbon.user.core.ldap.UniqueIDReadOnlyLDAPUserStoreManager.<init>(UniqueIDReadOnlyLDAPUserStoreManager.java:182)
    ... 65 more

Checked by connecting to the H2 database and API RESOURCE and SCOPE tables are not in the identity DB.

How to reproduce:

Expected behavior:

Environment information (Please complete the following information; remove any unnecessary fields) :


Optional Fields

Related issues:

Suggested labels:

pavinduLakshan commented 9 months ago

Faced the same error in the pre-RC3 pack today morning, after keeping the server running for a few hours and trying to restart after adding the mysql connector.

DB: H2

sadilchamishka commented 9 months ago

Same issue was reproduced.

brygom commented 6 months ago

Hello, any solution ?

sadilchamishka commented 6 months ago

Same issue was identified in some other systems which use the specific H2 version. It is recommend to use a production grade database instead of H2. Mean time upgrading the H2 version of the product might fix this issue.