networknt / light-oauth2

A fast, light and cloud native OAuth 2.0 authorization microservices based on light-4j
Apache License 2.0
315 stars 75 forks source link

Runtime exception ERR10010 when registering new oauth service #288

Open ghost opened 4 years ago

ghost commented 4 years ago

Hello,

I'm trying to register a new oauth service and I'm receiving a runtime exception with code ERR10010. The console log from the oauth service suggests the service is trying to save a record with host=null to the service table in the database, violating a NOT NULL constraint on the host column. Any suggestion what might be causing this problem ?

Steps to reproduce:

docker-compose -f light-docker/docker-compose-oauth2-postgres.yml up

curl -k -H 'Content-Type: application/json' -X POST -d '{"serviceId":"TUTORIAL-PARTIES","serviceType":"openapi","serviceName":"TUTORIAL - Parties API","serviceDesc":"TUTORIAL - An example of a simple Parties API","scope":"accounts","ownerId":"admin"}' https://localhost:6883/oauth2/service

The above curl request returns the following error response: {"statusCode":500,"code":"ERR10010","message":"RUNTIME_EXCEPTION","description":"Unexpected runtime exception","severity":"ERROR"}

Here the messages I see logged to stdout:

oauth2-code_1 | HOST IP null oauth2-code_1 | Http port disabled. oauth2-code_1 | Https Server started on ip:0.0.0.0 Port:6881 oauth2-key_1 | HOST IP null oauth2-key_1 | Http port disabled. oauth2-key_1 | Https Server started on ip:0.0.0.0 Port:6886 oauth2-refresh-token_1 | HOST IP null oauth2-refresh-token_1 | Http port disabled. oauth2-refresh-token_1 | Https Server started on ip:0.0.0.0 Port:6887 oauth2-service_1 | HOST IP null oauth2-service_1 | Http port disabled. oauth2-token_1 | HOST IP null oauth2-token_1 | Http port disabled. oauth2-token_1 | Https Server started on ip:0.0.0.0 Port:6882 oauth2-service_1 | Https Server started on ip:0.0.0.0 Port:6883 oauth2-user_1 | HOST IP null oauth2-user_1 | Http port disabled. oauth2-user_1 | Https Server started on ip:0.0.0.0 Port:6885 oauth2-client_1 | Jul 30, 2020 3:42:59 PM com.hazelcast.internal.partition.impl.PartitionStateManager oauth2-client_1 | INFO: [172.18.0.6]:5701 [dev] [3.12] Initializing cluster partition table arrangement... postgresdb_1 | ERROR: null value in column "host" violates not-null constraint postgresdb_1 | DETAIL: Failing row contains (TUTORIAL-PARTIES, openapi, TUTORIAL - Parties API, TUTORIAL - An example of a simple Parties API, accounts, admin, null). postgresdb_1 | STATEMENT: INSERT INTO service (service_id, service_type, service_name, service_desc, scope, owner_id) VALUES ($1, $2, $3, $4, $5, $6) oauth2-code_1 | 15:44:29.271 [hz._hzInstance_1_dev.partition-operation.thread-0] ERROR c.n.oauth.cache.ServiceMapStore store - Exception: oauth2-code_1 | org.postgresql.util.PSQLException: ERROR: null value in column "host" violates not-null constraint oauth2-code_1 | Detail: Failing row contains (TUTORIAL-PARTIES, openapi, TUTORIAL - Parties API, TUTORIAL - An example of a simple Parties API, accounts, admin, null). oauth2-code_1 | at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458) oauth2-code_1 | at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2158) oauth2-code_1 | at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:291) oauth2-code_1 | at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432) oauth2-code_1 | at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358) oauth2-code_1 | at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:171) oauth2-code_1 | at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:138) oauth2-code_1 | at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) oauth2-code_1 | at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) oauth2-code_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:50) oauth2-code_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:19) oauth2-code_1 | at com.hazelcast.map.impl.MapStoreWrapper.store(MapStoreWrapper.java:121) oauth2-code_1 | at com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore.add(WriteThroughStore.java:39) oauth2-code_1 | at com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore.add(WriteThroughStore.java:28) oauth2-code_1 | at com.hazelcast.map.impl.recordstore.DefaultRecordStore.putInternal(DefaultRecordStore.java:698) oauth2-code_1 | at com.hazelcast.map.impl.recordstore.DefaultRecordStore.set(DefaultRecordStore.java:681) oauth2-code_1 | at com.hazelcast.map.impl.operation.SetOperation.run(SetOperation.java:39) oauth2-code_1 | at com.hazelcast.spi.Operation.call(Operation.java:170) oauth2-code_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:210) oauth2-code_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:199) oauth2-code_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:416) oauth2-code_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:153) oauth2-code_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:123) oauth2-code_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110) oauth2-code_1 | Jul 30, 2020 3:44:29 PM com.hazelcast.map.impl.operation.SetOperation oauth2-code_1 | SEVERE: [172.18.0.7]:5701 [dev] [3.12] org.postgresql.util.PSQLException: ERROR: null value in column "host" violates not-null constraint oauth2-code_1 | Detail: Failing row contains (TUTORIAL-PARTIES, openapi, TUTORIAL - Parties API, TUTORIAL - An example of a simple Parties API, accounts, admin, null). oauth2-code_1 | java.lang.RuntimeException: org.postgresql.util.PSQLException: ERROR: null value in column "host" violates not-null constraint oauth2-code_1 | Detail: Failing row contains (TUTORIAL-PARTIES, openapi, TUTORIAL - Parties API, TUTORIAL - An example of a simple Parties API, accounts, admin, null). oauth2-code_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:53) oauth2-code_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:19) oauth2-code_1 | at com.hazelcast.map.impl.MapStoreWrapper.store(MapStoreWrapper.java:121) oauth2-code_1 | at com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore.add(WriteThroughStore.java:39) oauth2-code_1 | at com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore.add(WriteThroughStore.java:28) oauth2-code_1 | at com.hazelcast.map.impl.recordstore.DefaultRecordStore.putInternal(DefaultRecordStore.java:698) oauth2-code_1 | at com.hazelcast.map.impl.recordstore.DefaultRecordStore.set(DefaultRecordStore.java:681) oauth2-code_1 | at com.hazelcast.map.impl.operation.SetOperation.run(SetOperation.java:39) oauth2-code_1 | at com.hazelcast.spi.Operation.call(Operation.java:170) oauth2-code_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:210) oauth2-code_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:199) oauth2-code_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:416) oauth2-code_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:153) oauth2-code_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:123) oauth2-code_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110) oauth2-code_1 | Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "host" violates not-null constraint oauth2-code_1 | Detail: Failing row contains (TUTORIAL-PARTIES, openapi, TUTORIAL - Parties API, TUTORIAL - An example of a simple Parties API, accounts, admin, null). oauth2-code_1 | at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458) oauth2-code_1 | at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2158) oauth2-code_1 | at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:291) oauth2-code_1 | at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432) oauth2-code_1 | at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358) oauth2-code_1 | at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:171) oauth2-code_1 | at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:138) oauth2-code_1 | at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) oauth2-code_1 | at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) oauth2-code_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:50) oauth2-code_1 | ... 14 more oauth2-code_1 | oauth2-service_1 | 15:44:29.301 [XNIO-1 task-6] tYCoDTKsStCOp6j3fq15Nw ERROR c.n.exception.ExceptionHandler handleRequest - Exception: oauth2-service_1 | java.lang.RuntimeException: org.postgresql.util.PSQLException: ERROR: null value in column "host" violates not-null constraint oauth2-service_1 | Detail: Failing row contains (TUTORIAL-PARTIES, openapi, TUTORIAL - Parties API, TUTORIAL - An example of a simple Parties API, accounts, admin, null). oauth2-service_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:53) oauth2-service_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:19) oauth2-service_1 | at com.hazelcast.map.impl.MapStoreWrapper.store(MapStoreWrapper.java:121) oauth2-service_1 | at com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore.add(WriteThroughStore.java:39) oauth2-service_1 | at com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore.add(WriteThroughStore.java:28) oauth2-service_1 | at com.hazelcast.map.impl.recordstore.DefaultRecordStore.putInternal(DefaultRecordStore.java:698) oauth2-service_1 | at com.hazelcast.map.impl.recordstore.DefaultRecordStore.set(DefaultRecordStore.java:681) oauth2-service_1 | at com.hazelcast.map.impl.operation.SetOperation.run(SetOperation.java:39) oauth2-service_1 | at com.hazelcast.spi.Operation.call(Operation.java:170) oauth2-service_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:210) oauth2-service_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:199) oauth2-service_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:416) oauth2-service_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:153) oauth2-service_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:123) oauth2-service_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110) oauth2-service_1 | at ------ submitted from ------.(Unknown Source) oauth2-service_1 | at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolve(InvocationFuture.java:126) oauth2-service_1 | at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveAndThrowIfException(InvocationFuture.java:79) oauth2-service_1 | at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:163) oauth2-service_1 | at com.hazelcast.map.impl.proxy.MapProxySupport.invokeOperation(MapProxySupport.java:434) oauth2-service_1 | at com.hazelcast.map.impl.proxy.MapProxySupport.setInternal(MapProxySupport.java:501) oauth2-service_1 | at com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl.setInternal(NearCachedMapProxyImpl.java:257) oauth2-service_1 | at com.hazelcast.map.impl.proxy.MapProxyImpl.set(MapProxyImpl.java:246) oauth2-service_1 | at com.hazelcast.map.impl.proxy.MapProxyImpl.set(MapProxyImpl.java:237) oauth2-service_1 | at com.networknt.oauth.service.handler.Oauth2ServicePostHandler.handleRequest(Oauth2ServicePostHandler.java:43) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:208) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:229) oauth2-service_1 | at com.networknt.openapi.ValidatorHandler.handleRequest(ValidatorHandler.java:94) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:208) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:229) oauth2-service_1 | at com.networknt.audit.AuditHandler.next(AuditHandler.java:154) oauth2-service_1 | at com.networknt.audit.AuditHandler.handleRequest(AuditHandler.java:143) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:208) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:229) oauth2-service_1 | at com.networknt.body.BodyHandler.handleRequest(BodyHandler.java:116) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:208) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:229) oauth2-service_1 | at com.networknt.openapi.OpenApiHandler.handleRequest(OpenApiHandler.java:108) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:208) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:229) oauth2-service_1 | at com.networknt.correlation.CorrelationHandler.handleRequest(CorrelationHandler.java:77) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:208) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:229) oauth2-service_1 | at com.networknt.traceability.TraceabilityHandler.handleRequest(TraceabilityHandler.java:66) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:208) oauth2-service_1 | at com.networknt.handler.Handler.next(Handler.java:229) oauth2-service_1 | at com.networknt.exception.ExceptionHandler.handleRequest(ExceptionHandler.java:76) oauth2-service_1 | at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376) oauth2-service_1 | at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830) oauth2-service_1 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) oauth2-service_1 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) oauth2-service_1 | at java.base/java.lang.Thread.run(Unknown Source) oauth2-service_1 | Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "host" violates not-null constraint oauth2-service_1 | Detail: Failing row contains (TUTORIAL-PARTIES, openapi, TUTORIAL - Parties API, TUTORIAL - An example of a simple Parties API, accounts, admin, null). oauth2-service_1 | at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458) oauth2-service_1 | at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2158) oauth2-service_1 | at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:291) oauth2-service_1 | at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432) oauth2-service_1 | at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358) oauth2-service_1 | at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:171) oauth2-service_1 | at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:138) oauth2-service_1 | at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) oauth2-service_1 | at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) oauth2-service_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:50) oauth2-service_1 | at com.networknt.oauth.cache.ServiceMapStore.store(ServiceMapStore.java:19) oauth2-service_1 | at com.hazelcast.map.impl.MapStoreWrapper.store(MapStoreWrapper.java:121) oauth2-service_1 | at com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore.add(WriteThroughStore.java:39) oauth2-service_1 | at com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore.add(WriteThroughStore.java:28) oauth2-service_1 | at com.hazelcast.map.impl.recordstore.DefaultRecordStore.putInternal(DefaultRecordStore.java:698) oauth2-service_1 | at com.hazelcast.map.impl.recordstore.DefaultRecordStore.set(DefaultRecordStore.java:681) oauth2-service_1 | at com.hazelcast.map.impl.operation.SetOperation.run(SetOperation.java:39) oauth2-service_1 | at com.hazelcast.spi.Operation.call(Operation.java:170) oauth2-service_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:210) oauth2-service_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:199) oauth2-service_1 | at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:416) oauth2-service_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:153) oauth2-service_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:123) oauth2-service_1 | at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110) oauth2-service_1 | 15:44:29.461 [XNIO-1 task-6] tYCoDTKsStCOp6j3fq15Nw ERROR c.networknt.handler.LightHttpHandler setExchangeStatus - {"statusCode":500,"code":"ERR10010","message":"RUNTIME_EXCEPTION","description":"Unexpected runtime exception","severity":"ERROR"} at com.networknt.handler.LightHttpHandler.setExchangeStatus(LightHttpHandler.java:67)

stevehu commented 4 years ago

I am actively working on the light-portal for the oauth client and service registration and scope management. The client registration is done already and it can be accessed at https://dev.lightapi.net after logging in. The service registration is coming with the scope calculation. For most users, it is not necessary to register services and it is not required to do so from OAuth 2.0 specification. Only when you have too many services and scopes to manage.

For the above error, you need to pass in a host as it is mandatory. Use lightapi.net for now. On the light-portal, we support multi-tenancy with different organizations to have their own host to match their domain names. The host was added recently and the document is not updated yet. I will update the following document after the release this weekend. Thanks a lot for raising it.

https://doc.networknt.com/tutorial/oauth/service/

stevehu commented 4 years ago

This should be resolved with https://github.com/networknt/light-oauth2/issues/289 and the document update is pending.