JanssenProject / jans

An open source enterprise digital identity platform for CIAM or workforce... Janssen is a distribution of standards-based, developer friendly, components that are engineered to work together in any cloud. #OAuth #OpenID #FIDO
https://docs.jans.io
Apache License 2.0
472 stars 75 forks source link

fix(jans-config-api): fix agama GET operation endpoint #2472

Closed moabu closed 2 years ago

moabu commented 2 years ago

Request: GET on /jans-config-api/api/v1/agama

Exception:

2022-09-26 14:19:43.562:WARN :oejs.HttpChannel:qtp762476028-21: /jans-config-api/api/v1/agama
org.jboss.resteasy.spi.UnhandledException: io.jans.orm.exception.EntryPersistenceException: Failed to find entries with key: 'flows', expression: 'null'
    at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:105)
    ...
    at io.jans.configapi.filters.MetricFilter.doFilter(MetricFilter.java:56)
    at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:210)
    at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
    at io.jans.configapi.filters.CorsFilter.doFilter(CorsFilter.java:64)
    ...
Caused by: 
io.jans.orm.exception.EntryPersistenceException: Failed to find entries with key: 'flows', expression: 'null'
    at io.jans.orm.sql.impl.SqlEntryManager.findEntriesImpl(SqlEntryManager.java:500)
    at io.jans.orm.sql.impl.SqlEntryManager.findPagedEntries(SqlEntryManager.java:411)
    at jdk.internal.reflect.GeneratedMethodAccessor951.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.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:106)
    at io.jans.orm.PersistenceEntryManager$EntityManager$722412412$Proxy$_$$_WeldClientProxy.findPagedEntries(Unknown Source)
    at io.jans.configapi.service.auth.AgamaFlowService.searchFlows(AgamaFlowService.java:94)
    at io.jans.configapi.service.auth.AgamaFlowService$Proxy$_$$_WeldClientProxy.searchFlows(Unknown Source)
    at io.jans.configapi.rest.resource.auth.AgamaResource.doSearch(AgamaResource.java:412)
    at io.jans.configapi.rest.resource.auth.AgamaResource.getFlows(AgamaResource.java:87)
    at io.jans.configapi.rest.resource.auth.AgamaResource$Proxy$_$$_WeldSubclass.getFlows(Unknown Source)
    at io.jans.configapi.rest.resource.auth.AgamaResource$Proxy$_$$_WeldClientProxy.getFlows(Unknown Source)

Comment: Remaining CRUD operations work without any issues.

pujavs commented 2 years ago

@yuremm, this issue is in MySql DB wherein the paged result query for agama flow is throwing the above error. Note for LDAP DB there is no issue. MySQL logs: mySql-env-logs.zip

MySQL Query: image

LDAP testing image

yurem commented 2 years ago

@pujavs thank you for last screenshot. It sheds light on the root case. Can you check if we define in agmFlow objectClass qname attribute. ProtoFlow bean has this attribute:

    @AttributeName(name = Flow.ATTR_NAMES.QNAME)
    private String qname;
jgomer2001 commented 2 years ago

@pujavs , the problem is that default sort-by value employed in service implementation is qname; here: https://github.com/JanssenProject/jans/blob/main/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/AgamaResource.java#L74

But the "proper" value should be agFlowQname, that is, Flow.ATTR_NAMES.QNAME

pujavs commented 2 years ago

thankyou @yurem and @jgomer2001 for your comments. It's strange though that LDAP search is not throwing error and return 200 response. I will change to useagFlowQname, test and revert.

pujavs commented 2 years ago

Fixed via PR 2513 Testing on MySQL env image