Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring boot Actuator conflicts with shiro #16097

Closed
C644753271 opened this issue Mar 5, 2019 · 8 comments
Closed

Spring boot Actuator conflicts with shiro #16097

C644753271 opened this issue Mar 5, 2019 · 8 comments
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid

Comments

@C644753271
Copy link

C644753271 commented Mar 5, 2019

When i use Spring Boot with shiro , Spring Boot Actuator doesnt publish jvm metric。

I use Spring Boot with Shiro , but i starting Application and navigating to /actuator/metrics displays a list of available meter names:

names: [
"jdbc.connections.active",
"jdbc.connections.max",
"jdbc.connections.min",
"cache.removals",
"hikaricp.connections.idle",
"hikaricp.connections.pending",
"hikaricp.connections",
"hikaricp.connections.active",
"hikaricp.connections.creation",
"cache.puts",
"cache.evictions",
"hikaricp.connections.max",
"hikaricp.connections.min",
"cache.gets",
"hikaricp.connections.usage",
"hikaricp.connections.timeout",
"hikaricp.connections.acquire"
]

Just 17 items!!!

Then , i shield shiro config :

// @Configuration

I starting Application again and i get all.

I want to use both Actuator and Shiro. Thanks for any helps.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 5, 2019
@wilkinsona
Copy link
Member

Thanks for the report. From the information you've provided thus far, it's not clear to me that this is a problem with Spring Boot rather than with Shiro or your configuration. If you would like us to spend some time trying to help you, please spend some time to provide a minimal sample that reproduces the behaviour you have described.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Mar 5, 2019
@C644753271
Copy link
Author

Thank you for your help, but I think I should find the problem, but the specific reason is not very clear to me, I think the following website will make you more understand my problem, by the way, can you tell me the specific reason。
https://stackoverflow.com/questions/52943089/when-i-use-spring-boot-with-shiro-spring-boot-actuator-doesnt-publish-jvm-metr

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 6, 2019
@wilkinsona
Copy link
Member

It sounds like a bug in MyBatis that is triggering eager initialisation of some beans. If a meter binder is initialised too early it will not have a chance to bind its meters to the meter registry and they will disappear.

The above is only an educated guess. Given how popular MyBatis is, I’d like to fully understand the cause so that, hopefully, it can be fixed. Could you please provide a sample that reproduces the problem?

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Mar 6, 2019
@C644753271
Copy link
Author

C644753271 commented Mar 6, 2019

Thank you for taking time out of your busy schedule to deal with this problem. I think this is not a bug of mybatis, because the same problem still exists when I replace mybatis with JPA. Therefore, I think this should be shiro problem.I will provide a sample of the problem to you later

@wilkinsona
Copy link
Member

Great. Thank you. I'll look forward to taking a look at the sample.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 6, 2019
@C644753271
Copy link
Author

Hey, wilkinsona, when I delved into this issue, I made some other findings. At first, I always thought that it was the external injection of JPA beans or Mybatis Mapper into the custom ShiroRealm that caused the problem, but when I delved into it, I found that the problem might be where to get the source data. I have written the specific instructions in the following samples. Please tell me as soon as you know the reason. Thank you very much
actuator-shiro.zip

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 7, 2019
@wilkinsona
Copy link
Member

Thanks for the sample. The root cause of the problem is Shiro's ShiroFilterFactoryBean which is both a FactoryBean and a BeanPostProcessor. It's the latter that is causing the problem. BeanPostProcessors are needed very early in the application's lifecycle so that the can post-process each bean as it's created. This means that injecting dependencies into a BeanPostProcessor should be avoided as any dependency that is injected and its entire graph of dependencies will not be eligible for post-processing. You can see info messages about this being logged when you start the sample:

2019-03-07 10:45:14.298  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$abe4422b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.320  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroAutoConfigure' of type [com.duoqio.actuatorshiro.shiro.autoconfigure.ShiroAutoConfigure$$EnhancerBySpringCGLIB$$992dbe28] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.495  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'hashedCredentialsMatcher' of type [org.apache.shiro.authc.credential.HashedCredentialsMatcher] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.516  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#69da0b12' of type [org.springframework.beans.factory.config.PropertiesFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.517  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#69da0b12' of type [java.util.Properties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.520  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#3cee53dc' of type [org.springframework.data.repository.core.support.PropertiesBasedNamedQueries] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.525  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#a52ca2e' of type [org.springframework.data.repository.core.support.RepositoryFragmentsFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.526  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#a52ca2e' of type [org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.532  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#5246a3b3' of type [org.springframework.data.repository.query.ExtensionAwareEvaluationContextProvider] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.536  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.547  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.context.properties.ConversionServiceDeducer$Factory' of type [org.springframework.boot.context.properties.ConversionServiceDeducer$Factory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.551  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.582  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSource' of type [com.zaxxer.hikari.HikariDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.585  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration$$EnhancerBySpringCGLIB$$407c71ca] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.589  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'management.metrics.export.simple-org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleProperties' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.595  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'simpleConfig' of type [org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimplePropertiesConfigAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.599  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration' of type [org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration$$EnhancerBySpringCGLIB$$f7681a8a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.603  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'micrometerClock' of type [io.micrometer.core.instrument.Clock$1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.617  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'simpleMeterRegistry' of type [io.micrometer.core.instrument.simple.SimpleMeterRegistry] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.627  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.637  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.jpa-org.springframework.boot.autoconfigure.orm.jpa.JpaProperties' of type [org.springframework.boot.autoconfigure.orm.jpa.JpaProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.641  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration' of type [org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$$EnhancerBySpringCGLIB$$40583d35] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.648  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.transaction-org.springframework.boot.autoconfigure.transaction.TransactionProperties' of type [org.springframework.boot.autoconfigure.transaction.TransactionProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.651  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'platformTransactionManagerCustomizers' of type [org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.656  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration' of type [org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration$$EnhancerBySpringCGLIB$$c3b6a0f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.659  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'hikariPoolDataSourceMetadataProvider' of type [org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration$$Lambda$286/1898167916] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.669  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration' of type [org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$cabb049a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
…
2019-03-07 10:45:14.891  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'jpaVendorAdapter' of type [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:14.895  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'entityManagerFactoryBuilder' of type [org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
…
10:45:15.463  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'entityManagerFactory' of type [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.464  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'entityManagerFactory' of type [com.sun.proxy.$Proxy88] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.475  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean '(inner bean)#6fd77352' of type [com.sun.proxy.$Proxy90] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.486  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'jpaMappingContext' of type [org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.486  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'jpaMappingContext' of type [org.springframework.data.jpa.mapping.JpaMetamodelMappingContext] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.617  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userRepository' of type [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.617  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userRepository' of type [com.sun.proxy.$Proxy92] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.621  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'dataServiceImpl' of type [com.duoqio.actuatorshiro.data.service.impl.DataServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.622  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroRealm' of type [com.duoqio.actuatorshiro.shiro.realm.SecurityShiroRealm] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-07 10:45:15.628  INFO 91848 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'securityManager' of type [org.apache.shiro.web.mgt.DefaultWebSecurityManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

In your specific case, the ShiroFilterFactoryBean has quite a large graph of dependencies due to your custom realm. Within the graph is Micrometer's simple meter registry which means that it is not post-processed. Meters are bound to it via a post-processor which explains why some metrics are disappearing.

The underlying problem really needs to be fixed in Shiro as they should not be injecting dependencies into a BeanPostProcessor. I'd encourage you to open a Shiro issue linking to this one so that they can improve things there. In the meantime, you can work around the problem by injecting your custom Realm lazily:

@Bean
public org.apache.shiro.mgt.SecurityManager securityManager(@Lazy Realm shiroRealm) {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
    securityManager.setRealm(shiroRealm);
    return securityManager;
}

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Mar 7, 2019
@ricardolsmendes
Copy link

Hey folks,
I found this issue when googling spring-boot shiro trationDelegate$BeanPostProcessorChecker. For those who might be interested in getting rid of that myriad of annoying INFO log messages, there is an issue in Shiro's Jira: https://issues.apache.org/jira/browse/SHIRO-743.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants