2

我想在我的基于 Grails 2.2.2 的 Web 应用程序中启用 OAuth2 提供程序。但是我正在努力使用 spring-security-oauth2-provider 插件。

spring-security-oauth2-provider 插件使用 spring-security-oauth2 库。我正在尝试从 Git 运行插件版本 1.0.4-SNAPSHOT,它使用spring-security-oauth2-1.0.4.RELEASE库。

插件安装后,我的应用程序将无法启动,说它无法使用此异常和堆栈跟踪初始化“oauth2ProviderFilter” bean:

| Error 2013-06-15 23:51:51,434 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with name 'oauth2ProviderFilter': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauth2ProviderFilter': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:122)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
    at org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:153)
    at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:170)
    at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:127)
    at org.codehaus.groovy.grails.web.context.GrailsConfigUtils.configureWebApplicationContext(GrailsConfigUtils.java:121)
    at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:107)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.reflect.MalformedParameterizedTypeException
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:53)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94)
    at java.lang.reflect.Method.getGenericParameterTypes(Method.java:291)
    at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387)
    at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:114)
    at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72)
    at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56)
    at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1130)
    at java.beans.Introspector.getBeanInfo(Introspector.java:414)
    at java.beans.Introspector.getBeanInfo(Introspector.java:161)
    at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:217)
    at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:142)
    at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:324)
    at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:331)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1242)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1101)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)

在对 oauth2 库文档(此处)进行调查后,我发现这oauth2ProviderFilterOAuth2AuthenticationProcessingFilter. 在检查了这个类的源代码(github)之后,看起来需要实例化的属性( authenticationEntryPoint, authenticationManager, )很少。authencticationDetailsSource我认为依赖注入可能有问题,所以我尝试oauth2ProviderFilter在resources.groovy中定义bean,并引用Spring Security Core插件定义的实例。

我把它放在我的 resources.groovy 中:

beans = {
    oauth2ProviderFilter(OAuth2AuthenticationProcessingFilter){
        authenticationEntryPoint = ref('basicAuthenticationEntryPoint')
        authenticationManager = ref('authenticationManager')
        authenticationDetailsSource = ref('authenticationDetailsSource')
    }
}

那并没有解决问题,仍然有错误说无法实例化此过滤器。

由于我不是spring专家,您是否认为此错误可能与bean创建期间的依赖注入有关?问题可能出在哪里?

spring-security-oauth2 库是否有可能是为 spring 框架版本设计的,而 grails 可能使用不同的框架版本,这可能会导致问题?

我可以采取哪些后续步骤来找出问题的原因并最终解决问题?

4

1 回答 1

1

当您运行插件的发布版本而不是 SNAPSHOT 时会发生什么?我发现当我使用最新版本的 grails 时,很多时候它们会破坏现有的插件。所以我要做的是...

  1. 尝试在 2.2.2 grails 中使用插件的发布版本。
  2. 如果这不起作用,我会退回我的 grails 版本并尝试使用已发布插件的旧版本。
  3. 如果旧版本不起作用,我可能会在我的设置中遗漏一些东西,所以我会尝试找出它是什么。
  4. 如果在旧版本中工作正常,并且基于设置它看起来我的设置很好,那么我会在grails上询问正在发生的事情和/或打开JIRA 票证

另一件需要考虑的事情是插件的年轻/年旧程度以及它以前有多少错误。我们有很多次决定调试插件,因为这是一项值得的努力,但有时我们决定不使用它,因为它有太多问题,并且将来会让我们回头。

于 2013-06-16T13:50:31.480 回答