Announcement Announcement Module
Collapse
No announcement yet.
Custom authentication provider can't be instantiated Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom authentication provider can't be instantiated

    I'm building my own web application based on the Greenhouse as a great sample.
    The only differences are:
    1. I use XML for application configuration
    2. And I split separate part of the projects (persistence, services, social) into the separate modules/sub-projects.

    I've spent 2 days trying to figure out where is the difference between my application and the Greenhouse (Greenhouse runs fine from my IDE, and everything works as expected).
    The problem I have - container is not able to instantiate custom usernamePasswordAuthenticationProvider.
    There is the error:
    Could not instantiate bean class [com.myappl.service.UsernamePasswordAuthenticationP rovider]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.myappl.service.UsernamePasswordAuthenticationP rovider.<init>()
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:106)
    at org.springframework.beans.factory.support.Construc torResolver.resolveConstructorArguments(Constructo rResolver.java:616)
    at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:148)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:1035)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:939)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.security.config.debug.Security DebugBeanFactoryPostProcessor.postProcessBeanFacto ry(SecurityDebugBeanFactoryPostProcessor.java:21)
    at org.springframework.context.support.AbstractApplic ationContext.invokeBeanFactoryPostProcessors(Abstr actApplicationContext.java:681)
    at org.springframework.context.support.AbstractApplic ationContext.invokeBeanFactoryPostProcessors(Abstr actApplicationContext.java:671)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:446)
    at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:384)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.
    ...
    I tried all imaginary possible ways to fix it. The reason for this, that I @Inject AuthenticationService through constructor injection for UsernamePasswordAuthenticationProvider, which is declared as @Service. Everything is very similar to the Greenhouse application, so it makes me crazy. Why do I need default no arg constructor? I tried to change configuration files order I use in web contextConfigLocation, but no luck.
    Is this specific for @Configuration configuration? I don't want to switch my application into @Configuration instead of XML, at least, if I have to, I would like to know how to fix this error.

    Please, also look into http://forum.springsource.org/showth...ing-form-login (the last answer) and http://forum.springsource.org/showth...ation-provider.
    I asked them for this issue, I describe here, but got no answers.
    Please, if anyone, has any idea or thoughts what can be wrong, share it with me, I will appreciate that much.
    Let me know, if you additional information for this issue.

  • #2
    Addition to the original post.
    ======================
    Everything works fine from JUnit/Integration test, AccountRepository is @Injected (constructor injection) into AuthenticationService, and AuthenticationService is @Injected (constructor injection) into UsernamePasswordAuthenticationProvider (see attached screenshot below).
    But this doesn't work from the real web application. I suppose the reason is that UsernamePasswordAuthenticationProvider can't be constructed using one arg constructor, because at the construction time AuthenticationService is not available (if I'm right, so I am interested why AuthenticationService is not available?).
    And again, the same UsernamePasswordAuthenticationProvider without default constructor works fine for the Greenhouse application. Is @Configuration configuration very different internally to the classical XML+namespaces configuration?

    Thank you.
    Attachment
    Attached Files

    Comment


    • #3
      Ok, Rob Winch helped me, he mentioned that this was according to the <debug/> usage issue. Watch for fix here https://jira.springsource.org/browse/SEC-1885

      Comment

      Working...
      X